12
12
from enum import IntEnum
13
13
from pathlib import Path
14
14
from hashlib import sha256
15
- from typing import TYPE_CHECKING , Any , Callable , ContextManager , Iterable , Iterator , Sequence , TypeVar , cast
15
+ from typing import TYPE_CHECKING , Any , Callable , ContextManager , Iterable , Iterator , Sequence , TypeVar , cast , Optional
16
16
from dataclasses import dataclass
17
17
18
18
import math
@@ -148,18 +148,27 @@ def get_model_name(metadata, hyperparameters, dir_model, model_arch):
148
148
return gguf .MODEL_ARCH_NAMES [model_arch ]
149
149
self .model_name = get_model_name (self .metadata , self .hparams , self .dir_model , self .model_arch )
150
150
151
- # Generate default filename based on model specification and available metadata
152
- def extract_encoding_scheme (ftype ):
153
- # Extracts and converts the encoding scheme from the given file type name.
154
- # e.g. 'gguf.LlamaFileType.ALL_F32' --> 'F32'
155
- return ftype .name .partition ("_" )[2 ].upper ()
151
+ # Extracts and converts the encoding scheme from the given file type name. e.g. 'gguf.LlamaFileType.ALL_F32' --> 'F32'
152
+ encodingScheme = self .ftype .name .partition ("_" )[2 ]
153
+
154
+ # Get Expert Count From Hyperparameters
156
155
expert_count = self .hparams ["num_local_experts" ] if "num_local_experts" in self .hparams else None
157
- self .fname_default = f"{ gguf .naming_convention (self .model_name , self .metadata .version , expert_count , self .parameter_count (), extract_encoding_scheme (self .ftype ))} "
156
+
157
+ # Generate default filename based on model specification and available metadata
158
+ self .fname_default = gguf .naming_convention (self .model_name , self .metadata .version , expert_count , self .parameter_count (), encodingScheme )
158
159
159
160
# Filename Output
160
161
if fname_out is not None :
161
162
# custom defined filename and path was provided
162
- self .fname_out = fname_out
163
+ def fill_templated_filename (filename : str , encodingScheme : str ):
164
+ # Given a file name fill in any type templates e.g. 'some-model-name.{ftype}.gguf'
165
+ ftype_uppercase : str = encodingScheme .upper ()
166
+ ftype_lowercase : str = encodingScheme .lower ()
167
+ return filename .format (ftype_lowercase ,
168
+ outtype = ftype_lowercase , ftype = ftype_lowercase ,
169
+ OUTTYPE = ftype_uppercase , FTYPE = ftype_uppercase )
170
+
171
+ self .fname_out = fname_out .parent / fill_templated_filename (fname_out .name , encodingScheme )
163
172
else :
164
173
# output in the same directory as the model by default
165
174
self .fname_out = dir_model .parent / self .fname_default
0 commit comments