-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Control Flow Operator Tutorial #3609
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
base: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/tutorials/3609
Note: Links to docs will display an error until the docs builds have been completed. ❗ 2 Active SEVsThere are 2 currently active SEVs. If your PR is affected, please view them below:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Hi @bohnstingl! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
||
The tutorial is split into three parts: | ||
|
||
Part 1: Basic Inference Examples |
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 writing this! For part 1 and part 2, I feel this tutorial does not add much value compared to what we have in the doc string. For part 3, users probably know how to do autograd in PyTorch and it feels to me just a demo that we could do autograd.
Instead, maybe we should just focus on Part 2, explore the killer examples in depth and show the benefits of using control flow operators in that particular setting e.g. using scan for chunked loss, rnn and associative scan for SSMs and try to get convincing e2e benchmarking results.
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.
Thank you @ydwu4 for looking at it.
About part 1, to me it still feels instructive and my impression is that not too many people are aware of the control flow operators, hence showing some basic usecases may make sense?
I guess we can remove part 3 entirely and then expand more thoroughly in part 2. The RNN and SSM examples are already there, but I can definitely expand more on them. I will also add the chunked loss computation that you mentioned.
What I thought would be interesting to show also are the cases where the control flow ops are actually needed in order to have a compilable model, e.g., show that without them there would be graph breaks. Early stopping based on data-dependent conditions would be another example, aka while_loop. WDYT?
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, sounds good. For chunked loss, I'm doing some benchmarks against liger so you can focus on rnn/SSMs. Graph breaks are not the fundamental reasons why we need control flow operators unless you cannot have graph breaks e.g. in export. It doesn't necessarily have worse performance when the model has graph breaks (at least we need to prove it makes perf worse in important use cases). IMO it's important to show control flow operators' values from perf/usability side compared with eager, torch.compile with native control and with hand-tuned kernels.
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.
But what about early stopping? Wouldn't you need data-dependent operations that get compiled somehow?
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 compile the body and have multiple torch.compiles in your program where you want to accelerate.
@ydwu4, I've removed the part 3 and enhanced the I would be more than happy if you can help me investigate that. This is also linked to the dedicated benchmark scripts that I have started here. |
Description
This PR aims to add a tutorial of the recent control flow operators.
Checklist
cc @ydwu4