-
Notifications
You must be signed in to change notification settings - Fork 30.9k
Extend Transformers Trainer Class to Enable PyTorch Torchscript for Inference #17153
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
The documentation is not available anymore as the PR was closed or merged. |
This may be more optimum's domain than Transformers, what do you think @mfuntowicz @LysandreJik @lewtun ? |
Thanks for the ping and thank you @jianan-gu for opening the PR! I agree that inference-based improvements are better suited in Having said that, I wonder if it's overkill to create a new package just to support this feature, which is natively included in PyTorch. @mfuntowicz @michaelbenayoun do you see any other benefits that could be had by having a dedicated subpackage for |
I'd be happy to work on this PR if you give me a green light that you'll accept this feature. We can mark is as experimental - should you decide that it'd fit better elsewhere down the road. So it would be easier to experiment and try it on. |
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 adding this. We would need some test before we can merge the PR, and the code needs to be adapted to the way the labels are handled in Transformers.
Co-authored-by: Sylvain Gugger <[email protected]>
Co-authored-by: Sylvain Gugger <[email protected]>
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 addressing the comments, this will also need a test before we can merge.
Co-authored-by: Sylvain Gugger <[email protected]>
Co-authored-by: Sylvain Gugger <[email protected]>
Adding UT Tests in test_trainer.py for jit which covers |
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 adding the tests! I have a few last small comments.
Do you want to have a second look @stas00 ?
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.
What is the sounds of a tree falling in the forest when there is nobody to hear it?
All these new features need to be documented on the user-side so that they actually get used. So the same as with IPEX let's add user docs and as before ideally a small benchmark to give users an incentive to try the feature.
updade: I added a doc for inference as we haven't created it and then you can push the usage examples there - like we did with IPEX PR. So please fill out the blank and then we are good to go I think.
and added a few nits in the code.
Co-authored-by: Stas Bekman <[email protected]>
Co-authored-by: Stas Bekman <[email protected]>
|
||
## JIT-mode | ||
|
||
XXX: fill in the details |
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 isn't your PR adding support for inference only?
jit_mode_eval (`bool`, *optional*, defaults to `False`):
Whether or not to use PyTorch jit trace for inference.
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.
Yes, it is for inference only.
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.
so why the generic torch_jit_model
name? let's name it accordingly? i.e. adding _eval
to it
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.
Sure, have made changes accordingly, thanks for your suggestion.
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, @jianan-gu - please ping me when it's ready for a final review.
Though this jit mode works both for CPU and GPU, the current IPEX release covers CPU side optimizations with jit mode for model inference. Therefore we only have added and updated the inference doc for CPU (perf_infer_cpu.mdx), please take a review of the contents @stas00 , thanks. (for the small benchmark, for now, we only have relative performance numbers like shown in #17137, so we will prepare for the numbers with --skip_memory_metrics 0 as a follow-up) |
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.
last few small things to adjust and then it should be good.
Co-authored-by: Stas Bekman <[email protected]>
@sgugger, would you like to have a quick look at the last changes since your review - mainly the newly added doc. Thank you! otherwise it's good to be merged. |
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.
Some small comments on the new doc, thanks for adding it!
Co-authored-by: Sylvain Gugger <[email protected]>
Co-authored-by: Sylvain Gugger <[email protected]>
What does this PR do?
This PR intends to extend Transformers Trainer Class with PyTorch Torchscript (
torch.jit.trace
) to speed up model inference with just-in-time compilation.Users could simply enable "--jit_mode" Trainer input args to get benifits.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.