[Bug][Relax][ONNX] Constant rejects standard value_float/value_int attributes
Version
- Executed revision:
e269315c90e3a061c9e1c77b370ce883b1b223f4 - Current
mainsource rechecked:0587e59a696cb435ad4d328726a07daa8d966f3c; the converter still requires the tensor-valuedvalueattribute - TVM:
0.26.dev0 - Host: Ubuntu 24.04 x86-64, LLVM CPU
Reproducer
Run the complete script below. The risk
encodes the scalar with the standard value_float attribute. The control changes only the encoding
to an equivalent scalar TensorProto in value.
value reference 2.0
value TVM 2.0
value_float reference 2.0
Error converting operator Constant, with inputs: []
value_float TVM error ValueError no value in ConstantExpected behavior
ONNX Constant-13 accepts exactly one of value, sparse_value, or the value_* attributes.
value_float=2.0 is a valid scalar float32 constant and should import as the same value as the
TensorProto control.
Actual behavior and cause
The Relax ONNX converter checks only for attr["value"] and raises ValueError("no value in Constant") otherwise. It never handles value_float, value_floats, value_int, or value_ints.
The ONNX official multi-node scan reaches the same error in 28 valid expanded function models,
including Elu, Selu, LeakyRelu, HardSigmoid, Shrink, and window functions.
Duplicate check
GitHub issue and pull-request searches for the Relax ONNX Constant converter, value_float, and the
exact error found no matching Apache TVM report as of 2026-09-30. Issue #20001 concerns initializer
recovery for ConstantOfShape, a different operator and path.
Complete reproducer
import numpy as np
import onnx
import tvm
from onnx import TensorProto, helper
from onnx.reference import ReferenceEvaluator
from tvm import relax
from tvm.relax.frontend.onnx import from_onnx
def model(use_scalar_attribute):
kwargs = {"value_float": 2.0} if use_scalar_attribute else {
"value": helper.make_tensor("v", TensorProto.FLOAT, [], [2.0])
}
graph = helper.make_graph(
[helper.make_node("Constant", [], ["y"], **kwargs)],
"constant",
[],
[helper.make_tensor_value_info("y", TensorProto.FLOAT, [])],
)
result = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 13)])
onnx.checker.check_model(result)
return result
def run(use_scalar_attribute):
onnx_model = model(use_scalar_attribute)
expected = ReferenceEvaluator(onnx_model).run(None, {})[0]
print("value_float" if use_scalar_attribute else "value", "reference", expected.tolist())
mod = from_onnx(onnx_model, keep_params_in_input=False)
executable = relax.build(mod, target="llvm", relax_pipeline="default", exec_mode="bytecode")
vm = relax.VirtualMachine(executable, tvm.cpu())
actual = vm["main"]().numpy()
print("value_float" if use_scalar_attribute else "value", "TVM", actual.tolist())
np.testing.assert_array_equal(actual, expected)
for use_scalar_attribute in (False, True):
try:
run(use_scalar_attribute)
except Exception as error:
print("value_float" if use_scalar_attribute else "value", "TVM error", type(error).__name__, error)Source: apache/tvm