Skip to content

[Bug] [Relax][ONNX] Float8 Cast drops saturate and merges distinct programs #20936

Open

Description

@sunni13830

Expected behavior

Cast-19 distinguishes saturate=0 and 1 for FLOAT8E4M3FN overflow. Casting 1000 and casting back should give NaN and 448, respectively.

Actual behavior

Full ONNX checking and ReferenceEvaluator distinguish both models, while from_onnx produces structurally identical Relax IR. The Cast converter never reads saturate. This demonstrates semantic information loss during conversion; it does not attribute every Float8 backend difference to this attribute or claim a native Float8 kernel was executed.

Environment

TVM 0.28.dev0, LLVM 18.1.3, Linux x86_64; Python 3.12.3, NumPy 2.5.4, ONNX 1.22.0. Installed binary build revision is unknown. Current main was inspected statically, not rebuilt.

Steps to reproduce

import numpy as np
import onnx
import tvm
from onnx import TensorProto as T, helper as h
from onnx.reference import ReferenceEvaluator
from tvm.relax.frontend.onnx import from_onnx

x = np.array([1., 1000.], dtype="float32")
modules, expected = [], []
for saturate in [0, 1]:
    model = h.make_model(h.make_graph([
        h.make_node("Cast", ["x"], ["f8"], to=T.FLOAT8E4M3FN, saturate=saturate),
        h.make_node("Cast", ["f8"], ["y"], to=T.FLOAT)], "float8_cast",
        [h.make_tensor_value_info("x", T.FLOAT, [2])],
        [h.make_tensor_value_info("y", T.FLOAT, [2])]),
        opset_imports=[h.make_opsetid("", 19)], ir_version=10)
    onnx.checker.check_model(model, full_check=True)
    ref = ReferenceEvaluator(model).run(None, {"x": x})[0]
    assert ref[0] == 1
    expected.append(ref)
    modules.append(from_onnx(model, keep_params_in_input=False))
    print("saturate", saturate, "reference", ref.tolist())
assert np.isnan(expected[0][1]) and expected[1][1] == 448
tvm.ir.assert_structural_equal(modules[0], modules[1])
print("distinct ONNX Cast semantics import to structurally identical Relax IR")
print(modules[0].script())

Triage

  • needs-triage

Activity

  1. added
    needs-triagePRs or issues that need to be investigated by maintainers to find the right assignees to address it
    on Nov 7, 2026
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

    needs-triagePRs or issues that need to be investigated by maintainers to find the right assignees to address ittype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions