@@ -180,7 +180,8 @@ def get_tensors(self) -> Iterator[tuple[str, Tensor]]:
180
180
extra = sorted (tensor_names_from_parts .difference (self .tensor_names ))
181
181
missing_files = sorted (set (weight_map [n ] for n in missing if n in weight_map ))
182
182
if len (extra ) == 0 and len (missing_files ) > 0 :
183
- raise ValueError (f"Missing or incomplete model files: { missing_files } " )
183
+ raise ValueError (f"Missing or incomplete model files: { missing_files } \n "
184
+ f"Missing tensors: { missing } " )
184
185
else :
185
186
raise ValueError ("Mismatch between weight map and model parts for tensor names:\n "
186
187
f"Missing tensors: { missing } \n "
@@ -2726,6 +2727,27 @@ def set_gguf_parameters(self):
2726
2727
self .gguf_writer .add_rope_scaling_type (gguf .RopeScalingType .LINEAR )
2727
2728
self .gguf_writer .add_rope_scaling_factor (1.0 )
2728
2729
2730
+ _has_tok_embd = False
2731
+
2732
+ def modify_tensors (self , data_torch : Tensor , name : str , bid : int | None ) -> Iterable [tuple [str , Tensor ]]:
2733
+ del bid # unused
2734
+
2735
+ output_name = self .format_tensor_name (gguf .MODEL_TENSOR .OUTPUT )
2736
+ tok_embd_name = self .format_tensor_name (gguf .MODEL_TENSOR .TOKEN_EMBD )
2737
+
2738
+ new_name = self .map_tensor_name (name )
2739
+
2740
+ # assuming token_embd.weight is seen before output.weight
2741
+ if not self ._has_tok_embd and new_name == self .format_tensor_name (gguf .MODEL_TENSOR .OUTPUT ):
2742
+ # even though the tensor file(s) does not contain the word embeddings they are still in the weight map
2743
+ if "transformer.wte.weight" in self .tensor_names :
2744
+ logger .debug (f"{ tok_embd_name } not found before { output_name } , assuming they are tied" )
2745
+ self .tensor_names .remove ("transformer.wte.weight" )
2746
+ elif new_name == tok_embd_name :
2747
+ self ._has_tok_embd = True
2748
+
2749
+ return [(new_name , data_torch )]
2750
+
2729
2751
2730
2752
@Model .register ("InternLM2ForCausalLM" )
2731
2753
class InternLM2Model (Model ):
0 commit comments