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

Use numpy._core instead of numpy.core #3247

Merged
merged 5 commits into from
Nov 21, 2024
Merged

Use numpy._core instead of numpy.core #3247

merged 5 commits into from
Nov 21, 2024

Conversation

qgallouedec
Copy link
Member

What does this PR do?

We've been getting this warning:

/fsx/qgallouedec/miniconda3/envs/trl/lib/python3.11/site-packages/accelerate/utils/other.py:220: DeprecationWarning: numpy.core is deprecated and has been renamed to numpy._core. The numpy._core namespace contains private NumPy internals and its use is discouraged, as NumPy internals can change without warning in any release. In practice, most real-world usage of numpy.core is to access functionality in the public NumPy API. If that is the case, use the public NumPy API. If not, you are using NumPy internals. If you would still like to access an internal attribute, use numpy._core.multiarray.
np.core.multiarray._reconstruct,

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@muellerzr @BenjaminBossan @SunMarc

@BenjaminBossan
Copy link
Member

The issue here is that np._core does not exist in older numpy versions (probably < 2.0 but I haven't checked), so this would fail there (as happens in the failing doc build). We would need to do a version check and use either np.core or np._core.

@qgallouedec
Copy link
Member Author

qgallouedec commented Nov 20, 2024

good point!

The very first version that includes np._core is 1.26.1 2.0.0.

What about something like

np_core = np._core if version.parse(np.__version__) >= version.parse("2.0.0") else np.core

alternatively we can do something like

np_core = getattr(np, "_core", np.core)

but I find it less intuitive to know when the condition is met or not, and we'll probably forget to remove this if/else once we've increased the min version of numpy

EDIT: min version is actually 2.0.0

@qgallouedec
Copy link
Member Author

qgallouedec commented Nov 20, 2024

wait it seems like np._core for np<2.0 is not the same as for np>=2.0. Checking right now

EDIT: version threshold is actually 2.0.0 (not 1.26.1). Editing my above comment

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Member

@BenjaminBossan BenjaminBossan left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the warning.

Copy link
Member

@SunMarc SunMarc left a comment

Choose a reason for hiding this comment

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

Nice thanks !

@SunMarc SunMarc merged commit 08101b9 into main Nov 21, 2024
28 checks passed
@SunMarc SunMarc deleted the qgallouedec-patch-1 branch November 21, 2024 16:06
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.

4 participants