Conversation
test_varlen compares flash_attn_varlen_func against F.scaled_dot_product_attention with a fixed atol=rtol=3e-2 that was calibrated for head_dim <= 128. Since head_dim=256 support landed (Dao-AILab#2412), the bf16 backward dK/dV gradients (dK = dS^T @ Q, dV = P^T @ dO, summed over 256 dims) accumulate ~2x the rounding error of D=128 and reach ~6e-2, failing three MQA/GQA varlen cases. fp16 is unaffected (11-bit mantissa). Loosen the tolerance to 1e-1 for bf16 + head_dim=256 only; all other configs keep 3e-2. Co-Authored-By: Claude Code <noreply@anthropic.com>
This branch has not been deployed
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.
For bf16 backward, increasing head_dim from 128 to 256 (#2412) increases the reduction length of the dot products involved in computing dP (and consequently dS), which can lead to larger floating-point discrepancies between the FA4 and PyTorch SDPA implementations. These discrepancies can propagate to dK/dV, and are further exposed in MQA/GQA where gradients for shared KV heads require additional accumulation.