Skip to content
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

release numpy <2 pin, and support python 3.13 #719

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
]
dependencies = [
"ruamel.yaml",
"numpy<2.0.0",
"numpy",
DanielYang59 marked this conversation as resolved.
Show resolved Hide resolved
]
version = "2024.10.21"

Expand All @@ -44,7 +44,7 @@ json = [
"pandas",
"pydantic",
"pint",
"torch",
"torch", # need torch>=2.3.0 for numpy 2
Copy link
Contributor Author

@DanielYang59 DanielYang59 Oct 22, 2024

Choose a reason for hiding this comment

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

It seems only torch>=2.3.0 works NumPy 2, I don't want to pin torch>=2.3.0 directly because there could be NumPy 1 user that needs torch < 2.3.0. But as torch is an optional dependency, I would prioritize numpy.


I'm not a torch user at all, is there a workaround?

import torch
import numpy as np  # np is available


tensor = torch.tensor([1,2,3])
print(tensor.numpy().tolist())
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.1.2 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

If you are a user of the module, the easiest solution will be to
downgrade to 'numpy<2' or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last):  File "/Users/yang/developer/monty/debug/test_dump_torch_tensor.py", line 1, in <module>
    import torch
  File "/Users/yang/developer/monty/venv/lib/python3.12/site-packages/torch/__init__.py", line 1477, in <module>
    from .functional import *  # noqa: F403
  File "/Users/yang/developer/monty/venv/lib/python3.12/site-packages/torch/functional.py", line 9, in <module>
    import torch.nn.functional as F
  File "/Users/yang/developer/monty/venv/lib/python3.12/site-packages/torch/nn/__init__.py", line 1, in <module>
    from .modules import *  # noqa: F403
  File "/Users/yang/developer/monty/venv/lib/python3.12/site-packages/torch/nn/modules/__init__.py", line 35, in <module>
    from .transformer import TransformerEncoder, TransformerDecoder, \
  File "/Users/yang/developer/monty/venv/lib/python3.12/site-packages/torch/nn/modules/transformer.py", line 20, in <module>
    device: torch.device = torch.device(torch._C._get_default_device()),  # torch.device('cpu'),
/Users/yang/developer/monty/venv/lib/python3.12/site-packages/torch/nn/modules/transformer.py:20: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/torch/csrc/utils/tensor_numpy.cpp:84.)
  device: torch.device = torch.device(torch._C._get_default_device()),  # torch.device('cpu'),
Traceback (most recent call last):
  File "/Users/yang/developer/monty/debug/test_dump_torch_tensor.py", line 4, in <module>
    print(tensor.numpy().tolist())
          ^^^^^^^^^^^^^^
RuntimeError: Numpy is not available

]
multiprocessing = ["tqdm"]
optional = ["monty[dev,json,multiprocessing,serialization]"]
Expand Down
Loading