1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 setuptools,
9
10 # dependencies
11 numpy,
12 packaging,
13 torch,
14 typing-extensions,
15
16 # tests
17 onnx,
18 pytestCheckHook,
19 torchvision,
20 pythonAtLeast,
21}:
22
23buildPythonPackage rec {
24 pname = "pytorch-pfn-extras";
25 version = "0.8.2";
26 pyproject = true;
27
28 src = fetchFromGitHub {
29 owner = "pfnet";
30 repo = "pytorch-pfn-extras";
31 tag = "v${version}";
32 hash = "sha256-FQwCdn9zUWHyUYAGHPNxQXN7O0bSLBHJrByxzCxUtio=";
33 };
34
35 build-system = [ setuptools ];
36
37 dependencies = [
38 numpy
39 packaging
40 torch
41 typing-extensions
42 ];
43
44 nativeCheckInputs = [
45 onnx
46 pytestCheckHook
47 torchvision
48 ];
49
50 pytestFlagsArray = [
51 # Requires CUDA access which is not possible in the nix environment.
52 "-m 'not gpu and not mpi'"
53 "-Wignore::DeprecationWarning"
54 ];
55
56 pythonImportsCheck = [ "pytorch_pfn_extras" ];
57
58 disabledTests =
59 [
60 # AssertionError: assert 4 == 0
61 # where 4 = <MagicMock id='140733587469184'>.call_count
62 "test_lr_scheduler_wait_for_first_optimizer_step"
63 ]
64 ++ lib.optionals (pythonAtLeast "3.13") [
65 # RuntimeError: Dynamo is not supported on Python 3.13+
66 "test_register"
67 ]
68 ++ lib.optionals stdenv.hostPlatform.isDarwin [
69 # torch.distributed was not available on darwin at one point; revisit
70 "test_create_distributed_evaluator"
71 "test_distributed_evaluation"
72 "test_distributed_evaluator_progress_bar"
73 ];
74
75 disabledTestPaths =
76 [
77 # Requires optuna which is currently (2022-02-16) marked as broken.
78 "tests/pytorch_pfn_extras_tests/test_config_types.py"
79
80 # requires onnxruntime which was removed because of poor maintainability
81 # See https://github.com/NixOS/nixpkgs/pull/105951 https://github.com/NixOS/nixpkgs/pull/155058
82 "tests/pytorch_pfn_extras_tests/onnx_tests/test_annotate.py"
83 "tests/pytorch_pfn_extras_tests/onnx_tests/test_as_output.py"
84 "tests/pytorch_pfn_extras_tests/onnx_tests/test_export.py"
85 "tests/pytorch_pfn_extras_tests/onnx_tests/test_export_testcase.py"
86 "tests/pytorch_pfn_extras_tests/onnx_tests/test_lax.py"
87 "tests/pytorch_pfn_extras_tests/onnx_tests/test_load_model.py"
88 "tests/pytorch_pfn_extras_tests/onnx_tests/test_torchvision.py"
89 "tests/pytorch_pfn_extras_tests/onnx_tests/utils.py"
90
91 # RuntimeError: No Op registered for Gradient with domain_version of 9
92 "tests/pytorch_pfn_extras_tests/onnx_tests/test_grad.py"
93
94 # torch._dynamo.exc.BackendCompilerFailed: backend='compiler_fn' raised:
95 # AttributeError: module 'torch.fx.experimental.proxy_tensor' has no attribute 'maybe_disable_fake_tensor_mode'
96 "tests/pytorch_pfn_extras_tests/dynamo_tests/test_compile.py"
97 ]
98 ++ lib.optionals (stdenv.hostPlatform.isDarwin) [
99 # torch.distributed was not available on darwin at one point; revisit
100 "tests/pytorch_pfn_extras_tests/distributed_tests/test_distributed_validation_sampler.py"
101 "tests/pytorch_pfn_extras_tests/nn_tests/parallel_tests/test_distributed.py"
102 "tests/pytorch_pfn_extras_tests/profiler_tests/test_record.py"
103 "tests/pytorch_pfn_extras_tests/profiler_tests/test_time_summary.py"
104 "tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_accumulate.py"
105 "tests/pytorch_pfn_extras_tests/training_tests/extensions_tests/test_sharded_snapshot.py"
106 ]
107 ++ lib.optionals (stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64) [
108 # RuntimeError: internal error
109 # convolution (e.g. F.conv3d) causes runtime error
110 "tests/pytorch_pfn_extras_tests/nn_tests/modules_tests/test_lazy_conv.py"
111 ];
112
113 meta = {
114 description = "Supplementary components to accelerate research and development in PyTorch";
115 homepage = "https://github.com/pfnet/pytorch-pfn-extras";
116 changelog = "https://github.com/pfnet/pytorch-pfn-extras/releases/tag/${src.tag}";
117 license = lib.licenses.mit;
118 maintainers = with lib.maintainers; [ samuela ];
119 badPlatforms = [
120 # test_profile_report is broken on darwin
121 lib.systems.inspect.patterns.isDarwin
122 ];
123 };
124}