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

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Oct 22, 2024

Summary by CodeRabbit

  • New Features

    • Updated Python version requirements to support up to 3.13.
    • Enhanced dependency management for numpy, pint, and torch.
  • Bug Fixes

    • Improved compatibility notes for torch dependency concerning numpy 2.
  • Chores

    • Adjusted GitHub Actions workflow to reflect updated Python versions for testing, now covering versions 3.9 through 3.13.

pyproject.toml Outdated
@@ -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

pyproject.toml Outdated Show resolved Hide resolved
pyproject.toml Outdated
@@ -44,7 +44,7 @@ json = [
"pandas",
"pydantic",
"pint",
"torch",
"torch", # Note: need torch>=2.3.0 for numpy 2 # 719
Copy link
Contributor Author

@DanielYang59 DanielYang59 Oct 23, 2024

Choose a reason for hiding this comment

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

I decide to drop this pin entirely because I believe it's something torch should resolve instead of monty (i.e. torch should correctly list supported numpy)

Unless tensor.numpy() should not be used at certain versions? I'm not a torch user, input appreciated!


Plan B (which I don't really like because it would narrow the default supported NumPy version) is to have something like:

json = [
...,
monty[torch_with_numpy2,...]
]

torch_with_numpy2 = [
  "numpy>=2",
  "torch>=2.3.0",  # Torch version compatible with numpy 2
]
torch_with_numpy1 = [
  "numpy<2",
  "torch",  
]

@DanielYang59 DanielYang59 marked this pull request as ready for review October 23, 2024 08:50
Copy link

coderabbitai bot commented Oct 23, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the pyproject.toml and GitHub Actions workflow files. The pyproject.toml file updates the Python version requirements to restrict it to a maximum of 3.13 and removes the upper limit for the numpy dependency. Additionally, it introduces conditional dependencies for pint and torch based on the Python version. The GitHub Actions workflow is updated to reflect the new Python versions in the job matrix.

Changes

File Change Summary
pyproject.toml Updated requires-python to ">=3.9,<=3.13"; removed upper limit for numpy; added conditional dependencies for pint and torch.
.github/workflows/test.yml Updated python-version in job matrix from ["3.9", "3.12"] to ["3.9", "3.10", "3.11", "3.12", "3.13"]; reordered OS list and updated variable name to python.

Assessment against linked issues

Objective Addressed Explanation
Support Numpy 2
Support Python 3.13

🐰 Hopping through the code so bright,
Numpy's limits take flight!
With Torch by its side, oh what a sight,
Compatibility shines, all feels right!
Let's celebrate with a joyful cheer,
For changes that bring us near! 🎉


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 82f6dd1 and 89c03fe.

📒 Files selected for processing (1)
  • .github/workflows/test.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/test.yml

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@DanielYang59 DanielYang59 marked this pull request as draft October 23, 2024 08:52
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1798d59 and c1639c0.

📒 Files selected for processing (1)
  • pyproject.toml (2 hunks)
🧰 Additional context used

pyproject.toml Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.53%. Comparing base (1798d59) to head (d7a6d02).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #719      +/-   ##
==========================================
- Coverage   82.57%   82.53%   -0.05%     
==========================================
  Files          27       27              
  Lines        1584     1580       -4     
  Branches      284      284              
==========================================
- Hits         1308     1304       -4     
  Misses        215      215              
  Partials       61       61              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -9,7 +9,7 @@ maintainers = [
]
description = "Monty is the missing complement to Python."
readme = "README.md"
requires-python = ">=3.9"
requires-python = ">=3.9,<=3.13"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume setting an upper bound would be a good idea to avoid installation on unverified versions when new python release come out

@DanielYang59 DanielYang59 changed the title release numpy <2 pin release numpy <2 pin, and support python 3.13 Oct 23, 2024
@DanielYang59 DanielYang59 marked this pull request as ready for review October 23, 2024 09:09
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c1639c0 and 82f6dd1.

📒 Files selected for processing (2)
  • .github/workflows/test.yml (1 hunks)
  • pyproject.toml (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pyproject.toml
🧰 Additional context used
🔇 Additional comments (1)
.github/workflows/test.yml (1)

12-12: Verify CI dependencies compatibility with Python 3.13.

Let's ensure all dependencies specified in the '[ci]' extra are compatible with Python 3.13.

.github/workflows/test.yml Outdated Show resolved Hide resolved
os: [ubuntu-latest, macos-14, windows-latest]
python-version: ["3.9", "3.12"]
os: [windows-latest, ubuntu-latest, macos-latest]
python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps just maximize test coverage as monty test is super cheap (only a few seconds), also it's pretty lower level so we cannot afford it to break

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.

Support numpy 2 and python 3.13
1 participant