Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[relay] preserve the order of input_info of pytorch #14462

Merged
merged 4 commits into from
Apr 6, 2023
Merged
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
13 changes: 13 additions & 0 deletions python/tvm/relay/frontend/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5014,6 +5014,19 @@ def from_pytorch(
data_inputs.append(arg)
else:
func_args.append(arg)

# Ensures the order of data_input is the same as the order of inputs specified in input_info.
order_input_infos = {
input_info[0]: len(input_infos) - idx for idx, input_info in enumerate(input_infos)
}
data_inputs = sorted(
data_inputs,
key=lambda data_input: order_input_infos[data_input.name_hint]
if data_input.name_hint in order_input_infos
else -1,
reverse=True,
)

func_args = data_inputs + func_args

mod["main"] = tvm.relay.Function(func_args, ret)
Expand Down