@@ -132,19 +132,22 @@ def set_vocab(self):
132
132
def get_tensors (self ) -> Iterator [tuple [str , Tensor ]]:
133
133
tensor_names_from_parts : set [str ] = set ()
134
134
135
- if len (self .part_names ) > 1 :
135
+ index_name = "model.safetensors" if self .is_safetensors else "pytorch_model.bin"
136
+ index_name += ".index.json"
137
+ index_file = self .dir_model / index_name
138
+
139
+ if index_file .is_file ():
136
140
self .tensor_names = set ()
137
- index_name = "model.safetensors" if self .is_safetensors else "pytorch_model.bin"
138
- index_name += ".index.json"
139
141
logger .info (f"gguf: loading model weight map from '{ index_name } '" )
140
- with open (self . dir_model / index_name , "r" , encoding = "utf-8" ) as f :
142
+ with open (index_file , "r" , encoding = "utf-8" ) as f :
141
143
index : dict [str , Any ] = json .load (f )
142
144
weight_map = index .get ("weight_map" )
143
145
if weight_map is None or not isinstance (weight_map , dict ):
144
146
raise ValueError (f"Can't load 'weight_map' from { index_name !r} " )
145
147
self .tensor_names .update (weight_map .keys ())
146
148
else :
147
149
self .tensor_names = tensor_names_from_parts
150
+ weight_map = {}
148
151
149
152
for part_name in self .part_names :
150
153
logger .info (f"gguf: loading model part '{ part_name } '" )
@@ -171,9 +174,17 @@ def get_tensors(self) -> Iterator[tuple[str, Tensor]]:
171
174
data = LazyTorchTensor .from_eager (data )
172
175
yield name , data
173
176
174
- # only verify tensor name presence; it doesn't matter if they are not in the right files
175
- if len (sym_diff := tensor_names_from_parts .symmetric_difference (self .tensor_names )) > 0 :
176
- raise ValueError (f"Mismatch between weight map and model parts for tensor names: { sym_diff } " )
177
+ # verify tensor name presence and identify potentially missing files
178
+ if len (tensor_names_from_parts .symmetric_difference (self .tensor_names )) > 0 :
179
+ missing = sorted (self .tensor_names .difference (tensor_names_from_parts ))
180
+ extra = sorted (tensor_names_from_parts .difference (self .tensor_names ))
181
+ missing_files = sorted (set (weight_map [n ] for n in missing if n in weight_map ))
182
+ if len (extra ) == 0 and len (missing_files ) > 0 :
183
+ raise ValueError (f"Missing or incomplete model files: { missing_files } " )
184
+ else :
185
+ raise ValueError ("Mismatch between weight map and model parts for tensor names:\n "
186
+ f"Missing tensors: { missing } \n "
187
+ f"Extra tensors: { extra } " )
177
188
178
189
def format_tensor_name (self , key : gguf .MODEL_TENSOR , bid : int | None = None , suffix : str = ".weight" ) -> str :
179
190
if key not in gguf .MODEL_TENSORS [self .model_arch ]:
0 commit comments