[PyTorch] Add fp32_partial_output support for CP P2P ring attention#1
Open
vedaanta wants to merge 1 commit into
Open
[PyTorch] Add fp32_partial_output support for CP P2P ring attention#1vedaanta wants to merge 1 commit into
vedaanta wants to merge 1 commit into
Conversation
Extends context-parallel ring P2P attention (AttnFuncWithCPAndKVP2P) with a new `fp32_partial_output` flag that accumulates per-step partial attention outputs in float32 before LSE-correction merging, improving numerical stability across CP ranks for fp16/bf16 inputs. Implementation uses a software cast (out_per_step.to(float32)) after the cuDNN kernel call. The fake_dtype=torch.float32 path is wired and ready for when the cuDNN kernel gains native fp16/bf16→fp32 output support. Changes: - context_parallel.py: add fp32_partial_output param to cp_p2p_fwd_fused_attn and AttnFuncWithCPAndKVP2P.forward; fix THD out-buffer dtype; update backward return tuple for new forward input count - backends.py: thread fp32_partial_output through FusedAttentionBackend - dot_product_attention.py: expose fp32_partial_output in DotProductAttention.forward - tests: add test_cp_with_fused_attention_fp32_partial_output covering bf16/fp16, MHA/GQA, causal/non-causal, sbhd/thd, p2p/a2a+p2p Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
20d3e05 to
877d459
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
fp32_partial_outputflag toAttnFuncWithCPAndKVP2P(CP ring P2P attention) that casts each per-step partial output to float32 before LSE-correction merging across CP ranks, improving numerical stability for fp16/bf16 inputscp_p2p_fwd_fused_attn→attn_forward_func_with_cp→FusedAttentionBackend.fused_attention→DotProductAttention.forwardout_per_step.to(float32)) after the cuDNN kernel call; thefake_dtype=torch.float32path is wired and ready for when the cuDNN kernel gains native fp16/bf16→fp32 output supportfp32_partial_output=TrueAttnFuncWithCPAndKVP2P.backwardreturn tuple for the new forward inputTest plan
test_cp_with_fused_attention_fp32_partial_outputcovers all combinations of:🤖 Generated with Claude Code