Skip to content

Updates for Pytorch 2.7 #8429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open

Updates for Pytorch 2.7 #8429

wants to merge 13 commits into from

Conversation

ericspod
Copy link
Member

Description

This will update MONAI to be compatible with PyTorch 2.7. There appear to be few code changes with this release so hopefully this will be simply a matter of updating versions.

Types of changes

  • 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.

Signed-off-by: Eric Kerfoot <[email protected]>
@ericspod ericspod requested review from Copilot, Nic-Ma and KumoLiu April 25, 2025 11:38
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates MONAI’s torch dependency to a newer version aiming for improved compatibility with PyTorch. The changes include:

  • Increasing the minimum torch version in pyproject.toml from 2.3.0 to 2.4.1.
  • Updating the installation command in the GitHub Actions workflow (pythonapp.yml) accordingly.
  • Modifying the torch version matrix in the minimal workflow (pythonapp-min.yml).

Reviewed Changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 3 comments.

File Description
pyproject.toml Updated minimum torch dependency and Black target versions
.github/workflows/pythonapp.yml Updated torch installation command to new dependency
.github/workflows/pythonapp-min.yml Revised torch version matrix for testing
Files not reviewed (2)
  • docs/requirements.txt: Language not supported
  • setup.cfg: Language not supported

Signed-off-by: Eric Kerfoot <[email protected]>
Signed-off-by: Eric Kerfoot <[email protected]>
@ericspod
Copy link
Member Author

It's possible the CPU provided by the Windows runner is too old for PyTorch 2.7 which may now require instructions it doesn't have.

@ericspod
Copy link
Member Author

The issue with Windows appears to be related to float 64 calculations, specifically with RandRotate in tests\integration\test_pad_collation.py. This doesn't appear to be pad collation related and goes away if float 32 is used as the dtype. I'm investigating further.

@ericspod
Copy link
Member Author

I think I've traced the issue to apparently a bug in grid_sample, I've raised an issue here on the PyTorch repo.

@KumoLiu
Copy link
Contributor

KumoLiu commented Apr 29, 2025

I think I've traced the issue to apparently a bug in grid_sample, I've raised an issue here on the PyTorch repo.

Thank you for looking into this! Instead of waiting for a fix from PyTorch, do you think it's possible to implement a workaround by altering the dtype for Windows operating systems?

@ericspod
Copy link
Member Author

do you think it's possible to implement a workaround by altering the dtype for Windows operating systems?

I'm looking into that now and will hopefully have something soon. We may have to convert to float32 and back in places so we may have knock-on precision issues.

@KumoLiu
Copy link
Contributor

KumoLiu commented Apr 30, 2025

We may need waiting for the release from torch-tensorrt to support PyTorch2.7.
https://pypi.org/project/torch-tensorrt/#history

@ericspod
Copy link
Member Author

ericspod commented May 1, 2025

Hi @KumoLiu this got through the Windows tests now. I raised the issue with PyTorch so hopefully version 2.7.1 will resolve the issue, in the meantime we can run the blossom tests and discuss whether to merge this.

Signed-off-by: Eric Kerfoot <[email protected]>
@KumoLiu
Copy link
Contributor

KumoLiu commented May 2, 2025

/build

@KumoLiu
Copy link
Contributor

KumoLiu commented May 2, 2025

Error log:

