Fix AttributeError when loading float8 dtypes through numpy path #683
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes issue where loading safetensors files with float8_e5m2 (and other float8) dtypes fails with 'AttributeError: module numpy has no attribute float8_e5m2' when using PaddlePaddle < 3.2.0.
The issue occurs because when paddle.version < 3.2.0, load_file() uses numpy.load_file() which calls safe_open with framework='np'. The Rust code then tries to access numpy.float8_e5m2 which doesn't exist since NumPy doesn't have native float8 types.
Fix: Map float8 types (F8_E4M3, F8_E5M2, F8_E8M0, F4) to np.uint8 when is_numpy=True, similar to how bfloat16 is handled differently for numpy vs other frameworks. This matches the existing pattern in paddle.py where float8 types are mapped to np.uint8 (same width, byteswap is no-op).
Changes
get_pydtype()inlib.rsto checkis_numpyfor float8 typestest_float8_e5m2_loading()to verify the fixFix #682