WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Upgrade PyTorch to 2.3.1+ to support NumPy 2.0 #317

@tallamjr

Description

@tallamjr

Summary

Currently, the project is pinned to PyTorch 2.3.0, which is incompatible with NumPy 2.0. This requires constraining NumPy to <2.0, preventing users from benefiting from NumPy 2.0's performance improvements and new features.

Current State

  • PyTorch version: 2.3.0 (pinned in pyproject.toml)
  • NumPy constraint: >=1.24,<2.0 (added as workaround)
  • Issue: PyTorch 2.3.0 was compiled against NumPy 1.x C API and fails on Windows with NumPy 2.0+

Problem Details

Error on Windows with NumPy 2.0:

RuntimeError: Numpy is not available
UserWarning: Failed to initialize NumPy: _ARRAY_API not found

Affected operations:

  • torch.from_numpy() conversions
  • torchaudio.load() operations
  • Sparse tensor operations
  • Any torch/numpy interoperability

Root cause:
PyTorch binaries must be recompiled against NumPy 2.0's new C API to support both NumPy 1.x and 2.x. PyTorch 2.3.0 predates NumPy 2.0 (released June 2024) and lacks this compatibility.

Proposed Solution

Upgrade PyTorch to version 2.3.1 or later:

torch = [
    "torch>=2.3.1",  # NumPy 2.0 compatible
    "torchvision>=0.18.1",
    "torchaudio>=2.3.1",
]

Then remove the NumPy upper bound:

"numpy>=1.24",  # NumPy 2.0 supported with PyTorch 2.3.1+

Benefits

  1. NumPy 2.0 features: Access to performance improvements and new functionality
  2. Future compatibility: Aligns with ecosystem migration to NumPy 2.0
  3. Simplified dependencies: Removes artificial version constraints
  4. Better Windows support: Eliminates Windows-specific NumPy compatibility issues

Considerations

Python version compatibility:

  • PyTorch 2.3.1: Supports Python 3.10-3.12
  • PyTorch 2.4+: Adds Python 3.13 support (if we want to re-enable it in CI)
  • PyTorch 2.9+: Adds Python 3.14 preview support

Testing requirements:

  • Verify all tests pass on Linux, macOS, Windows
  • Check for any breaking changes in PyTorch 2.3.1+ release notes
  • Regenerate uv.lock after version updates

References

Upstream issues:

PyTorch releases:

Related PRs:

Acceptance Criteria

  • Upgrade PyTorch to 2.3.1+ (or 2.4+ if Python 3.13 support desired)
  • Remove <2.0 constraint from NumPy dependency
  • Regenerate uv.lock file
  • All CI tests pass on Linux, macOS, Windows
  • Update documentation if there are any breaking changes
  • Consider if torchvision/torchaudio versions need updating for compatibility

Priority

Medium - Current workaround (numpy<2.0) is functional, but upgrading provides better long-term compatibility and performance.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions