Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/tvm/relax/frontend/onnx/onnx_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6339,7 +6339,7 @@ def _parse_graph_initializers(self, graph: onnx.onnx_ml_pb2.GraphProto):
# Create variables for constants.
if self._keep_params_in_input:
# Pytorch sometimes inserts silly weight prefix. Remove it.
var_name = init_tensor.name.strip("onnx::")
var_name = init_tensor.name.removeprefix("onnx::")
init_var = self._new_var(var_name, shape=array.shape, dtype=array.dtype)
self._nodes[init_tensor.name] = init_var
# We need to keep track of both the real value and variable for this variable.
Expand Down
30 changes: 30 additions & 0 deletions tests/python/relax/test_frontend_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -11767,6 +11767,36 @@ def main(
tvm.ir.assert_structural_equal(tvm_model, Expected)


@pytest.mark.parametrize(
("initializer_name", "expected_name"),
[
("onnx::weight", "weight"),
(
"neck.lateral_convs.2.conv2.weight_quantized",
"neck.lateral_convs.2.conv2.weight_quantized",
),
],
)
def test_initializer_name_only_removes_onnx_prefix(initializer_name, expected_name):
graph = helper.make_graph(
[helper.make_node("Add", ["input", initializer_name], ["output"])],
"test_initializer_name_only_removes_onnx_prefix",
inputs=[helper.make_tensor_value_info("input", TensorProto.FLOAT, [1])],
initializer=[numpy_helper.from_array(np.ones([1], dtype="float32"), initializer_name)],
outputs=[helper.make_tensor_value_info("output", TensorProto.FLOAT, [1])],
)
model = helper.make_model(graph, opset_imports=[helper.make_opsetid("", 14)])
model.ir_version = 8

tvm_model = from_onnx(
model,
keep_params_in_input=True,
sanitize_input_names=False,
)

assert tvm_model["main"].params[-1].name == expected_name


def test_shape_dim_string_expression_graph_add():
identity_node = helper.make_node("Identity", ["x"], ["y"])

Expand Down
Loading