[Bug] [Relax][ONNX] Elu, Selu and LRN construct FLOAT scalars for FLOAT16 inputs

Open Beginner friendly
#20,890 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

The three converters are the Elu, Selu and LRN handlers in the Relax ONNX frontend, which is where the FLOAT scalar constants are built; Elu and Selu create default FLOAT constants for subtraction, and LRN creates FLOAT constants for multiplication. Start by running the repro script from the issue and compare the FLOAT and FLOAT16 paths. Done means all three ops import for FLOAT16 with scalar constants matching the input dtype, and the FLOAT case still passes.

Written by the indexing model from the issue text.

Description

needs-triage type: bug
Expected behavior

The ONNX Elu, Selu and LRN converters should accept FLOAT16 inputs, as allowed by their schemas, and create scalar constants with a compatible dtype.

Actual behavior

All three FLOAT controls import. The otherwise identical FLOAT16 models pass full ONNX checking but fail with:

TypeError: Binary operators must have the same datatype for both operands.

Elu/Selu construct default FLOAT constants for subtraction; LRN explicitly creates FLOAT constants for multiplication. This is in the Relax ONNX converters, separate from the earlier TOPI LRN result-dtype fix in #11032.

Environment

TVM 0.28.dev0 (local build; build commit unavailable), Python 3.12.3, Linux x86_64; ONNX 1.22.0, NumPy 2.5.4.

Steps to reproduce

Run with python repro.py:

import onnx
from onnx import TensorProto as T, helper as h
from tvm.relax.frontend.onnx import from_onnx

for op in ["Elu", "Selu", "LRN"]:
    for dtype in [T.FLOAT, T.FLOAT16]:
        attrs = {"size": 3} if op == "LRN" else {}
        node = h.make_node(op, ["x"], ["y"], **attrs)
        model = h.make_model(h.make_graph([node], op,
            [h.make_tensor_value_info("x", dtype, [1, 3, 2, 2])],
            [h.make_tensor_value_info("y", dtype, [1, 3, 2, 2])]),
            opset_imports=[h.make_opsetid("", 18)], ir_version=10)
        onnx.checker.check_model(model, full_check=True)
        try:
            from_onnx(model, keep_params_in_input=False)
            print(op, T.DataType.Name(dtype), "imported")
        except Exception as error:
            print(op, T.DataType.Name(dtype), type(error).__name__, str(error).splitlines()[-1])
Triage
  • needs-triage
Dominant language
Python
Stars
13.9k
Forks
4k
Avg merge
8h 6m
Merged PRs (30d)
184

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/tvm

All issues in apache/tvm

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.