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

[AOT] Sanitize input/output name in runtime #13046

Merged
merged 7 commits into from
Oct 17, 2022

Conversation

mehrdadh
Copy link
Member

@mehrdadh mehrdadh commented Oct 11, 2022

This PR adds name sanitization to input/output at AOT runtime module. This means when we use set_input/set_output with AOT, even if we use the original name of those input/outputs which were sanitized and changed in the codegen, it will map them to the correct input/output.

For example if your model has an input with name input:0, the AOT codegen would change this to input_0 but at runtime if we try to set this input it does not exist. Now, we use the same sanitization at runtime

cc @areusch

@mehrdadh mehrdadh requested a review from areusch October 11, 2022 21:44
@mehrdadh mehrdadh changed the title [AOTExecutor] Sanitize input/output name in runtime [AOT] Sanitize input/output name in runtime Oct 11, 2022
@apache apache deleted a comment from tvm-bot Oct 11, 2022
@apache apache deleted a comment from tvm-bot Oct 11, 2022
@mehrdadh mehrdadh force-pushed the aot/fix_name_mangling branch from 4bfa4af to 7be8741 Compare October 11, 2022 22:07
@tvm-bot
Copy link
Collaborator

tvm-bot commented Oct 11, 2022

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@@ -107,7 +108,7 @@ PackedFunc AotExecutor::GetFunction(const std::string& name,
} else if (name == "set_input_zero_copy") {
return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) {
if (String::CanConvertFrom(args[0])) {
int in_idx = this->GetInputIndex(args[0].operator String());
int in_idx = this->GetInputIndex(tvm::runtime::SanitizeName(args[0].operator String()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it also make sense to add a python test that passes in names like input:0 to test that this functionality doesn't regress for the various AoT commands?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it makes sense. I will add a test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test which exams both mangled name and the original name

inputs = {name: input_data}
runner.set_input(**inputs)
runner.run()
assert (runner.get_output(0).asnumpy() == expected_output).all()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also add checks of get_input and get_input_index since they are separate code paths in aot_executor.cc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added


/*!
* \file tvm/runtime/name_mangling.h
* \brief Utility functions for name mangling which are used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the name transforms are fairly standalone, can we move them all rather than having some here and some in the original file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this one since it is shared between runtime library and tvm library. I think it's better to keep the rest in src/backend since they are not used in runtime currently. wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see much harm moving them all across, they're small, self contained and it's likely if you need one you need others. Either way, it'd be good not to have name_mangling.h and name_transforms.h as it confuses people, if you don't want to move it together could we at least name them consistently? "Mangle" is also an unnecessarily aggressive word, we should probably not be using it in our codebase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I'll rename it to name_transforms

Copy link
Contributor

@lhutton1 lhutton1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix @mehrdadh, I ran into this issue recently so thought I'd have a quick look. Just found a few nits in the tests, otherwise LGTM!

tests/python/relay/aot/test_cpp_aot.py Outdated Show resolved Hide resolved
tests/python/relay/aot/test_cpp_aot.py Show resolved Hide resolved
@mehrdadh
Copy link
Member Author

@Mousius PTAL. thanks!

@mehrdadh
Copy link
Member Author

@tvm-bot rerun

@Mousius Mousius merged commit 3f0d3f2 into apache:main Oct 17, 2022
@mehrdadh mehrdadh deleted the aot/fix_name_mangling branch October 17, 2022 17:19
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 10, 2022
This PR adds name sanitization to input/output at AOT runtime module. This means when we use set_input/set_output with AOT, even if we use the original name of those input/outputs which were sanitized and changed in the codegen, it will map them to the correct input/output.

For example if your model has an input with name `input:0`, the AOT codegen would change this to `input_0` but at runtime if we try to set this input it does not exist. Now, we use the same sanitization at runtime
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
This PR adds name sanitization to input/output at AOT runtime module. This means when we use set_input/set_output with AOT, even if we use the original name of those input/outputs which were sanitized and changed in the codegen, it will map them to the correct input/output.

For example if your model has an input with name `input:0`, the AOT codegen would change this to `input_0` but at runtime if we try to set this input it does not exist. Now, we use the same sanitization at runtime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants