Skip to content

[Bug] keep_params_in_input strip names incorrectly when using tvm.relax.frontend.onnx.from_onnx #20290

Description

@HikaliIzu

Expected behavior

onnx input which is called "neck.lateral_convs.2.conv2.weight_quantized" should be converted to ir name "neck_lateral_convs_2_conv2_weight_quantized"

Actual behavior

converted name is "eck_lateral_convs_2_conv2_weight_quantized"

Environment

  • python 3.11.15
  • tvm 0.25.0.post1 wheel

Steps to reproduce

just use a model which's layers' name is started with "n", and simply run from_onnx, then output the script

import onnx
from tvm.relax.frontend.onnx import from_onnx

onnx_model = onnx.load(r"yunet_qop_fxp_320.onnx")
ir = from_onnx(onnx_model, keep_params_in_input=True, sanitize_input_names=False)
printf(ir.script())

How to fix

replace line 5439 at python/tvm/relax/frontend/onnx/onnx_frontend.py (line number may change because of different versions)

# strip method will execute char by char at "onnx::" to delete charactor in init_tensor.name
var_name = init_tensor.name.strip("onnx::")

with

# using removeprefix method to remove a sequence "onnx::" in init_tensor.name
var_name = init_tensor.name.removeprefix("onnx::")

Activity

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