Skip to content

AttributeError: module 'ml_dtypes' has no attribute 'float4_e2m1fn' with v1.19.0 #7249

Description

@nishantkumar1292

Bug Report

Is the issue related to model conversion?

No. The error is from the onnx package itself.

Describe the bug

Getting the below error:

from onnxmltools.convert import convert_lightgbm as convert_lightgbm_booster
  File "/home/runner/work/credit-model-training/credit-model-training/.venv/lib/python3.13/site-packages/onnxmltools/__init__.py", line 16, in <module>
    from .convert import convert_coreml
  File "/home/runner/work/credit-model-training/credit-model-training/.venv/lib/python3.13/site-packages/onnxmltools/convert/__init__.py", line 3, in <module>
    from .main import convert_coreml
  File "/home/runner/work/credit-model-training/credit-model-training/.venv/lib/python3.13/site-packages/onnxmltools/convert/main.py", line 5, in <module>
    import onnx
  File "/home/runner/work/credit-model-training/credit-model-training/.venv/lib/python3.13/site-packages/onnx/__init__.py", line 131, in <module>
    from onnx import (
    ...<12 lines>...
    )
  File "/home/runner/work/credit-model-training/credit-model-training/.venv/lib/python3.13/site-packages/onnx/compose.py", line 8, in <module>
    from onnx import (
    ...<7 lines>...
    )
  File "/home/runner/work/credit-model-training/credit-model-training/.venv/lib/python3.13/site-packages/onnx/helper.py", line 21, in <module>
    from onnx import _mapping, defs, subbyte
  File "/home/runner/work/credit-model-training/credit-model-training/.venv/lib/python3.13/site-packages/onnx/_mapping.py", line 104, in <module>
    np.dtype(ml_dtypes.float4_e2m1fn),
             ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'ml_dtypes' has no attribute 'float4_e2m1fn'. Did you mean: 'float8_e4m3fn'?

System information

  • OS Platform and Distribution (e.g. Linux Ubuntu 20.04): Ubuntu 24.04.2
  • ONNX version (e.g. 1.13): 1.19.0 (latest)
  • Python version: 3.13

Reproduction instructions

Version v1.19.0 has started depending on ml-dtypes, and this is where the bug started in the workflow. With the earlier version, it was running fine.

Run these in a fresh env

pip install onnx==1.19.0
pip install onnxmltools==1.14.0

from onnxmltools.convert import convert_lightgbm as convert_lightgbm_booster



### Expected behavior
It should just work..

### Notes
<!-- Any additional information -->

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestions about ONNX

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions