Skip to content

Commit fbbb64f

Browse files
committed
py : fix scalar-tensor conversion [no ci]
1 parent 13e6d73 commit fbbb64f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

convert_hf_to_gguf.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,13 @@ def prepare_tensors(self):
291291
bid = int(part)
292292
break
293293

294-
for new_name, data in ((n, d.squeeze().numpy()) for n, d in self.modify_tensors(data_torch, name, bid)):
295-
data: np.ndarray # type hint
294+
for new_name, data_torch in (self.modify_tensors(data_torch, name, bid)):
295+
data = data_torch.squeeze().numpy()
296+
297+
# if data ends up empty, it means data_torch was a scalar tensor -> restore
298+
if len(data.shape) == 0:
299+
data = data_torch.numpy()
300+
296301
n_dims = len(data.shape)
297302
data_qtype: gguf.GGMLQuantizationType | bool = self.tensor_force_quant(name, new_name, bid, n_dims)
298303

0 commit comments

Comments
 (0)