Visitar URL original
ONNX GraphSurgeon cannot export NumPy-backed INT4 or UINT4 constants · Issue #4912 · NVIDIA/TensorRT · GitHub
Skip to content

ONNX GraphSurgeon cannot export NumPy-backed INT4 or UINT4 constants #4912

Open

Description

@0z5a

Bug

ONNX GraphSurgeon cannot export a NumPy-backed gs.Constant with ml_dtypes.int4 or ml_dtypes.uint4. constant_to_onnx_tensor packs FLOAT4E2M1 values into ONNX nibbles but writes INT4/UINT4 as one byte per element. ONNX rejects the raw tensor size.

Reproduction

With current main 16ed0636, ONNX 1.19.0 and NumPy 2.2.6:

import ml_dtypes, numpy as np, onnx_graphsurgeon as gs
from onnx_graphsurgeon.exporters.onnx_exporter import OnnxExporter
x = gs.Constant("x", np.array([1, 2, 3, 4], dtype=ml_dtypes.int4))
OnnxExporter.export_tensor_proto(x)

This raises ValueError: Raw data size does not match tensor's size. Expected 2 bytes, but got 4 bytes. UINT4 fails similarly. The exporter should pack each pair of 4-bit values, including odd element counts and signed negative values, and produce an ONNX tensor that decodes to the original values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions