-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Refactor fused_bias_residual kernels for better readability
#2356
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c31c265
Refactor fused_bias_residual kernels for better readability
arashb a9d8083
Merge branch 'master' into arashb/refact-res-add-kernel
tjruwase 30c8ea8
Merge branch 'master' into arashb/refact-res-add-kernel
tjruwase ae45836
Merge branch 'master' into arashb/refact-res-add-kernel
arashb 6c933c5
Merge branch 'master' into arashb/refact-res-add-kernel
arashb 790eac9
Merge branch 'master' into arashb/refact-res-add-kernel
arashb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
@RezaYazdaniAminabadi in these kernels the computation output is stored in
residualas opposed to finalhidden_state. Then as output of the MLP here we return the residual value. Wouldn't make sense to store the output inhidden_stateand return thehidden_stateinstead?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.
The underlying storage for
residualis actually the original input tensor to the Transformer layer (which we don't otherwise modify), whereashidden_stateis backed by an offset into our scratchpad memory. That scratchpad section would be overwritten by another part of the Transformer (the allocation for hidden states is here and conflicts with the QKV GEMM allocation here).Long term I don't know how safe it necessarily is to assume that we can freely modify the input Tensor though, so modifying our scratchpad structure might be the most correct option? I don't know if anyone else thinks there's risk in using the input tensor this way though.
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 bringing up this @arashb. Also, thanks @cmikeh2 for the main reason of not putting data in the hidden_state here. I think the safe way is probably to create another tensor for the output if this is needed in other places of the pipeline, however, this imposes more memory-usage of the inference system which is not desired. So, I think let's keep the default as writing in
residualand if required by the users we can add a flag to create tensors for each layer's individual outputs. How does it sound?