Skip to content

Commit

Permalink
compatibility fix
Browse files Browse the repository at this point in the history
  • Loading branch information
christianazinn committed Jun 10, 2024
1 parent 854bd64 commit 05b183f
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions gguf-py/gguf/gguf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,25 @@ def write_tensor_data(self, tensor: np.ndarray[Any, Any]) -> None:
if self.endianess == GGUFEndian.BIG:
tensor.byteswap(inplace=True)

for fout in self.fout:
self.write_padding(fout, fout.tell())
tensor.tofile(fout)
self.write_padding(fout, tensor.nbytes)
file_id = -1
for i, tensors in enumerate(self.tensors):
if len(tensors) > 0:
file_id = i
break

fout = self.fout[file_id]

# pop the first tensor info
# TODO: cleaner way to get the first key
first_tensor_name = [name for name, _ in zip(self.tensors[file_id].keys(), range(1))][0]
ti = self.tensors[file_id].pop(first_tensor_name)
assert len(ti.shape) == len(tensor.shape)
assert all(dim1 == dim2 for dim1, dim2 in zip(ti.shape, tensor.shape))
assert ti.nbytes == tensor.nbytes

self.write_padding(fout, fout.tell())
tensor.tofile(fout)
self.write_padding(fout, tensor.nbytes)

self.state = WriterState.WEIGHTS

Expand Down

0 comments on commit 05b183f

Please sign in to comment.