Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 173f7cb

Browse files
authoredOct 16, 2024··
Update model_spec.py
1 parent 1ec999c commit 173f7cb

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
 

‎python/ctranslate2/specs/model_spec.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -749,15 +749,15 @@ def num_bytes(self) -> int:
749749
def to_bytes(self) -> bytes:
750750
max_size = 2**31 - 1
751751
num_bytes = self.num_bytes()
752-
output = b""
752+
chunks = []
753753
offset = 0
754754
while num_bytes > 0:
755755
chunk_size = max_size if num_bytes > max_size else num_bytes
756756
chunk = ctypes.string_at(self.tensor.data_ptr() + offset, chunk_size)
757-
output += chunk
757+
chunks.append(chunk) # Collect chunks in a list
758758
offset += chunk_size
759759
num_bytes -= chunk_size
760-
return output
760+
return b"".join(chunks)
761761

762762
def _to(self, dtype: str) -> Variable:
763763
dtype = getattr(torch, dtype)

0 commit comments

Comments
 (0)
Please sign in to comment.