diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 27dc28c0..dd716eed 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,13 +31,14 @@ repos: "--", "-Dwarnings", ] - - repo: https://github.com/psf/black - rev: 22.3.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.12.8 hooks: - - id: black - name: "Python (black)" - args: ["--line-length", "119", "--target-version", "py35"] - types: ["python"] + # Run the linter. + - id: ruff-check + # Run the formatter. + - id: ruff-format - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: v0.11.11 diff --git a/bindings/python/Cargo.lock b/bindings/python/Cargo.lock new file mode 100644 index 00000000..c2d1b3aa --- /dev/null +++ b/bindings/python/Cargo.lock @@ -0,0 +1,234 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "indoc" +version = "2.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd" + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "libc" +version = "0.2.174" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" + +[[package]] +name = "memchr" +version = "2.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" + +[[package]] +name = "memmap2" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3f7eed9d3848f8b98834af67102b720745c4ec028fcd0aa0239277e7de374f" +dependencies = [ + "libc", +] + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "portable-atomic" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "pyo3" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8970a78afe0628a3e3430376fc5fd76b6b45c4d43360ffd6cdd40bdde72b682a" +dependencies = [ + "indoc", + "libc", + "memoffset", + "once_cell", + "portable-atomic", + "pyo3-build-config", + "pyo3-ffi", + "pyo3-macros", + "unindent", +] + +[[package]] +name = "pyo3-build-config" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "458eb0c55e7ece017adeba38f2248ff3ac615e53660d7c71a238d7d2a01c7598" +dependencies = [ + "once_cell", + "target-lexicon", +] + +[[package]] +name = "pyo3-ffi" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7114fe5457c61b276ab77c5055f206295b812608083644a5c5b2640c3102565c" +dependencies = [ + "libc", + "pyo3-build-config", +] + +[[package]] +name = "pyo3-macros" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8725c0a622b374d6cb051d11a0983786448f7785336139c3c94f5aa6bef7e50" +dependencies = [ + "proc-macro2", + "pyo3-macros-backend", + "quote", + "syn", +] + +[[package]] +name = "pyo3-macros-backend" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4109984c22491085343c05b0dbc54ddc405c3cf7b4374fc533f5c3313a572ccc" +dependencies = [ + "heck", + "proc-macro2", + "pyo3-build-config", + "quote", + "syn", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "safetensors" +version = "0.6.2" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "safetensors-python" +version = "0.6.2" +dependencies = [ + "memmap2", + "pyo3", + "safetensors", + "serde_json", +] + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "syn" +version = "2.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "target-lexicon" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "unindent" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3" diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index 1eb786b3..e1e21564 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "safetensors-python" -version = "0.6.2-dev.0" +version = "0.6.2" edition = "2021" rust-version = "1.74" diff --git a/bindings/python/py_src/safetensors/torch.py b/bindings/python/py_src/safetensors/torch.py index 49405bf3..f2285e0f 100644 --- a/bindings/python/py_src/safetensors/torch.py +++ b/bindings/python/py_src/safetensors/torch.py @@ -433,7 +433,7 @@ def load(data: bytes) -> Dict[str, torch.Tensor]: _float8_e8m0: 1, _float4_e2m1_x2: 1, } -if Version(torch.__version__) > Version("2.0.0"): +if Version(torch.__version__) >= Version("2.3.0"): _SIZE.update( { torch.uint64: 8, @@ -456,7 +456,7 @@ def load(data: bytes) -> Dict[str, torch.Tensor]: "F8_E4M3": _float8_e4m3fn, "F8_E5M2": _float8_e5m2, } -if Version(torch.__version__) > Version("2.0.0"): +if Version(torch.__version__) >= Version("2.3.0"): _TYPES.update( { "U64": torch.uint64, diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index 36f784b4..c039d6e4 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -33,7 +33,7 @@ struct PyView<'a> { } impl View for &PyView<'_> { - fn data(&self) -> std::borrow::Cow<[u8]> { + fn data(&self) -> std::borrow::Cow<'_, [u8]> { Cow::Borrowed(self.data.as_bytes()) } fn shape(&self) -> &[usize] { diff --git a/safetensors/Cargo.toml b/safetensors/Cargo.toml index 839d06e2..de83c0ef 100644 --- a/safetensors/Cargo.toml +++ b/safetensors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "safetensors" -version = "0.6.2-dev.0" +version = "0.6.2" edition = "2021" rust-version = "1.80" homepage = "https://github.com/huggingface/safetensors" diff --git a/safetensors/src/tensor.rs b/safetensors/src/tensor.rs index 0a4edf3d..c9ee2143 100644 --- a/safetensors/src/tensor.rs +++ b/safetensors/src/tensor.rs @@ -142,7 +142,7 @@ struct PreparedData { /// fn shape(&self) -> &[usize]{ /// &self.shape /// } -/// fn data(&self) -> Cow<[u8]>{ +/// fn data(&self) -> Cow<'_, [u8]>{ /// (&self.data).into() /// } /// fn data_len(&self) -> usize{ @@ -166,7 +166,7 @@ struct PreparedData { /// fn shape(&self) -> &[usize]{ /// &self.shape /// } -/// fn data(&self) -> Cow<[u8]>{ +/// fn data(&self) -> Cow<'_, [u8]>{ /// self.data.into() /// } /// fn data_len(&self) -> usize{ @@ -193,7 +193,7 @@ struct PreparedData { /// fn shape(&self) -> &[usize]{ /// &self.shape /// } -/// fn data(&self) -> Cow<[u8]>{ +/// fn data(&self) -> Cow<'_, [u8]>{ /// // This copies data from GPU to CPU. /// let data: Vec = self.data.to_vec(); /// data.into() @@ -211,7 +211,7 @@ pub trait View { /// The shape of the tensor fn shape(&self) -> &[usize]; /// The data of the tensor - fn data(&self) -> Cow<[u8]>; + fn data(&self) -> Cow<'_, [u8]>; /// The length of the data, in bytes. /// This is necessary as this might be faster to get than `data().len()` /// for instance for tensors residing in GPU. @@ -678,7 +678,7 @@ impl View for &TensorView<'_> { &self.shape } - fn data(&self) -> Cow<[u8]> { + fn data(&self) -> Cow<'_, [u8]> { self.data.into() } @@ -696,7 +696,7 @@ impl View for TensorView<'_> { &self.shape } - fn data(&self) -> Cow<[u8]> { + fn data(&self) -> Cow<'_, [u8]> { self.data.into() }