]> khamidou — GitHub mirrors - safetensors.git/commitdiff
Use np.prod for compatibility with Python 3.7 (#14)
authorSylvain Gugger <35901082+sgugger@users.noreply.github.com>
Fri, 30 Sep 2022 11:36:02 +0000 (07:36 -0400)
committerGitHub <noreply@github.com>
Fri, 30 Sep 2022 11:36:02 +0000 (13:36 +0200)
bindings/python/py_src/safetensors/torch.py

index 2a5485ddac612e1431d09c53d6149ae7e871ad86..8e36a936adecd46a724bf01601ed455c7e3f7d11 100644 (file)
@@ -84,7 +84,7 @@ def _tobytes(tensor: torch.Tensor) -> bytes:
     import ctypes
     import numpy as np
 
-    length = math.prod(tensor.shape)
+    length = np.prod(tensor.shape).item()
     bytes_per_item = _SIZE[tensor.dtype]
 
     total_bytes = length * bytes_per_item