From: Nicolas Patry Date: Thu, 24 Feb 2022 18:27:51 +0000 (+0100) Subject: ByteArray (to be writeable for torch support). X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=74ca280a76806e0322e8c1cc0a37b2f0ec1a487f;p=safetensors.git ByteArray (to be writeable for torch support). --- diff --git a/bindings/python/py_src/safetensors/__init__.py b/bindings/python/py_src/safetensors/__init__.py index bc52d71..d830908 100644 --- a/bindings/python/py_src/safetensors/__init__.py +++ b/bindings/python/py_src/safetensors/__init__.py @@ -7,18 +7,12 @@ import torch def save(tensor_dict: Dict[str, np.ndarray]) -> bytes: - import datetime - - start = datetime.datetime.now() flattened = { k: {"dtype": v.dtype.name, "shape": v.shape, "data": v.tobytes()} for k, v in tensor_dict.items() } - print("Flattened", datetime.datetime.now() - start) serialized = serialize(flattened) - print("Serialized", datetime.datetime.now() - start) result = bytes(serialized) - print("Bytes", datetime.datetime.now() - start) return result diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 60dca86..4e7039d 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -1,6 +1,6 @@ use pyo3::exceptions; use pyo3::prelude::*; -use pyo3::types::{PyBytes, PyDict, PyList}; +use pyo3::types::{PyByteArray, PyBytes, PyDict, PyList}; use safetensors::{Dtype, SafeTensor, SafeTensorBorrowed, Tensor}; use std::collections::HashMap; @@ -59,7 +59,7 @@ fn deserialize(py: Python, bytes: &[u8]) -> PyResult