gemini-code-assist[bot] commented on code in PR #222:
URL: https://github.com/apache/tvm-ffi/pull/222#discussion_r2488969212
##########
python/tvm_ffi/_dtype.py:
##########
@@ -314,7 +314,8 @@ def lanes(self) -> int:
dtype._NUMPY_DTYPE_TO_STR[np.dtype(ml_dtypes.bfloat16)] = "bfloat16"
dtype._NUMPY_DTYPE_TO_STR[np.dtype(ml_dtypes.float8_e4m3fn)] =
"float8_e4m3fn"
dtype._NUMPY_DTYPE_TO_STR[np.dtype(ml_dtypes.float8_e5m2)] = "float8_e5m2"
- dtype._NUMPY_DTYPE_TO_STR[np.dtype(ml_dtypes.float4_e2m1fn)] =
"float4_e2m1fn"
+ if hasattr(ml_dtypes, "float4_e2m1fn"): # ml_dtypes >= 0.5.0
+ dtype._NUMPY_DTYPE_TO_STR[np.dtype(ml_dtypes.float4_e2m1fn)] =
"float4_e2m1fn"
Review Comment:

This guard is a good addition for compatibility. However, the fix is
incomplete and the comment is slightly inaccurate.
1. `float4_e2m1fn` was introduced in `ml_dtypes` v0.4.0, not v0.5.0.
2. Other dtypes like `float8_e4m3fn` and `float8_e5m2` (lines 315-316) also
need `hasattr` guards, as they were added in `ml_dtypes` v0.2.0 and will cause
an `AttributeError` with v0.1.0.
For a complete fix, all dtypes added after the initial `ml_dtypes` release
should be guarded.
Here is a suggestion to correct the comment for the current change:
```suggestion
if hasattr(ml_dtypes, "float4_e2m1fn"): # ml_dtypes >= 0.4.0
dtype._NUMPY_DTYPE_TO_STR[np.dtype(ml_dtypes.float4_e2m1fn)] =
"float4_e2m1fn"
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]