Skip to content

Added notebook torchscriptable_t5_with_torchtext.ipynb #2122

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

Merged
merged 1 commit into from
Jan 8, 2024

Conversation

rbahumi
Copy link
Contributor

@rbahumi rbahumi commented Mar 20, 2023

This notebook is an example of a (working) "Hacky" solution for wrapping the full 'generate' functionality inside a "forward" function. The perpose of this is to start a discussion and be a suggention on how to make the this functionality TorchScriptable.

To do so I:

  1. Inherited from T5Model:
  • extracted the decoding code from t5.forward() function to a standalone 'decode' function that returns a specific type.
  • added the GenerationUtils's 'generate' functionality as a class method (similar to HuggingFace).
  1. Added TorchScriptableT5, a module that implements the full generative logic in the forward method.
  2. Helper classes that build a jit (TorchScript) model from a predefined T5 Bundle

This notebook is an example of a (working) "Hacky" solution for wrapping the full 'generate' functionality inside a "forward" function.
The perpose of this is to start a discussion and be a suggention on how to make the this functionality TorchScriptable.

To do so, I:

1. T5TorchGenerative: inherited from T5Model:
- extracted the decoding code from t5.forward() function to a standalone 'decode' function that returns a specific type.
- added the GenerationUtils's 'generate' functionality as a class method (similar to HuggingFace).
2. Added TorchScriptableT5, a module that implements the full generative logic in the forward method.
3. Helper classes that build a jit (TorchScript) model from a predefined T5 Bundle
@joecummings joecummings merged commit dc94b32 into pytorch:main Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants