Uh oh!
There was an error while loading. Please reload this page.
[PyTorch] FP8 MHA with RoPE and Miscellaneous Improvements - #1100
Conversation
4bdddfd to
b10d27fCompare
timmoon10
left a comment
There was a problem hiding this comment.
Overall I like this approach. The current FP8 MHA impl is brittle since it expects the modules to pass specific combinations of Float8Tensor/torch.Tensor. Adding logic so the modules can do casts internally makes this more flexible.
This is similar to how I envision the operation-based API to work. See how we cast inputs in the linear operation:
TransformerEngine/transformer_engine/pytorch/ops/basic/basic_linear.py
Lines 465 to 488 in ec49a52
We're not there yet, but the goal is to be able to implement FP8 MHA with something like:
model=te.Sequential(
te.ops.LayerNorm(...), # fp8 outputte.ops.Linear(...),
te.ops.RoPE(...), # fp8 outputte.ops.SelfAttention(...), # fp8 outputte.ops.Linear(...),
)
withte.fp8_autocast():
y=model(x)Uh oh!
There was an error while loading. Please reload this page.
timmoon10
commented
Aug 13, 2024
Regarding further optimizations: removing the select operations would be helpful if it's not too difficult. I've observed that they add non-trivial CPU overhead in other cases, so I recommend looking at #865. You should also be aware that I've made significant changes in the The logic for |
Thanks for your explanation. |
6e1334d to
a1ba977CompareUh oh!
There was an error while loading. Please reload this page.
a1ba977 to
2af460bCompareUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
Signed-off-by: Xin Yao <xiny@nvidia.com>
2af460b to
33c3ed6Comparefor more information, see https://pre-commit.ci
Signed-off-by: Xin Yao <xiny@nvidia.com>
timmoon10
commented
Aug 16, 2024
/te-ci pytorch |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
@yaox12 do we have a test that particularly tests the functionality of FP8 MHA + RoPE? The test should be able to answer your question above as well, regarding the |
1ca1860 to
521c77aCompareSigned-off-by: Xin Yao <xiny@nvidia.com>
yaox12
commented
Aug 21, 2024
Thanks. Added RoPE tests. |
for more information, see https://pre-commit.ci
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Signed-off-by: Xin Yao <xiny@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Xin Yao <xiny@nvidia.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
cyanguwa
commented
Aug 26, 2024
/te-ci pytorch |
Signed-off-by: Xin Yao <xiny@nvidia.com>
@cyanguwa I find Flash Attention 3 is not installed in our CI container, so I just skip the FP8 DPA/MHA tests when FA3 is not available, otherwise they will throw the error "no attention backends available". Another CI failure is |
Yes, |
yaox12
commented
Aug 30, 2024
@timmoon10 Can you review above unresolved comments? |
yaox12
commented
Sep 2, 2024
@timmoon10@cyanguwa Can you trigger the CI? |
yaox12
commented
Sep 4, 2024
/te-ci pytorch |
Signed-off-by: Xin Yao <xiny@nvidia.com>
yaox12
commented
Sep 4, 2024
/te-ci pytorch |
yaox12
commented
Sep 5, 2024
As Tim and Charlene have approved, and all comments have been resolved, and the CI has passed, I'll merge this PR. |
Description
Float8Tensorinputs depending on the dtype instead of thefp8_mhaflag inDotProductAttention.fp8_mhastill ensures the output of DPA is in FP8. With this PR:is_first_module_in_mhatofp8_outputand add this flag toLayerNormLinear, otherwise even theLayerNormLinearin MLP (after MHA) would produce FP8 outputs whenfp8_mha=True.index_selectops incast_to_fp8.index_selectops in FP8 DPA. I only modified the fwd functions because in backward the CPU overheads are not exposed.Float8Tensorinputs inLinear.Timeline
As we can see, this PR greatly reduces the CPU overheads in red boxes.
Type of change
Checklist: