2023-04-29 16:46:19 +00:00
|
|
|
{ stdenv
|
|
|
|
, lib
|
|
|
|
, buildPythonPackage
|
2023-05-24 13:37:59 +00:00
|
|
|
, cargo
|
2023-04-29 16:46:19 +00:00
|
|
|
, fetchFromGitHub
|
|
|
|
, h5py
|
|
|
|
, numpy
|
|
|
|
, pythonOlder
|
|
|
|
, pytestCheckHook
|
2023-05-24 13:37:59 +00:00
|
|
|
, rustc
|
2023-04-29 16:46:19 +00:00
|
|
|
, rustPlatform
|
|
|
|
, setuptools-rust
|
|
|
|
, torch
|
|
|
|
, libiconv
|
|
|
|
}:
|
|
|
|
|
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "safetensors";
|
2024-02-07 01:22:34 +00:00
|
|
|
version = "0.4.2";
|
|
|
|
pyproject = true;
|
2023-04-29 16:46:19 +00:00
|
|
|
|
|
|
|
disabled = pythonOlder "3.7";
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "huggingface";
|
2024-02-07 01:22:34 +00:00
|
|
|
repo = "safetensors";
|
2023-04-29 16:46:19 +00:00
|
|
|
rev = "refs/tags/v${version}";
|
2024-02-07 01:22:34 +00:00
|
|
|
hash = "sha256-hdPUI8k7CCQwt2C/AsjUHRmAL6ob+yCN97KkWtqOQL8=";
|
2023-04-29 16:46:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cargoDeps = rustPlatform.fetchCargoTarball {
|
2023-07-15 17:15:38 +00:00
|
|
|
inherit src;
|
2023-08-04 22:07:22 +00:00
|
|
|
sourceRoot = "${src.name}/bindings/python";
|
2024-02-07 01:22:34 +00:00
|
|
|
hash = "sha256-7n9aYlha6IaPsZ2zMfD5EIkrk8ENwMBwj41s6QU7ml0=";
|
2023-04-29 16:46:19 +00:00
|
|
|
};
|
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
sourceRoot = "${src.name}/bindings/python";
|
2023-04-29 16:46:19 +00:00
|
|
|
|
2023-05-24 13:37:59 +00:00
|
|
|
nativeBuildInputs = [
|
2023-04-29 16:46:19 +00:00
|
|
|
setuptools-rust
|
2023-05-24 13:37:59 +00:00
|
|
|
cargo
|
|
|
|
rustc
|
|
|
|
rustPlatform.cargoSetupHook
|
2024-02-07 01:22:34 +00:00
|
|
|
rustPlatform.maturinBuildHook
|
2023-04-29 16:46:19 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = lib.optionals stdenv.isDarwin [ libiconv ];
|
|
|
|
|
|
|
|
nativeCheckInputs = [
|
|
|
|
h5py numpy pytestCheckHook torch
|
|
|
|
];
|
|
|
|
pytestFlagsArray = [ "tests" ];
|
|
|
|
# don't require PaddlePaddle (not in Nixpkgs), Flax, or Tensorflow (onerous) to run tests:
|
|
|
|
disabledTestPaths = [
|
|
|
|
"tests/test_flax_comparison.py"
|
|
|
|
"tests/test_paddle_comparison.py"
|
|
|
|
"tests/test_tf_comparison.py"
|
2024-02-07 01:22:34 +00:00
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
# don't require mlx (not in Nixpkgs) to run tests
|
|
|
|
"tests/test_mlx_comparison.py"
|
2023-04-29 16:46:19 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
pythonImportsCheck = [
|
|
|
|
"safetensors"
|
|
|
|
];
|
|
|
|
|
|
|
|
meta = with lib; {
|
|
|
|
homepage = "https://github.com/huggingface/safetensors";
|
|
|
|
description = "Fast (zero-copy) and safe (unlike pickle) format for storing tensors";
|
|
|
|
changelog = "https://github.com/huggingface/safetensors/releases/tag/v${version}";
|
|
|
|
license = licenses.asl20;
|
|
|
|
maintainers = with maintainers; [ bcdarwin ];
|
|
|
|
};
|
|
|
|
}
|