Bump numpy to >=2.2.6 with Python 3.10+ requirement#1
Conversation
- 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.
There was a problem hiding this comment.
💡 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".
| 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" |
There was a problem hiding this comment.
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 👍 / 👎.
| 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 |
There was a problem hiding this comment.
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 👍 / 👎.
Summary
This PR upgrades the numpy dependency to version 2.2.6+ and updates the codebase for numpy 2.x compatibility.
Changes
numpy >= 1.21, <2.0.0→numpy >= 2.2.6np.object_→object(Python builtin)dtype.type == np.str_→dtype.kind == "U"np.object_("val")→np.asarray("val", dtype=object)[()]Files Modified
pyproject.tomltox.inipytriton/model_config/generator.pypytriton/proxy/data.pypytriton/decorators.pypytriton/proxy/validators.pypytriton/client/client.pytests/unit/test_decorators.pytests/unit/test_proxy_validators.pyexamples/nemo_megatron_gpt_multinode/helpers.pyNew Tests
Added
tests/unit/test_numpy2_compatibility.pywith comprehensive tests to verify:Test Plan
Breaking Changes