-
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
Remove compile_engine.h for real this time. #8775
Conversation
TVM_REGISTER_PASS_CONFIG_OPTION("relay.backend.use_auto_scheduler", Bool); | ||
TVM_REGISTER_PASS_CONFIG_OPTION("relay.backend.disable_compile_engine_cache", Bool); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._make_LoweredOutput") | ||
.set_body_typed([](tvm::Array<te::Tensor> outputs, OpImplementation impl) { | ||
return LoweredOutput(outputs, impl); | ||
}); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._make_CCacheKey") | ||
.set_body_typed([](Function source_func, Target target) { | ||
return CCacheKey(source_func, target); | ||
}); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._CompileEngineGlobal").set_body_typed([]() { | ||
return CompileEngine::Global(); | ||
}); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._CompileEngineClear").set_body_typed([](CompileEngine self) { | ||
self->Clear(); | ||
}); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._CompileEngineLower") | ||
.set_body_typed([](CompileEngine self, CCacheKey key, const String mod_name) { | ||
return self->Lower(key, mod_name); | ||
}); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._CompileEngineLowerShapeFunc") | ||
.set_body_typed([](CompileEngine self, CCacheKey key) { return self->LowerShapeFunc(key); }); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._CompileLowerExternalFunctions") | ||
.set_body_typed([](CompileEngine self) { return self->LowerExternalFunctions(); }); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._CompileEngineJIT") | ||
.set_body_typed([](CompileEngine self, CCacheKey key) { return self->JIT(key); }); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._CompileEngineListItems").set_body_typed([](CompileEngine self) { | ||
CompileEngineImpl* ptr = dynamic_cast<CompileEngineImpl*>(self.operator->()); | ||
ICHECK(ptr != nullptr); | ||
return ptr->ListItems(); | ||
}); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._CompileEngineListShapeFuncItems") | ||
.set_body_typed([](CompileEngine self) { | ||
CompileEngineImpl* ptr = dynamic_cast<CompileEngineImpl*>(self.operator->()); | ||
ICHECK(ptr != nullptr); | ||
return ptr->ListShapeFuncItems(); | ||
}); | ||
|
||
TVM_REGISTER_GLOBAL("relay.backend._CompileEngineGetCurrentCCacheKey") | ||
.set_body_typed([](CompileEngine self) { | ||
CompileEngineImpl* ptr = dynamic_cast<CompileEngineImpl*>(self.operator->()); | ||
ICHECK(ptr != nullptr); | ||
return ptr->GetCurrentCCacheKey(); | ||
}); |
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.
Can we document the corresponding APIs in this PR? For example, I didn't find the alternative of relay.backend._CompileEngineJIT
?
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.
There is one JIT method in src/relay/backend/te_compiler.h
. Is it what we want?
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.
That's the one, but it doesn't have a TVM global symbol anymore. Does that mean we are only allowed to access these functions via C++ by including te_compiler.h
in the future?
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.
The push for the new lowering is to refactor away single-op lowering to lowering the entire program in one shot. Unless I'm missing something fundamental all uses of the compile engine have been lowered to C++ or removed. The only occurrences left are in testing code.
I know there is some dependency on the relay compile engine in some other projects. Shall we slow down a little bit and wait for some consensus? Thanks a lot! |
Is this still WIP? otherwise, how will this PR pass the CI? |
No this builds perfectly fine locally, after the last interpreter patch went in there is no longer any need for the |
I know there is strong dependency to compile engine in other projects, and would love to propose several actions we could take to make sure the process working properly for both parties.
|
@junrushao1994 We can keep an adaptor interface for a while longer, the only challenge is at some point we are going to have to refactor the internals to handle other requirements from ARM, and other folks and so the implementation might change even if we preserve the interface. Happy to discuss more tomorrow. |
LGTM. This is dead code in-tree, appears we are uncertain about out-of-tree uses for which AFAIKT s/CompileEngine/TECompiler/g would work. Could we hot-swap in this PR? |
I've checked our use cases and here is my summary:
|
Thanks @comaniac for the list! It is definitely helpful for narrowing down the scope for discussion. Looks like we are pretty close to a solution to hot-swap the out-of-tree implementation :-) Looks like the first and the second point are relatively okay. On the second point, we might just want to remove @jroesch would you like to respond to the last point? Looks like something doable |
I guess we cannot remove |
LGTM, it's great to see that we've finally reached this milestone in the refactoring work! @comaniac Since we are trying to unify lowering around one API, I think that that lowering function will need to be removed at some point (though @jroesch can comment better on when it needs to happen by). You'll still be able to lower through the function LowerTE. Also, can you elaborate a bit more on your use case where you don't have the input tensors? Are you allocating inside the function you are lowering? Thanks in advance |
As the moderator in this thread, I do expect sufficient discussion as an architectural change. Let’s keep the discussion purely technical as we always enjoy in the community :-) We have already done great work moving to TE compiler. It seems that there are some final sticky points we wanted to address. Yep Cody is right and I was wrong. I just checked and saw several python functions registered in compile_engine.py still in use by TE compiler. We might want to move them to te_compiler.py. Lily, Cody is referring to some methods implemented in python instead of c++. Although it doesn’t actually cause divergent code path right now, we are not in favor of mixing c++ and python if there is no specific reason. So as you said, we might want to migrate them to c++ some day in the future. The input tensors are not exposed by methods in te compiler, which I assume is a fixable thing? Would you guys like to discuss more specifically on this? Do we want to slightly tweak the interface or add a new API to make it happen? Would love to hear concrete proposals from you guys! Thanks a lot! |
In TE compiler, the input tensors are internally created by
|
@comaniac Hey Cody, Sorry for slow response, been having a busy week. Let me clarify all my assumptions and models and see if we can clarify from there:
I am happy to support use cases along the way to this world if I better understand critical need. I do agree that we need to move the few registered helped functions, but other then that My main question is what use case really needs the existing API or would more fine grained helper APIs allow you to do the customization you want? Thanks for the feedback! |
Thanks for the response :) I completely understand the concern of unifying the lowering mechanism and feel this is the right track as well. Meanwhile, I have two cases:
Finally, while I agree that TE compiler could be as private as possible, it doesn't hurt to keep the Python interface for debugging and experiments. We just need to make sure they are only used for developments and no one really uses them in the submitted PRs. |
Not any more! I just rejigged the interpreter to work module-at-a-time. However the TIR-to-PackedFunc 'build' step is still one-function-at-a-time and done on demand but I think at some point we can similarly fold that into a module-at-a-time transform. |
Okay, I didn’t see any actual conflict here. Shall we just add a few helpers and proceed? |
[UPDATE] The removal of the compile engine is up to date now in ---> #9282. |
Closing for @mikepapadim's change. |
…p of #8775 (#9282) * Remove compile_engine.h for real * Fix format * RM compile_engine.cc * Swap compile engine with TECompiler * Cleanup on compile engine py leftovers * [WIP] Exposing legacy compile engine capabilities through TE Compiler * Swap usages for depreciated compile engine with TE compiler * Track and replace usages of compile engine refactor them to TE compiler * [Docs] Log helper mod * Remove depreciated function for lookup compile engine cachce * Fix typos * Debug misc cleanups * Register global pass for using te compiler for auto scheduler * Fix tests using the legacy compile engine * Fix broken autotuner tests and minor cleanups * Swap compile engine with te_compiler in rst config * PR nits * Fix failed test Co-authored-by: Jared Roesch <roeschinc@gmail.com>
…p of apache#8775 (apache#9282) * Remove compile_engine.h for real * Fix format * RM compile_engine.cc * Swap compile engine with TECompiler * Cleanup on compile engine py leftovers * [WIP] Exposing legacy compile engine capabilities through TE Compiler * Swap usages for depreciated compile engine with TE compiler * Track and replace usages of compile engine refactor them to TE compiler * [Docs] Log helper mod * Remove depreciated function for lookup compile engine cachce * Fix typos * Debug misc cleanups * Register global pass for using te compiler for auto scheduler * Fix tests using the legacy compile engine * Fix broken autotuner tests and minor cleanups * Swap compile engine with te_compiler in rst config * PR nits * Fix failed test Co-authored-by: Jared Roesch <roeschinc@gmail.com>
…p of apache#8775 (apache#9282) * Remove compile_engine.h for real * Fix format * RM compile_engine.cc * Swap compile engine with TECompiler * Cleanup on compile engine py leftovers * [WIP] Exposing legacy compile engine capabilities through TE Compiler * Swap usages for depreciated compile engine with TE compiler * Track and replace usages of compile engine refactor them to TE compiler * [Docs] Log helper mod * Remove depreciated function for lookup compile engine cachce * Fix typos * Debug misc cleanups * Register global pass for using te compiler for auto scheduler * Fix tests using the legacy compile engine * Fix broken autotuner tests and minor cleanups * Swap compile engine with te_compiler in rst config * PR nits * Fix failed test Co-authored-by: Jared Roesch <roeschinc@gmail.com>
This removes the
compile_engine.h
header enabling us to start refactoring thete_compiler.h
interface to better match the rest of the compiler. After we land the final refactors from @mikepapadim and @mbs-octoml we can start cleaning up the interface to better match the desired end state.cc @electriclilies @csullivan @tmoreau89