Skip to content
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

Simplify the cache decoding graph #780

Merged
merged 1 commit into from
Mar 3, 2023

Conversation

mattdangerw
Copy link
Member

This updates our CachedMultiHeadAttention layer to avoid slicing the input to a dynamic length during generative decoding. Instead, our cache is always a fixed length, as are the keys and values after the cache is applied.

Overall this ends up being both a nice simplification and speedup. After patching in a fix for #779, generating 25 sequences of length 256 with the base model goes from 52s -> 33s.

Copy link
Contributor

@chenmoneygithub chenmoneygithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Matt! It works pretty well! Dropped a few comments on the code itself.

keras_nlp/layers/transformer_decoder.py Outdated Show resolved Hide resolved
keras_nlp/layers/transformer_decoder_test.py Show resolved Hide resolved
keras_nlp/layers/transformer_layer_utils.py Show resolved Hide resolved
keras_nlp/models/gpt2/gpt2_causal_lm.py Show resolved Hide resolved
@mattdangerw
Copy link
Member Author

Thanks for the review! Addressed all comments.

Copy link
Contributor

@chenmoneygithub chenmoneygithub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Matt!

keras_nlp/layers/transformer_decoder_test.py Outdated Show resolved Hide resolved
keras_nlp/models/gpt2/gpt2_causal_lm.py Show resolved Hide resolved
@mattdangerw mattdangerw merged commit 23f06c0 into keras-team:master Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants