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

Remove LoweredModule #8886

Merged

Conversation

electriclilies
Copy link
Contributor

@electriclilies electriclilies commented Aug 31, 2021

In this PR, I remove LoweredModule. I do this by annotating all functions with their targets and annotating external modules and function info on the module.

There is still some cleanup work to be done, specifically with removing per_target_modules_ in the interpreter. I'm going to remove those in a follow-up PR.

@mbs-octoml @mikepapadim @jroesch

@electriclilies electriclilies force-pushed the remove-lowered-module-final-draft branch from 3fb6beb to a6aa3b8 Compare August 31, 2021 23:04
@electriclilies electriclilies force-pushed the remove-lowered-module-final-draft branch from a6aa3b8 to 6ed813b Compare August 31, 2021 23:17
@electriclilies electriclilies marked this pull request as ready for review September 1, 2021 16:46
@electriclilies electriclilies changed the title [DRAFT] Remove LoweredModule Remove LoweredModule Sep 1, 2021
@electriclilies
Copy link
Contributor Author

@Mousius I fixed the nit from #8835 in this PR!

@jroesch
Copy link
Member

jroesch commented Sep 1, 2021

@manupa-arm @mbaret @Mousius could you guys take a review pass on this if you have cycles? should be a quick review, just consolidates everything into an IRModule.

Copy link
Member

@Mousius Mousius left a comment

Choose a reason for hiding this comment

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

Overall I'd say that this is a good change! I've put in a few suggestions for improvements but as this is evolving in the future I'm happy to see this merged and see if the code even exists in the next patch 😸

P.S. Thanks for addressing that nit @electriclilies 🥇 !

src/relay/backend/graph_executor_codegen.cc Outdated Show resolved Hide resolved
src/relay/backend/te_compiler.h Outdated Show resolved Hide resolved
function_metadata_.Set(runtime::symbol::tvm_module_main, main_func_info.value());

// Get only the Relay functions out of the lowered module so we can run type inference on them
IRModule main_module = tec::GetMainModule(lowered_mod);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok in a follow up if you like, but I think folding type inf into LowerTEPass makes sense to account for the rewritten calls. Someday we'll figure out how to gracefully do that incrementally since it's really overkill for just xfering known types from old to new CallNodes!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add it as a TODO

Copy link
Contributor Author

@electriclilies electriclilies Sep 2, 2021

Choose a reason for hiding this comment

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

Actually there's a slight problem with this -- you can't run InferType on the whole lowered_mod becauselowered_mod has functions with GlobalVars that are in the IRModule's global_var_map, but you can't find them using Lookup because they are not the same object (it fails on line 210)..
https://github.com/apache/tvm/blob/main/src/relay/transforms/type_infer.cc#L209:L215
My workaround was to only apply type inferencing to the main_module (since that was what was done before this PR).

I'm not sure if this is a bug in how the type inferencer is dealing with GlobalVars (maybe it should be doing lookup by name hint, not pointer equality) or if it's a bug in how those GlobalVars are being made / propagated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then the other problem is even if you do successfully manage to lookup the function, there are PrimFuncs in the module which the type inferencer doesn't know how to deal with. We could just skip PrimFuncs we find during type inference..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK actually I think I fixed this in #8399

@mbs-octoml
Copy link
Contributor

LGTM. So much clearer, thank you Lily.

@electriclilies
Copy link
Contributor Author

@Mousius @mbs-octoml Thanks for the review!

Copy link
Contributor

@leandron leandron left a comment

Choose a reason for hiding this comment

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

LGTM

@leandron leandron merged commit 0744641 into apache:main Sep 3, 2021
@leandron
Copy link
Contributor

leandron commented Sep 3, 2021

This is merged now, thanks @electriclilies @Mousius and @mbs-octoml!

@electriclilies electriclilies deleted the remove-lowered-module-final-draft branch September 3, 2021 16:49
@electriclilies
Copy link
Contributor Author

thanks @leandron @Mousius @mbs-octoml!

ylc pushed a commit to ylc/tvm that referenced this pull request Sep 29, 2021
* Remove LoweredModule

* Clean up some comments

* QEMU flaky tests

* Don't add external functions to the LoweredFunctions module

* QEMU flaky test

* Respond to feedback

* flaky test
ylc pushed a commit to ylc/tvm that referenced this pull request Jan 13, 2022
* Remove LoweredModule

* Clean up some comments

* QEMU flaky tests

* Don't add external functions to the LoweredFunctions module

* QEMU flaky test

* Respond to feedback

* flaky test
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.

None yet

5 participants