Skip to content

Add Python 3.12-3.14 support - #6

Open
HasinthakaPiyumal wants to merge 1 commit into
JeremieMelo:mainfrom
HasinthakaPiyumal:fix/python-3.14-support
Open

Add Python 3.12-3.14 support#6
HasinthakaPiyumal wants to merge 1 commit into
JeremieMelo:mainfrom
HasinthakaPiyumal:fix/python-3.14-support

Conversation

@HasinthakaPiyumal

Copy link
Copy Markdown

Summary

  • Fixes compatibility with Python 3.12+ by removing deprecated distutils module usage
  • Adds fallback shim for mmcv builder functions when mmcv is unavailable (fails to build on Python 3.12+)
  • Guards all CUDA-specific code paths to gracefully fall back to CPU
  • Updates dependency version constraints for Python 3.12+ compatibility
  • Moves tensorflow to optional dependency (pip install torchonn[tf]) since no Python 3.14 wheel exists

Key changes

File Change
setup.py Remove distutils, guard torch import, read version from file, update deps/classifiers
torchonn/layers/base_layer.py mmcv fallback shim, fix circular import
torchonn/op/matrix_parametrization.py Handle missing CUDA extension, fix .detach().numpy()
torchonn/layers/mzi_conv2d.py Fix driver="gesvd" (CUDA-only arg)
15+ files Replace hardcoded torch.device("cuda:0") with CPU fallback
unitest/* Support CPU-only test execution

Dependency changes

  • numpy>=1.26.0 (was 1.19.2)
  • torch>=2.1.0 (was 1.13.0)
  • torchvision>=0.16.0 (was 0.9.0.dev)
  • scipy>=1.11.0, scikit-learn>=1.3.0, matplotlib>=3.8.0
  • torchonn-pyutils>=0.0.2 (was pyutils>=0.0.1 — wrong package name)
  • mmengine>=0.10.0 (new — needed for mmcv fallback)
  • tensorflow moved to extras_require
  • python_requires=">=3.10"

Test plan

  • Verified pip install -e . succeeds on Python 3.14.3
  • Verified import torchonn and all submodule imports work
  • 11/13 unit tests pass on CPU-only Python 3.14.3 (2 failures are numerical precision differences between CPU/CUDA SVD, not Python version issues)

Note: torchonn-pyutils also needs a fix (tensorflow as hard dep). A separate PR should be opened on JeremieMelo/pyutility to move tensorflow to optional dependencies.

🤖 Generated with Claude Code

- Remove deprecated `distutils` imports from setup.py (removed in Python 3.12)
- Guard `import torch` in setup.py with try/except for clean pip install
- Read version from file instead of importing torchonn at build time
- Add mmcv fallback shim in base_layer.py (mmcv fails to build on Python 3.12+)
- Fix circular import by deferring mobilevit import in base_layer.py
- Fix `matrix_parametrization_cuda` to gracefully handle missing CUDA extension
- Fix `.cpu().numpy()` -> `.detach().cpu().numpy()` for newer PyTorch
- Fix `torch.linalg.svd(driver="gesvd")` to only pass driver on CUDA tensors
- Fix raw string escape sequence warning in mrr_op.py
- Replace hardcoded `torch.device("cuda:0")` defaults with CPU fallback
- Update dependency versions for Python 3.12+ compatibility
- Move tensorflow to optional dependency (no Python 3.14 wheel available)
- Fix wrong package name: `pyutils` -> `torchonn-pyutils`
- Add mmengine to dependencies
- Update python_requires to >=3.10 and add 3.11-3.14 classifiers
- Fix CleanCommand for cross-platform support (shutil instead of rm)
- Update tests to support CPU-only execution

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant