-
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
[REFACTOR] Use more TypedPackedFuncs #2981
Conversation
Thanks for the contribution, I like the automated detection of the signatures. The main question is the naming convention to make sure we are not confusing the users. Let us open a new issue about other parts of RFC. I will summarize some of my take here(which can be moved to the RFC). I like the idea of Node hierarchy compile time generation. This is something I have thought about and discussed with @jroesch for a while and might help #2523 (comment) It is always tempting to automate more parts of the wrapper generation. However, our past experiences suggest that the automatic wrapper generation is never perfect. Think about how can we support keyword arguments, good pythonic style docstring and so on. It is also harder for developers to find the actual implementation of the "generated API" since some of them are generated at runtime. Eventually, we find that it is simpler to just do a manual wrapping, which gives us all the good native features, docs, and keep PackedFunc simple (by only support positional arguments without any meta-data). |
This idea actually comes a lot :P #2328 (comment) I know, for sure, that we could get good docs with really good codegen like that offered by Rust macros, but I also know for sure that we're not about to rewrite TVM in Rust :) I think that the boilerplate really does bother new (advanced) users who want to use TVM as a tool. I wonder if there's a way forward here that satisfies all desiderata? |
Yeah I didn't put any thought into these, would welcome suggestions. Could do something like |
This is ready to merge once we bikeshed the helper names |
Here are some thoughts about naming:
We also need to update the comment a bit to reflect the template arguments |
Done @tqchen |
* Add `set_body_simple` to Registry, refactor a lot of code to use it * Add more types to Relay PackedFuncs * Add Registry::set_body_method to easily make Node methods into PackedFuncs * Add set_body_method, set_body_node_method; start typing api_lang * Add some docs, remove unused script * Fix mysterious linter problem * Touch up api_ir.cc * Fix some issues with TOPI argument counts * Revert changes to topi.cc to avoid problems with optional arguments * A little more cleanup * Type more of the api _ functions * Whitespace * Finalize names and docs for new registry helpers * Update docs
* Add `set_body_simple` to Registry, refactor a lot of code to use it * Add more types to Relay PackedFuncs * Add Registry::set_body_method to easily make Node methods into PackedFuncs * Add set_body_method, set_body_node_method; start typing api_lang * Add some docs, remove unused script * Fix mysterious linter problem * Touch up api_ir.cc * Fix some issues with TOPI argument counts * Revert changes to topi.cc to avoid problems with optional arguments * A little more cleanup * Type more of the api _ functions * Whitespace * Finalize names and docs for new registry helpers * Update docs
This PR converts a good chunk of TVM's global
PackedFunc
s to beTypedPackedFunc
s. Right now, this shouldn't actually change any behavior, since the type information is immediately discarded once the functions are registered in theRegistry
.It does make things a lot shorter, using a few helper methods I added on
Registry
:set_body_simple
,set_body_method
, andset_body_node_method
(names up for debate). These helpers use the properties of function pointers to infer argument and return types:becomes ->
This is shorter, runtime-equivalent, and also now has type information!
I don't believe this change has much runtime cost. It might interfere with inlining in some cases, would have to measure. Also,
PackedFunc
s aren't intended to be all that fast anyway.So, that's the refactoring part. Now, the RFC part:
(moved to #2983)