Skip to content

Bump numpy to >=2.2.6 with Python 3.10+ requirement#1

Open
vbhakta8 wants to merge 6 commits into
mainfrom
numpy-2.x-upgrade
Open

Bump numpy to >=2.2.6 with Python 3.10+ requirement#1
vbhakta8 wants to merge 6 commits into
mainfrom
numpy-2.x-upgrade

Conversation

@vbhakta8

Copy link
Copy Markdown

Summary

This PR upgrades the numpy dependency to version 2.2.6+ and updates the codebase for numpy 2.x compatibility.

Changes

  • Dependency Update: numpy >= 1.21, <2.0.0numpy >= 2.2.6
  • Python Version: Minimum Python version bumped from 3.8 to 3.10 (required by numpy 2.x)
  • Code Updates: Replaced deprecated numpy APIs removed in numpy 2.0:
    • np.object_object (Python builtin)
    • dtype.type == np.str_dtype.kind == "U"
    • np.object_("val")np.asarray("val", dtype=object)[()]

Files Modified

File Change
pyproject.toml numpy version, Python version, classifiers, ruff target
tox.ini Updated envlist to py310-py313
pytriton/model_config/generator.py np.object_ → object
pytriton/proxy/data.py np.object_ → object
pytriton/decorators.py np.object_ → object
pytriton/proxy/validators.py Removed np.object_ from allowed types
pytriton/client/client.py np.str_ check → dtype.kind
tests/unit/test_decorators.py Updated scalar creation
tests/unit/test_proxy_validators.py dtype=np.object_ → dtype=object
examples/nemo_megatron_gpt_multinode/helpers.py np.object_ → object

New Tests

Added tests/unit/test_numpy2_compatibility.py with comprehensive tests to verify:

  • dtype comparison correctness
  • Serialization round-trip functionality
  • Decorator logic compatibility
  • Generator dtype conversion

Test Plan

  • All existing unit tests pass (295 passed, platform-specific failures unrelated to numpy)
  • New numpy 2.x compatibility tests pass
  • Import smoke tests pass with numpy 2.4.1
  • API signatures unchanged
  • Run tests on Linux environment

Breaking Changes

  • Drops support for Python 3.8 and 3.9 (numpy 2.2+ requires Python 3.10+)

- Update numpy dependency from ">=1.21, <2.0.0" to ">=2.2.6"
- Bump minimum Python version from 3.8 to 3.10 (required by numpy 2.x)
- Remove Python 3.8 and 3.9 from classifiers
- Update ruff target-version to py310
- Remove outdated Python 3.8 comments
np.object_ was removed in numpy 2.0. Replace with Python's built-in
object type which is semantically equivalent.

Files updated:
- pytriton/model_config/generator.py
- pytriton/proxy/data.py
- pytriton/decorators.py
- pytriton/proxy/validators.py
np.str_ was removed in numpy 2.0. Replace dtype.type == np.str_ check
with dtype.kind == "U" which correctly identifies unicode string arrays.
- Replace dtype=np.object_ with dtype=object in test_proxy_validators.py
- Replace np.object_("val1") scalar creation with np.asarray("val1", dtype=object)[()]
  in test_decorators.py
- Update tox envlist to py310-py313 (remove py38, py39)
- Remove np.object_ from example helpers.py
Add comprehensive tests to verify numpy 2.x compatibility:
- dtype comparison tests (object, bytes, unicode)
- Serialization round-trip tests
- Decorator logic tests
- Generator dtype conversion tests

These tests ensure the numpy 2.x migration is complete and correct.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c25164b47b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 52 to 54
def _convert_dtype_to_triton_dtype(dtype: Union[Type[np.dtype], Type[object]]) -> str:
if dtype in [np.object_, object, bytes, np.bytes_]:
if dtype in [object, bytes, np.bytes_]:
dtype = "TYPE_STRING"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Treat np.object_ as TYPE_STRING in dtype conversion

If a user still supplies np.object_ in a TensorSpec (valid in NumPy 2.x), this branch no longer recognizes it as a string type and falls through to client_utils.np_to_triton_dtype, which doesn't accept object dtypes. That turns a previously supported config into a runtime error when generating the model config. Consider normalizing np.object_ to object or adding it back to the string-type list to preserve compatibility with existing configs.

Useful? React with 👍 / 👎.

Comment on lines +148 to 150
allowed_object_types = [bytes, object, np.bytes_]
if (value.dtype.kind not in "OSU" and not np.issubdtype(value.dtype, output_config.dtype)) or (
value.dtype.kind in "OSU" and output_config.dtype not in allowed_object_types

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep np.object_ in allowed output dtypes

Models configured with output_config.dtype = np.object_ (common in NumPy 1.x/2.x for string-like outputs) will now be rejected even if the actual output is an object array, because np.object_ was removed from allowed_object_types. This is a regression from the previous behavior and will raise ValueError for otherwise valid outputs. Adding np.object_ back (or normalizing it to object) would avoid breaking existing model configs.

Useful? React with 👍 / 👎.

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