-
-
Notifications
You must be signed in to change notification settings - Fork 20.1k
[torch.compile][ROCm][V1] Enable attention output FP8 fusion for V1 attention backends #19767
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 1 commit
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
f93fcf4
Enable attention output FP8 fusion for V1 attention backends
gshtras 9417465
reformat
gshtras f7ac2b8
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras 845e40c
No longer disabling noop and fusion in V1 graph mode
gshtras f3eb6cb
Restrict triton attention fusion to per tensor scaling
gshtras a7e64d7
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras 01e6130
Fix the fusion pattern to account fot the output tensot ro be initial…
gshtras 61f7551
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras f9e195a
V1 unit tests
gshtras 0c94a0d
Using the updated test backend
gshtras e528023
TEMP fixed tests (except output)
ProExpertProg a2c2bc2
Cleanup and attempt to use an inverse scale
gshtras 4646027
Another inverted scale for the V1 split attn prefill path
gshtras 97759d3
Using empty tensors with matching dtype
gshtras 3e1f552
Merge remote-tracking branch 'upstream/main' into attention_fusion_v1
gshtras 4ebb561
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras 15ba786
Fix the new test. Rename parameters
gshtras 76e7a01
Remove deprecated parameter
gshtras 8310c81
Add quant custom op in the test
gshtras a394548
Rename parameter names at call sites
gshtras fb8c9f6
I will always press save after pressing reformat
gshtras 2b467a4
Remove memory restrictions
gshtras 96d201f
linter
gshtras b52e5f0
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras 62a1451
Skip attn fusion test on CUDA. Fusion is not applicable to the CUDA F…
gshtras ff5e1b8
Try to force triton attention on cuda in the test
gshtras 16078b7
Format
gshtras 6df13c2
Remove debug leftovers
gshtras 7430120
Try out the process per test decorator
gshtras 3418837
Syntax
gshtras d148c55
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras 3bde9ad
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras 0e8b47f
Remove the print
gshtras ea3e55a
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras becbd2f
Trying to figure out why the test passes on ROCm, but OOMs on CUDA
gshtras 61c34ae
Spawn in itself doesn't seem to work on CUDA
gshtras 8b42595
Trying to fit into the memory constrains of the CI CUDA machines
gshtras 3f309e8
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras c99f236
Fixed pattern and unit tests
gshtras c03d469
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras 6c46e87
Add dtype to the v0 test
gshtras 4422fcf
Add float16 to test. Gate it on cuda-alike platforms. Refactor common…
gshtras d33bc75
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras f14f017
Less explicit model variables name
gshtras 998421c
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras 8a1333e
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras 747d55c
Merge remote-tracking branch 'origin/main' into attention_fusion_v1
gshtras cb94169
cleanup test checks (#663)
ProExpertProg 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
|
|
||
| # To check compatibility | ||
| IS_TURING = current_platform.get_device_capability() == (7, 5) | ||
| float8_info = torch.finfo(current_platform.fp8_dtype()) | ||
|
|
||
|
|
||
| # Here's an example autotuner config for this kernel. This config does provide | ||
|
|
@@ -42,6 +43,7 @@ def _fwd_kernel(Q, | |
| sm_scale, | ||
| k_scale, | ||
| v_scale, | ||
| out_scale, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| B_Start_Loc, | ||
| B_Seqlen, | ||
| x: tl.constexpr, | ||
|
|
@@ -80,8 +82,11 @@ def _fwd_kernel(Q, | |
| num_unroll_cache: tl.constexpr, | ||
| num_unroll_request: tl.constexpr, | ||
| SKIP_DECODE: tl.constexpr, | ||
| USE_FP8: tl.constexpr, | ||
| MAX_Q_LEN: tl.constexpr = 0, | ||
| MAX_CTX_LEN: tl.constexpr = 0): | ||
| MAX_CTX_LEN: tl.constexpr = 0, | ||
| FP8_MIN: tl.constexpr = float8_info.min, | ||
| FP8_MAX: tl.constexpr = float8_info.max): | ||
|
|
||
| cur_batch = tl.program_id(0) | ||
| cur_head = tl.program_id(1) | ||
|
|
@@ -274,6 +279,9 @@ def _fwd_kernel(Q, | |
| off_o = ((cur_batch_in_all_start_index + offs_m[:, None]) * stride_obs + | ||
| cur_head * stride_oh + offs_d[None, :] * stride_od) | ||
| out_ptrs = Out + off_o | ||
| if USE_FP8: | ||
| acc = acc / tl.load(out_scale) | ||
|
ProExpertProg marked this conversation as resolved.
Outdated
|
||
| acc = tl.clamp(acc, FP8_MIN, FP8_MAX) | ||
| tl.store(out_ptrs, | ||
| acc, | ||
| mask=dim_mask[None, :] & (offs_m[:, None] < cur_batch_query_len)) | ||
|
|
@@ -732,7 +740,8 @@ def context_attention_fwd(q, | |
| alibi_slopes=None, | ||
| sliding_window=None, | ||
| sm_scale=None, | ||
| skip_decode=False): | ||
| skip_decode=False, | ||
| fp8_out_scale=None): | ||
|
|
||
| q_dtype_is_f32 = q.dtype is torch.float32 | ||
|
|
||
|
|
@@ -857,6 +866,7 @@ def context_attention_fwd(q, | |
| sm_scale, | ||
| k_scale, | ||
| v_scale, | ||
| fp8_out_scale, | ||
| b_start_loc, | ||
| b_seq_len, | ||
| k_cache.shape[4], | ||
|
|
@@ -892,6 +902,7 @@ def context_attention_fwd(q, | |
| BLOCK_DMODEL_PADDED=Lk_padded, | ||
| SLIDING_WINDOW=sliding_window, | ||
| SKIP_DECODE=skip_decode, | ||
| USE_FP8=fp8_out_scale is not None, | ||
| BLOCK_M=128, | ||
| BLOCK_N=64, | ||
| num_unroll_cache=4, | ||
|
|
||
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
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
Oops, something went wrong.
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.
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.
Can we call this
out_descaleorout_scale_inv?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.
Arguably this name is now more correct after the inversion since now we're multiplying by it inside the kernel
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.
Yes but I think the convention in vllm is that
x_scaleis the scaling factor forxin the quantized representation, and so this is the inverse of the scaling factor.