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分
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 が 22 日前に担当しました。 オープンModule:Polygraphy
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信
-
Deprecate demoDiffusion再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンModule:Demo
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
NVIDIA/TensorRT の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
[BUG] Failed archive extraction deletes the dataset cache対応中かも @dajiaohuang が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
alibaba/GraphScope#4674 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 93/100
webarkit/WebARKitLib#107 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ONLYOFFICE/DesktopEditors#2527 ·
-
bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
HEL3AN/econspace-mmo#529 ·
メンテナーはふだん 1 日以内に返信