-
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
PyTorch frontend: make type inference incremental #6900
Conversation
9117082
to
a9badc1
Compare
The other question is whether we would want to make the translator a use a class interface so that the type inference can directly access the outputs' types. |
Yes we can consider this approach. Initially I thought function-only approach would be cleaner (e.g. for recursively converting blocks in We can introduce a global object (like a class) to hold these constants. |
While the functional approach is pretty neat, we ended up having global state (default frontend, dtype) and it'll be more soon (caching of inferred types, see apache#6900). To not have to pass around the state, this moves the op conversion into a class with instances having the state.
While the functional approach is pretty neat, we ended up having global state (default frontend, dtype) and it'll be more soon (caching of inferred types, see apache#6900). To not have to pass around the state, this moves the op conversion into a class with instances having the state.
While the functional approach is pretty neat, we ended up having global state (default frontend, dtype) and it'll be more soon (caching of inferred types, see apache#6900). To not have to pass around the state, this moves the op conversion into a class with instances having the state.
While the functional approach is pretty neat, we ended up having global state (default frontend, dtype) and it'll be more soon (caching of inferred types, see apache#6900). To not have to pass around the state, this moves the op conversion into a class with instances having the state.
While the functional approach is pretty neat, we ended up having global state (default frontend, dtype) and it'll be more soon (caching of inferred types, see #6900). To not have to pass around the state, this moves the op conversion into a class with instances having the state.
While the functional approach is pretty neat, we ended up having global state (default frontend, dtype) and it'll be more soon (caching of inferred types, see apache#6900). To not have to pass around the state, this moves the op conversion into a class with instances having the state.
While the functional approach is pretty neat, we ended up having global state (default frontend, dtype) and it'll be more soon (caching of inferred types, see apache#6900). To not have to pass around the state, this moves the op conversion into a class with instances having the state.
a9badc1
to
5e07318
Compare
@masahi @siju-samuel I think this is ready for review now. In BERT conversion, I get a 10x speedup for from_python. In addition to removing the N² problem, it prunes the module before type inference, which seems essential for prelude. |
@t-vi Please have a look at the CI issue. It is due to the recent change I made. |
5e07318
to
1046b65
Compare
Oh, right, an undetected merge confict. Fixed. Thank you @masahi. |
Thanks @t-vi |
Thank you @masahi, for the guidance and discussion, and review! |
While the functional approach is pretty neat, we ended up having global state (default frontend, dtype) and it'll be more soon (caching of inferred types, see apache#6900). To not have to pass around the state, this moves the op conversion into a class with instances having the state.
Currently, the PyTorch frontend will use the vanilla TVM type inference pass to get the types.
Combined with the incremental nature of translating the graph, this makes for quadratic (in the graph size) runtime.
This patch runs type inference on a subgraph (starting from the things that has types) instead. It is a bit hacky though because it essentially tries to implement in-place modification where TVM does not foresee it.
For converting Huggingface BERT, this patch gives a ~10x increase in the speed of conversion (from 31 seconds to just below 3), so it is solving a very real and quite bad problem.