Skip to content

Commit 8ee3f89

Browse files
ericspodpre-commit-ci[bot]KumoLiu
authored
Updates for Pytorch 2.7 (#8429)
### Description This will update MONAI to be compatible with PyTorch 2.7.1. There appear to be few code changes with this release so hopefully this will be simply a matter of updating versions. The versions tested in the actions are now fixed to explicit version strings rather than including "latest" as a PyTorch version, this will avoid new breaking versions being released and rendering PRs unmergable. ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit * **Bug Fixes** * Implemented a platform-specific workaround to address issues with PyTorch's grid_sample on Windows with float64 CPU tensors, ensuring correct behavior in spatial transforms and resampling. * Suppressed unnecessary error messages during expected test failures to improve test output clarity. * Adjusted test tolerances on Windows to account for platform-specific numerical differences. * **Chores** * Updated dependency requirements to allow newer versions of PyTorch, with special handling for Windows. * Restricted the pytype version range for development environments. * Improved test configuration to include the latest PyTorch version in continuous integration. * Refined dependency version constraints to support PyTorch 2.7.1 and beyond. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Eric Kerfoot <[email protected]> Signed-off-by: Eric Kerfoot <[email protected]> Signed-off-by: Eric Kerfoot <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: YunLiu <[email protected]>
1 parent def4222 commit 8ee3f89

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

.github/workflows/pythonapp-min.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ jobs:
124124
strategy:
125125
fail-fast: false
126126
matrix:
127-
pytorch-version: ['2.4.1', '2.5.1', '2.6.0'] # FIXME: add 'latest' back once PyTorch 2.7 issues are resolved
127+
pytorch-version: ['2.4.1', '2.5.1', '2.6.0', '2.7.1']
128128
timeout-minutes: 40
129129
steps:
130130
- uses: actions/checkout@v4
@@ -151,11 +151,7 @@ jobs:
151151
- name: Install the dependencies
152152
run: |
153153
# min. requirements
154-
if [ ${{ matrix.pytorch-version }} == "latest" ]; then
155-
python -m pip install torch
156-
else
157-
python -m pip install torch==${{ matrix.pytorch-version }}
158-
fi
154+
python -m pip install torch==${{ matrix.pytorch-version }}
159155
python -m pip install -r requirements-min.txt
160156
python -m pip list
161157
BUILD_MONAI=0 python setup.py develop # no compile of extensions

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
-f https://download.pytorch.org/whl/cpu/torch-2.4.1%2Bcpu-cp39-cp39-linux_x86_64.whl
2-
torch>=2.4.1, <2.7.0
2+
torch>=2.4.1
33
pytorch-ignite==0.4.11
44
numpy>=1.20
55
itk>=5.2

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
requires = [
33
"wheel",
44
"setuptools",
5-
"torch>=2.4.1, <2.7.0",
5+
"torch>=2.4.1",
66
"ninja",
77
"packaging"
88
]

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pyflakes
2020
black>=25.1.0
2121
isort>=5.1, <6.0
2222
ruff
23-
pytype>=2020.6.1; platform_system != "Windows"
23+
pytype>=2020.6.1, <=2024.4.11; platform_system != "Windows"
2424
types-setuptools
2525
mypy>=1.5.0, <1.12.0
2626
ninja

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
torch>=2.4.1, <2.7.0
1+
torch>=2.4.1; platform_system != "Windows"
2+
torch>=2.4.1, !=2.7.0; platform_system == "Windows"
23
numpy>=1.24,<3.0

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ setup_requires =
4242
ninja
4343
packaging
4444
install_requires =
45-
torch>=2.4.1, <2.7.0
45+
torch>=2.4.1
4646
numpy>=1.24,<3.0
4747

4848
[options.extras_require]

tests/integration/test_pad_collation.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
from __future__ import annotations
1313

14+
import os
1415
import random
1516
import unittest
17+
from contextlib import redirect_stderr
1618
from functools import wraps
1719

1820
import numpy as np
@@ -35,7 +37,7 @@
3537
RandZoomd,
3638
ToTensor,
3739
)
38-
from monai.utils import set_determinism
40+
from monai.utils import first, set_determinism
3941

4042

4143
@wraps(pad_list_data_collate)
@@ -97,8 +99,9 @@ def test_pad_collation(self, t_type, collate_method, transform):
9799
# Default collation should raise an error
98100
loader_fail = DataLoader(dataset, batch_size=10)
99101
with self.assertRaises(RuntimeError):
100-
for _ in loader_fail:
101-
pass
102+
# stifle PyTorch error reporting, we expect failure so don't need to look at it
103+
with open(os.devnull) as f, redirect_stderr(f):
104+
_ = first(loader_fail)
102105

103106
# Padded collation shouldn't
104107
loader = DataLoader(dataset, batch_size=10, collate_fn=collate_method)

0 commit comments

Comments
 (0)