@@ -1862,8 +1862,6 @@ class MiniCPM3Model(Model):
1862
1862
def set_gguf_parameters (self ):
1863
1863
hparams = self .hparams
1864
1864
1865
- rope_dims = hparams ["qk_rope_head_dim" ]
1866
-
1867
1865
self .gguf_writer .add_file_type (self .ftype )
1868
1866
self .gguf_writer .add_context_length (hparams ["max_position_embeddings" ])
1869
1867
self .gguf_writer .add_embedding_length (hparams ["hidden_size" ])
@@ -1879,24 +1877,25 @@ def set_gguf_parameters(self):
1879
1877
self .gguf_writer .add_key_length (hparams ["qk_nope_head_dim" ] + hparams ["qk_rope_head_dim" ])
1880
1878
self .gguf_writer .add_rope_dimension_count (hparams ["qk_rope_head_dim" ])
1881
1879
1880
+ def generate_extra_tensors (self ) -> Iterable [tuple [str , Tensor ]]:
1882
1881
rope_scaling = self .find_hparam (['rope_scaling' ], True )
1883
- if rope_scaling is None :
1884
- return
1882
+ if rope_scaling is not None :
1883
+ rope_dims = self . hparams [ "qk_rope_head_dim" ]
1885
1884
1886
- long_factors = rope_scaling .get ('long_factor' , None )
1887
- short_factors = rope_scaling .get ('short_factor' , None )
1885
+ long_factors = rope_scaling .get ('long_factor' , None )
1886
+ short_factors = rope_scaling .get ('short_factor' , None )
1888
1887
1889
- if long_factors is None or short_factors is None :
1890
- raise KeyError ('Missing the required key rope_scaling.long_factor or rope_scaling_short_factor' )
1888
+ if long_factors is None or short_factors is None :
1889
+ raise KeyError ('Missing the required key rope_scaling.long_factor or rope_scaling_short_factor' )
1891
1890
1892
- if len (long_factors ) != len (short_factors ) or len (long_factors ) != rope_dims / 2 :
1893
- raise ValueError (f'The length of rope long and short factors must be { rope_dims / 2 } ' )
1891
+ if len (long_factors ) != len (short_factors ) or len (long_factors ) != rope_dims / 2 :
1892
+ raise ValueError (f'The length of rope long and short factors must be { rope_dims / 2 } ' )
1894
1893
1895
- self .gguf_writer . add_tensor (gguf .TENSOR_NAMES [ gguf . MODEL_TENSOR .ROPE_FACTORS_LONG ] + ".weight" , np . array (long_factors , dtype = np .float32 ))
1896
- self .gguf_writer . add_tensor (gguf .TENSOR_NAMES [ gguf . MODEL_TENSOR .ROPE_FACTORS_SHORT ] + ".weight" , np . array (short_factors , dtype = np .float32 ))
1894
+ yield ( self .format_tensor_name (gguf .MODEL_TENSOR .ROPE_FACTORS_LONG ), torch . tensor (long_factors , dtype = torch .float32 ))
1895
+ yield ( self .format_tensor_name (gguf .MODEL_TENSOR .ROPE_FACTORS_SHORT ), torch . tensor (short_factors , dtype = torch .float32 ))
1897
1896
1898
1897
def set_vocab (self ):
1899
- self ._set_vocab_llama_hf ()
1898
+ self ._set_vocab_sentencepiece ()
1900
1899
1901
1900
def _reverse_hf_permute (self , weights : Tensor , n_head : int , n_kv_head : int | None = None ) -> Tensor :
1902
1901
if n_kv_head is not None and n_head != n_kv_head :
0 commit comments