@@ -260,6 +260,33 @@ def set_gguf_parameters(self):
260
260
self .gguf_writer .add_file_type (self .ftype )
261
261
logger .info (f"gguf: file type = { self .ftype } " )
262
262
263
+ # get pooling path
264
+ pooling_path = None
265
+ self .pooling_type = gguf .PoolingType .NONE
266
+ module_path = self .dir_model / "modules.json"
267
+ if module_path .is_file ():
268
+ with open (module_path , encoding = "utf-8" ) as f :
269
+ modules = json .load (f )
270
+ for mod in modules :
271
+ if mod ["type" ] == "sentence_transformers.models.Pooling" :
272
+ pooling_path = mod ["path" ]
273
+ break
274
+
275
+ # get pooling type
276
+ if pooling_path is not None :
277
+ with open (self .dir_model / pooling_path / "config.json" , encoding = "utf-8" ) as f :
278
+ pooling = json .load (f )
279
+ if pooling ["pooling_mode_mean_tokens" ]:
280
+ self .pooling_type = gguf .PoolingType .MEAN
281
+ elif pooling ["pooling_mode_cls_token" ]:
282
+ self .pooling_type = gguf .PoolingType .CLS
283
+ elif pooling ["pooling_mode_lasttoken" ]:
284
+ self .pooling_type = gguf .PoolingType .LAST
285
+ else :
286
+ logger .warning ("Only [MEAN|CLS|LAST] pooling types supported, default NONE" )
287
+ self .gguf_writer .add_pooling_type (self .pooling_type )
288
+ logger .info (f"gguf: pooling type = { self .pooling_type } " )
289
+
263
290
def modify_tensors (self , data_torch : Tensor , name : str , bid : int | None ) -> Iterable [tuple [str , Tensor ]]:
264
291
del bid # unused
265
292
@@ -2210,7 +2237,6 @@ def set_gguf_parameters(self):
2210
2237
self .gguf_writer .add_rope_scaling_factor (self .hparams ["rope_scaling" ]["factor" ])
2211
2238
self .gguf_writer .add_rope_scaling_orig_ctx_len (self .hparams ["rope_scaling" ]["original_max_position_embeddings" ])
2212
2239
2213
-
2214
2240
@Model .register ("Qwen2VLForConditionalGeneration" )
2215
2241
class Qwen2VLModel (Model ):
2216
2242
model_arch = gguf .MODEL_ARCH .QWEN2VL
@@ -2957,29 +2983,6 @@ def set_gguf_parameters(self):
2957
2983
super ().set_gguf_parameters ()
2958
2984
self .gguf_writer .add_causal_attention (False )
2959
2985
2960
- # get pooling path
2961
- pooling_path = None
2962
- module_path = self .dir_model / "modules.json"
2963
- if module_path .is_file ():
2964
- with open (module_path , encoding = "utf-8" ) as f :
2965
- modules = json .load (f )
2966
- for mod in modules :
2967
- if mod ["type" ] == "sentence_transformers.models.Pooling" :
2968
- pooling_path = mod ["path" ]
2969
- break
2970
-
2971
- # get pooling type
2972
- if pooling_path is not None :
2973
- with open (self .dir_model / pooling_path / "config.json" , encoding = "utf-8" ) as f :
2974
- pooling = json .load (f )
2975
- if pooling ["pooling_mode_mean_tokens" ]:
2976
- pooling_type = gguf .PoolingType .MEAN
2977
- elif pooling ["pooling_mode_cls_token" ]:
2978
- pooling_type = gguf .PoolingType .CLS
2979
- else :
2980
- raise NotImplementedError ("Only MEAN and CLS pooling types supported" )
2981
- self .gguf_writer .add_pooling_type (pooling_type )
2982
-
2983
2986
def set_vocab (self ):
2984
2987
tokens , toktypes , tokpre = self .get_vocab_base ()
2985
2988
self .vocab_size = len (tokens )
0 commit comments