-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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
TF: generate without tf.TensorArray
#17801
Conversation
The documentation is not available anymore as the PR was closed or merged. |
tf.TensorArray
cc @ydshieh -- this PR fixes the XLNet generate error we have been seeing :) |
Cool! |
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! (And agree about TensorArray
being cursed). Did you see any performance changes from doing it this way?
@Rocketknight1 no differences in terms of execution speed 👍
|
What does this PR do?
Some models, like XLNet, need more than just the previous token when
past
is used. This PR solves this problem with the help of some refactoring -- we no longer useTensorArray
, instead we scatter updates into a fixed-size tensor. This refactor simplifiesgenerate
, especiallybeam_search
, which may prove to be helpful in enabling XLA.Slow tests have been run for the usual generate models (gpt2, t5, rag, speech_to_text, encoder_decoder, vision_encoder_decoder, bart).
Why was this refactor needed?
As it can be read in this issue,
TensorArray
is meant to be used as a write-once array, anything else falls in the unexpected behavior domain -- in other words, our use was dangerous. The original solution to the XLNet problem was to read all existing tokens from theTensorArray
, using the same logic as in this PR, but it failed with XLA -- and the behavior depended on what was written into the variable on its first write. Since we use fixed-size tensors, a normal tensor works just fine, and with simpler code (assuming the reader is familiar with how scatter works :D ).