depot/third_party/nixpkgs/pkgs/development/python-modules/pytorch-metric-learning/default.nix
Default email 7e47f3658e Project import generated by Copybara.
GitOrigin-RevId: 1925c603f17fc89f4c8f6bf6f631a802ad85d784
2024-09-26 11:04:55 +00:00

111 lines
2.4 KiB
Nix

{
stdenv,
lib,
buildPythonPackage,
fetchFromGitHub,
isPy27,
config,
# build-system
setuptools,
# dependencies
numpy,
scikit-learn,
torch,
tqdm,
# optional-dependencies
faiss,
tensorboard,
# tests
cudaSupport ? config.cudaSupport,
pytestCheckHook,
torchvision
}:
buildPythonPackage rec {
pname = "pytorch-metric-learning";
version = "2.6.0";
pyproject = true;
disabled = isPy27;
src = fetchFromGitHub {
owner = "KevinMusgrave";
repo = pname;
rev = "refs/tags/v${version}";
hash = "sha256-xlTqUUF+tUIbULd1B8XR18Kxd7kl2TRKdbp0GoAfi4g=";
};
build-system = [
setuptools
];
dependencies = [
numpy
torch
scikit-learn
tqdm
];
optional-dependencies = {
with-hooks = [
# TODO: record-keeper
faiss
tensorboard
];
with-hooks-cpu = [
# TODO: record-keeper
faiss
tensorboard
];
};
preCheck = ''
export HOME=$TMP
export TEST_DEVICE=cpu
export TEST_DTYPES=float32,float64 # half-precision tests fail on CPU
'';
# package only requires `unittest`, but use `pytest` to exclude tests
nativeCheckInputs = [
pytestCheckHook
torchvision
] ++ lib.flatten (lib.attrValues optional-dependencies);
disabledTests = [
# network access
"test_tuplestoweights_sampler"
"test_metric_loss_only"
"test_add_to_indexer"
"test_get_nearest_neighbors"
"test_list_of_text"
"test_untrained_indexer"
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
# AttributeError: module 'torch.distributed' has no attribute 'init_process_group'
"test_single_proc"
] ++ lib.optionals cudaSupport [
# crashes with SIGBART
"test_accuracy_calculator_and_faiss_with_torch_and_numpy"
"test_accuracy_calculator_large_k"
"test_custom_knn"
"test_global_embedding_space_tester"
"test_global_two_stream_embedding_space_tester"
"test_index_type"
"test_k_warning"
"test_many_tied_distances"
"test_query_within_reference"
"test_tied_distances"
"test_with_same_parent_label_tester"
];
meta = {
description = "Metric learning library for PyTorch";
homepage = "https://github.com/KevinMusgrave/pytorch-metric-learning";
changelog = "https://github.com/KevinMusgrave/pytorch-metric-learning/releases/tag/v${version}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ bcdarwin ];
};
}