Skip to content

Remove LoweredModule - #8886

Merged
leandron merged 7 commits into
apache:mainfrom
electriclilies:remove-lowered-module-final-draft
Sep 3, 2021
Merged

Remove LoweredModule#8886
leandron merged 7 commits into
apache:mainfrom
electriclilies:remove-lowered-module-final-draft

Conversation

@electriclilies

@electriclilieselectriclilies commented Aug 31, 2021

Copy link
Copy Markdown
Contributor

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
electricliliesforce-pushed the remove-lowered-module-final-draft branch from 3fb6beb to a6aa3b8CompareAugust 31, 2021 23:04
@electriclilies
electricliliesforce-pushed the remove-lowered-module-final-draft branch from a6aa3b8 to 6ed813bCompareAugust 31, 2021 23:17
@electriclilies
electriclilies marked this pull request as ready for review September 1, 2021 16:46
@electriclilieselectriclilies changed the title [DRAFT] Remove LoweredModule Remove LoweredModuleSep 1, 2021
@electriclilies

Copy link
Copy Markdown
ContributorAuthor

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

@jroesch

Copy link
Copy Markdown
Member

@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.

@MousiusMousius left a comment

Copy link
Copy Markdown
Member

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 🥇 !

Comment threadsrc/relay/backend/graph_executor_codegen.cc Outdated
Comment threadsrc/relay/backend/te_compiler.h Outdated
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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

@electriclilieselectricliliesSep 2, 2021

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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

Comment threadsrc/relay/backend/te_compiler.cc Outdated
@mbs-octoml

Copy link
Copy Markdown
Contributor

LGTM. So much clearer, thank you Lily.

@electriclilies

Copy link
Copy Markdown
ContributorAuthor

@Mousius@mbs-octoml Thanks for the review!

@leandronleandron left a comment

Copy link
Copy Markdown
Contributor

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:mainSep 3, 2021
@leandron

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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 freeto 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

@electriclilies@jroesch@mbs-octoml@leandron@Mousius