-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Relay] Flexible shape dispatch transformation #11199
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
Conversation
jroesch
left a comment
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.
LGTM modulo feedback
|
cc @mbs-octoml |
|
@jroesch I think the documentation should now be substantially improved based on your input. Let me know what you think. |
mbs-octoml
left a comment
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.
LGTM, some optional nits:
- consider asserting dim is Any in override_shape to avoid surprises
- rename dim -> axis, value -> dim
- should we force a TypeInfer afterwards to be sure the Any->dim subst is sound?
|
All feedback has been addressed and tests are green. @jroesch do you want to give this one more pass? |
* Added pass that creates a semi-dynamic dispatcher around a relay module. * Added automatic padding feature. * Output slicing working. * Multiple input support working i think. * Added test file. * Improve comments. * Fix lint. * Allow default values. * Fix docstring. * Improved documentation based on feedback. * Add extra check for record loading. * Improve variable names. * Add type inference to make sure things worked. * Added support for multiple outputs.
* Added pass that creates a semi-dynamic dispatcher around a relay module. * Added automatic padding feature. * Output slicing working. * Multiple input support working i think. * Added test file. * Improve comments. * Fix lint. * Allow default values. * Fix docstring. * Improved documentation based on feedback. * Add extra check for record loading. * Improve variable names. * Add type inference to make sure things worked. * Added support for multiple outputs.
This PR adds a new pass to
relay.transformthat creates a dispatcher around an input module to handle multiple input shapes. For example consider a case where I'd like to optimize my model to handle bothbatch_size=1andbatch_size=4. I can now do so elegantly as follows:As seen above
FlexibleShapeDispatchis a simple halfway point between fully static and fully dynamic graphs that allows us to leverage TVM tuning. If an input shape is not provided inbuckets, it will either run fully dynamically usingrelay.Any, or if theauto_padargument is set forFlexibleShapeDispatch, padding will be applied to match the closest bucket.There are a few special cases that this pass handles. Multiple dynamic inputs (like those you might see in BERT) can be handled by setting
input_indicesto indicate which inputs have a dynamic axis.affects_outputcan be set toFalsefor cases where the output shape is not dependent on input dynamism which could occur in dynamic resolution cases or something.To make applying tuning logs more convenient, I also added the ability to load and merge multiple files to both autotvm and autoscheduler.
Thanks @jroesch for providing the backbone of this implementation.