From e61e87240d0eabc9749a67ccebe38dca620d48b4 Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Thu, 2 Jan 2025 18:07:11 +0100 Subject: [PATCH] Memory map as private pure copy. (#553) --- bindings/python/Cargo.toml | 2 +- bindings/python/src/lib.rs | 2 +- flake.nix | 1 + safetensors/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/bindings/python/Cargo.toml b/bindings/python/Cargo.toml index 81923eb3..c963fd64 100644 --- a/bindings/python/Cargo.toml +++ b/bindings/python/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "safetensors-python" -version = "0.5.0-dev.0" +version = "0.5.1-dev.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/bindings/python/src/lib.rs b/bindings/python/src/lib.rs index ecd318c7..21062bd4 100644 --- a/bindings/python/src/lib.rs +++ b/bindings/python/src/lib.rs @@ -406,7 +406,7 @@ impl Open { // SAFETY: Mmap is used to prevent allocating in Rust // before making a copy within Python. - let buffer = unsafe { MmapOptions::new().map(&file)? }; + let buffer = unsafe { MmapOptions::new().map_copy_read_only(&file)? }; let (n, metadata) = SafeTensors::read_metadata(&buffer).map_err(|e| { SafetensorError::new_err(format!("Error while deserializing header: {e:?}")) diff --git a/flake.nix b/flake.nix index 5711a08e..d9effbaf 100644 --- a/flake.nix +++ b/flake.nix @@ -32,6 +32,7 @@ postShellHook = '' unset SOURCE_DATE_EPOCH ''; + LD_LIBRARY_PATH = "$LD_LIBRARY_PATH:${pkgs.stdenv.cc.cc.lib}/lib"; }; } diff --git a/safetensors/Cargo.toml b/safetensors/Cargo.toml index b2d20b8e..d59a6e18 100644 --- a/safetensors/Cargo.toml +++ b/safetensors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "safetensors" -version = "0.5.0-dev.0" +version = "0.5.1-dev.0" edition = "2021" homepage = "https://github.com/huggingface/safetensors" repository = "https://github.com/huggingface/safetensors"