@@ -189,10 +189,10 @@ def index_tensors(self, remote_hf_model_id: str | None = None) -> dict[str, Call
189189 return tensors
190190
191191 prefix = "model" if not self .is_mistral_format else "consolidated"
192- part_names : list [str ] = ModelBase .get_model_part_names (self .dir_model , prefix , ".safetensors" )
192+ part_names : set [str ] = set ( ModelBase .get_model_part_names (self .dir_model , prefix , ".safetensors" ) )
193193 is_safetensors : bool = len (part_names ) > 0
194194 if not is_safetensors :
195- part_names = ModelBase .get_model_part_names (self .dir_model , "pytorch_model" , ".bin" )
195+ part_names = set ( ModelBase .get_model_part_names (self .dir_model , "pytorch_model" , ".bin" ) )
196196
197197 tensor_names_from_index : set [str ] = set ()
198198
@@ -209,6 +209,7 @@ def index_tensors(self, remote_hf_model_id: str | None = None) -> dict[str, Call
209209 if weight_map is None or not isinstance (weight_map , dict ):
210210 raise ValueError (f"Can't load 'weight_map' from { index_name !r} " )
211211 tensor_names_from_index .update (weight_map .keys ())
212+ part_names |= set (weight_map .values ())
212213 else :
213214 weight_map = {}
214215 else :
@@ -825,6 +826,15 @@ def set_gguf_parameters(self):
825826 self .gguf_writer .add_expert_group_used_count (n_group_used )
826827 logger .info (f"gguf: expert groups used count = { n_group_used } " )
827828
829+ if (score_func := self .find_hparam (["score_function" , "scoring_func" , "score_func" ], optional = True )) is not None :
830+ if score_func == "sigmoid" :
831+ self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SIGMOID )
832+ elif score_func == "softmax" :
833+ self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SOFTMAX )
834+ else :
835+ raise ValueError (f"Unsupported expert score gating function value: { score_func } " )
836+ logger .info (f"gguf: expert score gating function = { score_func } " )
837+
828838 if (head_dim := self .hparams .get ("head_dim" )) is not None :
829839 self .gguf_writer .add_key_length (head_dim )
830840 self .gguf_writer .add_value_length (head_dim )
@@ -2553,15 +2563,6 @@ def set_gguf_parameters(self):
25532563 if (n_dense_layers := self .hparams .get ("num_dense_layers" )) is not None :
25542564 self .gguf_writer .add_leading_dense_block_count (n_dense_layers )
25552565
2556- # Expert Gating Function
2557- score_func = self .hparams .get ("score_func" )
2558- if score_func == "sigmoid" :
2559- self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SIGMOID )
2560- elif score_func == "softmax" :
2561- self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SOFTMAX )
2562- elif score_func is not None :
2563- raise ValueError (f"Unsupported score_function value: { score_func } " )
2564-
25652566 # Route normalization and scaling
25662567 if (route_norm := self .hparams .get ("route_norm" )) is not None :
25672568 self .gguf_writer .add_expert_weights_norm (route_norm )
@@ -7182,13 +7183,6 @@ def set_gguf_parameters(self):
71827183 self .gguf_writer .add_expert_weights_scale (hparams ["routed_scaling_factor" ])
71837184 self .gguf_writer .add_expert_weights_norm (hparams ["norm_topk_prob" ])
71847185
7185- if hparams ["scoring_func" ] == "sigmoid" :
7186- self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SIGMOID )
7187- elif hparams ["scoring_func" ] == "softmax" :
7188- self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SOFTMAX )
7189- else :
7190- raise ValueError (f"Unsupported scoring_func value: { hparams ['scoring_func' ]} " )
7191-
71927186 self .gguf_writer .add_rope_dimension_count (hparams ["qk_rope_head_dim" ])
71937187
71947188 rope_scaling = self .hparams .get ("rope_scaling" ) or {}
@@ -7294,12 +7288,6 @@ def __init__(self, *args, **kwargs):
72947288
72957289 def set_gguf_parameters (self ):
72967290 super ().set_gguf_parameters ()
7297- if self .hparams ["scoring_func" ] == "sigmoid" :
7298- self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SIGMOID )
7299- elif self .hparams ["scoring_func" ] == "softmax" :
7300- self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SOFTMAX )
7301- else :
7302- raise ValueError (f"Unsupported scoring_func value: { self .hparams ['scoring_func' ]} " )
73037291
73047292 self .gguf_writer .add_expert_feed_forward_length (self .find_hparam (["intermediate_size" ]))
73057293 self .gguf_writer .add_rope_dimension_count (self .find_hparam (["rotary_dim" ]))
@@ -7392,11 +7380,6 @@ def set_gguf_parameters(self):
73927380 self .gguf_writer .add_expert_weights_scale (self .hparams ["routed_scaling_factor" ])
73937381 self .gguf_writer .add_expert_weights_norm (self .hparams ["norm_topk_prob" ])
73947382
7395- if self .hparams ["scoring_func" ] == "noaux_tc" :
7396- self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SIGMOID )
7397- else :
7398- raise ValueError (f"Unsupported scoring_func value: { self .hparams ['scoring_func' ]} " )
7399-
74007383 def modify_tensors (self , data_torch : Tensor , name : str , bid : int | None ):
74017384 if name .endswith ("e_score_correction_bias" ):
74027385 name = name .replace ("e_score_correction_bias" , "e_score_correction.bias" )
@@ -8717,13 +8700,6 @@ def set_gguf_parameters(self):
87178700 self .gguf_writer .add_expert_shared_count (hparams ["num_shared_experts" ])
87188701 self .gguf_writer .add_expert_weights_norm (hparams ["norm_topk_prob" ])
87198702
8720- if hparams ["score_function" ] == "sigmoid" :
8721- self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SIGMOID )
8722- elif hparams ["score_function" ] == "softmax" :
8723- self .gguf_writer .add_expert_gating_func (gguf .ExpertGatingFuncType .SOFTMAX )
8724- else :
8725- raise ValueError (f"Unsupported score_function value: { hparams ['score_function' ]} " )
8726-
87278703 if (nextn_layers := self .hparams .get ("num_nextn_predict_layers" )) is not None :
87288704 self .gguf_writer .add_nextn_predict_layers (nextn_layers )
87298705
0 commit comments