2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
lib,
|
2024-09-19 14:19:46 +00:00
|
|
|
stdenv,
|
2024-06-05 15:53:02 +00:00
|
|
|
buildPythonPackage,
|
|
|
|
fetchFromGitHub,
|
2024-09-19 14:19:46 +00:00
|
|
|
rustPlatform,
|
|
|
|
|
|
|
|
# nativeBuildInputs
|
|
|
|
cargo,
|
|
|
|
rustc,
|
|
|
|
setuptools-rust,
|
|
|
|
|
|
|
|
# buildInputs
|
|
|
|
libiconv,
|
|
|
|
|
|
|
|
# tests
|
2024-06-05 15:53:02 +00:00
|
|
|
h5py,
|
|
|
|
numpy,
|
|
|
|
pytestCheckHook,
|
|
|
|
torch,
|
2023-04-29 16:46:19 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
buildPythonPackage rec {
|
|
|
|
pname = "safetensors";
|
2024-09-19 14:19:46 +00:00
|
|
|
version = "0.4.5";
|
2024-02-07 01:22:34 +00:00
|
|
|
pyproject = true;
|
2023-04-29 16:46:19 +00:00
|
|
|
|
|
|
|
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-09-19 14:19:46 +00:00
|
|
|
hash = "sha256-gr4hBbecaGHaoNhRQQXWfLfNB0/wQPKftSiTnGgngog=";
|
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-09-19 14:19:46 +00:00
|
|
|
hash = "sha256-zDXzEVvmJF1dEVUFGBc3losr9U1q/qJCjNFkdJ/pCd4=";
|
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 = [
|
|
|
|
cargo
|
|
|
|
rustc
|
|
|
|
rustPlatform.cargoSetupHook
|
2024-02-07 01:22:34 +00:00
|
|
|
rustPlatform.maturinBuildHook
|
2024-09-19 14:19:46 +00:00
|
|
|
setuptools-rust
|
2023-04-29 16:46:19 +00:00
|
|
|
];
|
|
|
|
|
2024-09-26 11:04:55 +00:00
|
|
|
buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];
|
2023-04-29 16:46:19 +00:00
|
|
|
|
|
|
|
nativeCheckInputs = [
|
2024-06-05 15:53:02 +00:00
|
|
|
h5py
|
|
|
|
numpy
|
|
|
|
pytestCheckHook
|
|
|
|
torch
|
2023-04-29 16:46:19 +00:00
|
|
|
];
|
|
|
|
pytestFlagsArray = [ "tests" ];
|
|
|
|
# don't require PaddlePaddle (not in Nixpkgs), Flax, or Tensorflow (onerous) to run tests:
|
2024-06-05 15:53:02 +00:00
|
|
|
disabledTestPaths =
|
|
|
|
[
|
|
|
|
"tests/test_flax_comparison.py"
|
|
|
|
"tests/test_paddle_comparison.py"
|
|
|
|
"tests/test_tf_comparison.py"
|
|
|
|
]
|
2024-09-26 11:04:55 +00:00
|
|
|
++ lib.optionals stdenv.hostPlatform.isDarwin [
|
2024-06-05 15:53:02 +00:00
|
|
|
# don't require mlx (not in Nixpkgs) to run tests
|
|
|
|
"tests/test_mlx_comparison.py"
|
|
|
|
];
|
2023-04-29 16:46:19 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
pythonImportsCheck = [ "safetensors" ];
|
2023-04-29 16:46:19 +00:00
|
|
|
|
2024-09-19 14:19:46 +00:00
|
|
|
meta = {
|
2023-04-29 16:46:19 +00:00
|
|
|
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}";
|
2024-09-19 14:19:46 +00:00
|
|
|
license = lib.licenses.asl20;
|
|
|
|
maintainers = with lib.maintainers; [ bcdarwin ];
|
2023-04-29 16:46:19 +00:00
|
|
|
};
|
|
|
|
}
|