[2025-05-02T05:07:25.738Z]   Attempting uninstall: setuptools
[2025-05-02T05:07:25.738Z]     Found existing installation: setuptools 45.2.0
[2025-05-02T05:07:25.738Z]     Uninstalling setuptools-45.2.0:
[2025-05-02T05:07:25.738Z]       Successfully uninstalled setuptools-45.2.0
[2025-05-02T05:08:04.452Z] ERROR: Exception:
[2025-05-02T05:08:04.452Z] Traceback (most recent call last):
[2025-05-02T05:08:04.452Z]   File "/usr/lib/python3.9/py_compile.py", line 144, in compile
[2025-05-02T05:08:04.452Z]     code = loader.source_to_code(source_bytes, dfile or file,
[2025-05-02T05:08:04.452Z]   File "<frozen importlib._bootstrap_external>", line 918, in source_to_code
[2025-05-02T05:08:04.452Z]   File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
[2025-05-02T05:08:04.452Z]   File "/usr/local/lib/python3.9/dist-packages/pytype/tools/merge_pyi/test_data/parse_error.py", line 2
[2025-05-02T05:08:04.452Z]     def f(*): pass
[2025-05-02T05:08:04.452Z]            ^
[2025-05-02T05:08:04.452Z] SyntaxError: named arguments must follow bare *
[2025-05-02T05:08:04.452Z] 
[2025-05-02T05:08:04.452Z] During handling of the above exception, another exception occurred:
[2025-05-02T05:08:04.452Z] 
[2025-05-02T05:08:04.452Z] Traceback (most recent call last):
[2025-05-02T05:08:04.452Z]   File "/usr/lib/python3.9/compileall.py", line 238, in compile_file
[2025-05-02T05:08:04.452Z]     ok = py_compile.compile(fullname, cfile, dfile, True,
[2025-05-02T05:08:04.452Z]   File "/usr/lib/python3.9/py_compile.py", line 150, in compile
[2025-05-02T05:08:04.452Z]     raise py_exc
[2025-05-02T05:08:04.452Z] py_compile.PyCompileError:   File "/usr/local/lib/python3.9/dist-packages/pytype/tools/merge_pyi/test_data/parse_error.py", line 2
[2025-05-02T05:08:04.452Z]     def f(*): pass
[2025-05-02T05:08:04.452Z]            ^
[2025-05-02T05:08:04.452Z] SyntaxError: named arguments must follow bare *
[2025-05-02T05:08:04.452Z] 
[2025-05-02T05:08:04.452Z] 
[2025-05-02T05:08:04.452Z] During handling of the above exception, another exception occurred:
[2025-05-02T05:08:04.452Z] 
[2025-05-02T05:08:04.452Z] Traceback (most recent call last):
[2025-05-02T05:08:04.452Z]   File "/usr/local/lib/python3.9/dist-packages/pip/_internal/cli/base_command.py", line 105, in _run_wrapper
[2025-05-02T05:08:04.452Z]     status = _inner_run()
[2025-05-02T05:08:04.452Z]   File "/usr/local/lib/python3.9/dist-packages/pip/_internal/cli/base_command.py", line 96, in _inner_run
[2025-05-02T05:08:04.452Z]     return self.run(options, args)
[2025-05-02T05:08:04.452Z]   File "/usr/local/lib/python3.9/dist-packages/pip/_internal/cli/req_command.py", line 68, in wrapper
[2025-05-02T05:08:04.452Z]     return func(self, options, args)
[2025-05-02T05:08:04.452Z]   File "/usr/local/lib/python3.9/dist-packages/pip/_internal/commands/install.py", line 459, in run
[2025-05-02T05:08:04.452Z]     installed = install_given_reqs(
[2025-05-02T05:08:04.452Z]   File "/usr/local/lib/python3.9/dist-packages/pip/_internal/req/__init__.py", line 83, in install_given_reqs
[2025-05-02T05:08:04.452Z]     requirement.install(
[2025-05-02T05:08:04.452Z]   File "/usr/local/lib/python3.9/dist-packages/pip/_internal/req/req_install.py", line 867, in install
[2025-05-02T05:08:04.452Z]     install_wheel(
[2025-05-02T05:08:04.452Z]   File "/usr/local/lib/python3.9/dist-packages/pip/_internal/operations/install/wheel.py", line 728, in install_wheel
[2025-05-02T05:08:04.452Z]     _install_wheel(
[2025-05-02T05:08:04.452Z]   File "/usr/local/lib/python3.9/dist-packages/pip/_internal/operations/install/wheel.py", line 614, in _install_wheel
[2025-05-02T05:08:04.452Z]     success = compileall.compile_file(path, force=True, quiet=True)
[2025-05-02T05:08:04.452Z]   File "/usr/lib/python3.9/compileall.py", line 255, in compile_file
[2025-05-02T05:08:04.452Z]     msg = err.msg.encode(sys.stdout.encoding,
[2025-05-02T05:08:04.452Z] TypeError: encode() argument 'encoding' must be str, not None
[2025-05-02T05:08:04.452Z] 

@KumoLiu
Copy link
Contributor

KumoLiu commented May 2, 2025

/build

Signed-off-by: Eric Kerfoot <[email protected]>
@ericspod
Copy link
Member Author

ericspod commented May 2, 2025

The blossom issue is related to the current pytype version, so I've added <=2024.4.11 to the requirements-dev.txt file for it.

@KumoLiu
Copy link
Contributor

KumoLiu commented May 2, 2025

/build

@KumoLiu
Copy link
Contributor

KumoLiu commented May 2, 2025

The blossom issue is related to the current pytype version, so I've added <=2024.4.11 to the requirements-dev.txt file for it.

Seems related to the new version of the pip: https://pypi.org/project/pip/#history
I tried downgrade it to 25.0.1, then it works.

raise issue here: google/pytype#1909

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants