-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[Metaschedule] New relay backend for meta schedule task extraction #10578
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like not having to go through VMCompiler to get tasks. And I'd like to see this adapted to autoscheduler/autotvm. Another improvement would be to remove all metascheduler/auotscheduler depenednt code from te_compiler. te_compiler could return a list of tasks and the metascheduler/autoscheduler could handle it as they please. Maybe Collage will do this.
This is basically my goal of this PR, and already achieved for meta scheduler. There is no longer meta scheduler-specific code path for task extraction in
are not specific to any tuners and thus can be shared. Different tuners can customize the behavior as they please, e.g. how to create "task" objects from lowered TE compute. |
Will review next week! |
840ed47
to
8475b18
Compare
*/ | ||
virtual Optional<ObjectRef> Query(runtime::String task_name, IRModule mod, Target target, | ||
Optional<Array<IRModule>> dispatched) = 0; | ||
virtual IRModule Query(runtime::String task_name, IRModule mod, Target target, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for refactoring this interface! On the other hand, the interface itself might be unnecessary any more after the refactoring :-) Perhaps we would love to refactor this completely some time after this PR is merged!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, based on the current use, I want to change the interface to be tir::Schedule -> tir::Schedule
or PrimFunc -> PrimFunc
, and rename Query
to ApplySchedule
or something like that.
When we do need IRModule -> IRModule
interface later, I think it's better to introduce another function. Rather than one interface that does everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of renaming to something more meaningful :-)
On the interface side, I would prefer IRModule -> IRModule
transformation instead of limiting it to something less general. Imagine the case where we do subgraph-level BYOC, which we already supported in Builder/Runner, and adding the database support might be less tricky if we use the most general IRModule -> IRModule
transformation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I commented above, for other use cases that may or may not happen in the future, I think it's better to introduce another interface dedicated for it. BYOC, as currently implemented today, doesn't go through TE Compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me! Only a few nitpicks :-)
5c8800c
to
1497d65
Compare
commit 501fac6 Merge: 076fa33 ce8c563 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 14:16:47 2022 +0900 New relay backend for meta schedule task extraction commit ce8c563 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 14:12:30 2022 +0900 fix cpplint commit dfa4fb0 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 14:09:11 2022 +0900 update expected op list in test_meta_schedule_integration_extract_from_resnet to remove dep on Ansor commit a98182e Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 13:56:35 2022 +0900 fixed test_meta_schedule_integration_apply_history_best commit 40d52a1 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 13:50:43 2022 +0900 uniquefy task names commit dfaf496 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 13:45:30 2022 +0900 dedup tasks commit e49d500 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 12:59:45 2022 +0900 return reversed list commit 74636be Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 12:39:58 2022 +0900 refactor commit 99f1701 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 12:34:14 2022 +0900 clean up integration.cc and Query interface commit 3f93a1e Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 11:54:57 2022 +0900 check in minor vnni-related change commit af3e988 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 07:36:35 2022 +0900 Removed TaskExtraction node commit 7b4d35e Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 05:42:56 2022 +0900 add doc to util functions commit 3c5a318 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 05:27:53 2022 +0900 rename to task extraction commit 57f2882 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 05:24:37 2022 +0900 fixed constant param bind commit f099537 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 05:10:44 2022 +0900 remove unused stuff from python extract_tasks_from_relay commit 4a5e4aa Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 05:10:30 2022 +0900 move BindParams function to cc file commit efeccea Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 03:56:05 2022 +0900 refactor param binding commit 109187f Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 02:21:58 2022 +0900 New relay backend for meta schedule task extraction commit 6f01901 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 11:25:44 2022 +0900 fixed anchor impl selection commit be6c258 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 10:57:02 2022 +0900 Forgot visiting arg in ScheduleBuilder CallNode vsit commit 0c6d4a6 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 10:45:08 2022 +0900 add public, fix include path convention commit 4cd3a16 Author: Masahiro Masuda <[email protected]> Date: Thu Mar 10 18:43:15 2022 +0900 removed create_schedule stuff commit eb1bc7e Author: Masahiro Masuda <[email protected]> Date: Thu Mar 10 18:13:42 2022 +0900 fixed merge conflict commit 6e68fd9 Author: Masahiro Masuda <[email protected]> Date: Thu Mar 10 14:27:34 2022 +0900 Decouple TE compute and schedule lowering in ScheduleBuilder
Co-authored-by: Junru Shao <[email protected]>
04b7ea1
to
40ee540
Compare
…pache#10578) * New relay backend for meta schedule task extraction commit 501fac6 Merge: 076fa33 ce8c563 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 14:16:47 2022 +0900 New relay backend for meta schedule task extraction commit ce8c563 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 14:12:30 2022 +0900 fix cpplint commit dfa4fb0 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 14:09:11 2022 +0900 update expected op list in test_meta_schedule_integration_extract_from_resnet to remove dep on Ansor commit a98182e Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 13:56:35 2022 +0900 fixed test_meta_schedule_integration_apply_history_best commit 40d52a1 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 13:50:43 2022 +0900 uniquefy task names commit dfaf496 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 13:45:30 2022 +0900 dedup tasks commit e49d500 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 12:59:45 2022 +0900 return reversed list commit 74636be Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 12:39:58 2022 +0900 refactor commit 99f1701 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 12:34:14 2022 +0900 clean up integration.cc and Query interface commit 3f93a1e Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 11:54:57 2022 +0900 check in minor vnni-related change commit af3e988 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 07:36:35 2022 +0900 Removed TaskExtraction node commit 7b4d35e Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 05:42:56 2022 +0900 add doc to util functions commit 3c5a318 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 05:27:53 2022 +0900 rename to task extraction commit 57f2882 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 05:24:37 2022 +0900 fixed constant param bind commit f099537 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 05:10:44 2022 +0900 remove unused stuff from python extract_tasks_from_relay commit 4a5e4aa Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 05:10:30 2022 +0900 move BindParams function to cc file commit efeccea Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 03:56:05 2022 +0900 refactor param binding commit 109187f Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 02:21:58 2022 +0900 New relay backend for meta schedule task extraction commit 6f01901 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 11:25:44 2022 +0900 fixed anchor impl selection commit be6c258 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 10:57:02 2022 +0900 Forgot visiting arg in ScheduleBuilder CallNode vsit commit 0c6d4a6 Author: Masahiro Masuda <[email protected]> Date: Fri Mar 11 10:45:08 2022 +0900 add public, fix include path convention commit 4cd3a16 Author: Masahiro Masuda <[email protected]> Date: Thu Mar 10 18:43:15 2022 +0900 removed create_schedule stuff commit eb1bc7e Author: Masahiro Masuda <[email protected]> Date: Thu Mar 10 18:13:42 2022 +0900 fixed merge conflict commit 6e68fd9 Author: Masahiro Masuda <[email protected]> Date: Thu Mar 10 14:27:34 2022 +0900 Decouple TE compute and schedule lowering in ScheduleBuilder * update integration.h doc * remove unused import * fix mypy check * use_meta_schedule restored, now extracts the same task as Ansor * python doc update * unused import * cache_ -> cache, suppres "Cannot find workdload" warning * Update src/relay/backend/task_extraction.cc and te_compiler_cache.cc Co-authored-by: Junru Shao <[email protected]> * removed unnecessary include * fixed build * drop relay.const on params * updated comment in integration.cc * update schedule_rule name to prepend "metaschedule" * typo fix * more nit change * make the output of Query Optional * update py doc * remove TODO comment on parse_mod Co-authored-by: Junru Shao <[email protected]>
This PR adds `te.extern_primfunc` which provides the interface around TE ExternOp that allows a TVMScript defined schedulable TIR PrimFunc to be inlined into a TE compute graph. The result is that TIR can be used for compute definitions in Relay OpStrategies and, paired with meta-scheduler support in relay as introduced in #10578, these compute definitions can be scheduled and tuned as demonstrated in the attached tests. Prior to this, compute definitions were limited to those definable in TE only. As a consequence of this patch and ongoing improvements to TVMScript meta-programming (#11097), TOPI can be extended to include compute and scheduling functions targeting schedulable TIR uniformly.
Building on #10561, add a new interface for task extraction that doesn't require the whole
VMCompiler.lower()
. Extracted tasks are the same as ones from the existing flow. Currently only enabled for meta schedule, but I believe it is worth adapting for autotvm / ansor cc @comaniac @tkonoligeI'm currently working on a model where TE scheduling leads to an error during lowering, but TIR scheduling might work. I wanted to try the latter, but currently task extraction entails (for no reason) TE schedule application and lowering, which leads to the said error. This motivated this work, which aims to remove the unnecessary TE scheduling steps from the task extraction process.
Please review @junrushao1994 @mbs-octoml @jroesch