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