onnx_graphsurgeon: Constant with float8_e4m3fnuz values is exported as FLOAT8E4M3FN
维护者通常 1 天内回复
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 92/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
从 onnx_graphsurgeon/exporters/onnx_exporter.py 中的 dtype_to_onnx 和 ml_dtype_to_onnx_name 表开始。运行最小的 Constant/export_tensor_proto 复现,然后验证 float8_e4m3fnuz 是否导出为 FLOAT8E4M3FNUZ,以及导入的 initializer 在值被具体化并重新导出后是否仍保留该类型。
由索引模型根据 Issue 内容生成。
描述
Description
dtype_to_onnx in onnx_graphsurgeon/exporters/onnx_exporter.py currently maps ml_dtypes.float8_e4m3fnuz to FLOAT8E4M3FN instead of FLOAT8E4M3FNUZ:
ml_dtype_to_onnx_name = {
np.dtype(ml_dtypes.float8_e4m3fn): "FLOAT8E4M3FN",
np.dtype(ml_dtypes.float8_e4m3fnuz): "FLOAT8E4M3FN", # should be FLOAT8E4M3FNUZ
np.dtype(ml_dtypes.float8_e5m2): "FLOAT8E5M2",
np.dtype(ml_dtypes.float8_e5m2fnuz): "FLOAT8E5M2FNUZ",
...
}
FLOAT8E4M3FN and FLOAT8E4M3FNUZ are distinct ONNX data types with the same storage width. As a result, the exported raw_data has the expected size and bytes, but the tensor is tagged with the wrong type. Consumers that decode those bytes according to the ONNX type can therefore interpret the values differently.
A minimal reproduction:
import ml_dtypes
import numpy as np
import onnx
from onnx_graphsurgeon.ir.tensor import Constant
from onnx_graphsurgeon.exporters.onnx_exporter import OnnxExporter
values = np.random.random_sample((2, 4)).astype(
ml_dtypes.float8_e4m3fnuz
)
proto = OnnxExporter.export_tensor_proto(
Constant("c", values=values)
)
print(proto.data_type) # 17: FLOAT8E4M3FN
print(onnx.TensorProto.FLOAT8E4M3FNUZ) # 18: expected
The issue also breaks import/export round trips once a lazy initializer is materialized. Import already handles FLOAT8E4M3FNUZ correctly, but after accessing .values, re-exporting the tensor changes its type from 18 to 17:
graph = gs.import_onnx(model_with_fnuz_initializer)
tensor = graph.tensors()["w"]
_ = tensor.values # materialize LazyValues
OnnxExporter.export_tensor_proto(tensor).data_type
# 17 (FLOAT8E4M3FN), originally 18 (FLOAT8E4M3FNUZ)
float8_e5m2fnuz is mapped correctly to FLOAT8E5M2FNUZ in the same table, so the problem appears to be isolated to the float8_e4m3fnuz entry.
Expected behavior
ml_dtypes.float8_e4m3fnuz values should export with:
onnx.TensorProto.FLOAT8E4M3FNUZ
and an imported FLOAT8E4M3FNUZ initializer should preserve its data type after materialization and re-export.
Environment
onnx_graphsurgeon0.6.1- also reproducible on current
main onnx1.23.0ml_dtypes0.6.0- Python 3.13
Provenance
The mapping appears to have been introduced in commit a180e081 (10.8 release changes, 2025-01-31), which added the ml_dtype_to_onnx_name table. The affected entry currently matches the float8_e4m3fn mapping immediately above it.
- 主要语言
- C++
- 星标
- 13.4k
- 派生
- 2.4k
- 平均合并
- 15 分钟
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NVIDIA/TensorRT 的其他 Issue
-
Module:Polygraphy
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
EmbLayerNormVarSeqlenPlugin: dangling pointer and out-of-bounds read during serialization可能已有人在做 @gabortar 于 10 天前认领。 未关闭Module:Plugins
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
onnx-graphsurgeon: Graph.toposort() hits RecursionError when a graph has a local function and an If/Loop node可能已有人在做 @gabortar 于 11 天前认领。 未关闭Module:GraphSurgeon
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
Polygraphy parse_meta accepts a shape with a missing bracket可能已有人在做 @SashaMIT 于 23 天前认领。 未关闭Module:Polygraphy
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复
-
Deprecate demoDiffusion可能重新可做 关联的 PR 已关闭且未合并。 未关闭Module:Demo
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
bulletphysics/bullet3#4819 ·
-
[YSQL] Local-node initdb reads postgres.bki, but YB clusters bootstrap only from yb_postgres.bki未关闭area/ysql kind/enhancement priority/low status/awaiting-triage
难度 2/5 1-3 小时 新手友好度 72/100
yugabyte/yugabyte-db#35763 ·
维护者通常 1 天内回复
-
category:port-update
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
facebookresearch/faiss#5775 · 1 条评论 ·
维护者通常 2 天内回复
-
Eval bug: minimax-m3: build_moe_ffn() drops the per-expert NVFP4 scale → garbled output (M3.1 Flash)未关闭bug-unconfirmed
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复