MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / to_bytes

Method to_bytes

python/ctranslate2/specs/model_spec.py:746–757  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

744 return self.tensor.numel() * self.tensor.element_size()
745
746 def to_bytes(self) -> bytes:
747 max_size = 2**31 - 1
748 num_bytes = self.num_bytes()
749 output = b""
750 offset = 0
751 while num_bytes > 0:
752 chunk_size = max_size if num_bytes > max_size else num_bytes
753 chunk = ctypes.string_at(self.tensor.data_ptr() + offset, chunk_size)
754 output += chunk
755 offset += chunk_size
756 num_bytes -= chunk_size
757 return output
758
759 def _to(self, dtype: str) -> Variable:
760 dtype = getattr(torch, dtype)

Callers

nothing calls this directly

Calls 1

num_bytesMethod · 0.95

Tested by

no test coverage detected