fix: pack flash_attn_varlen_func softmax LSE output - #861
Merged
Conversation
voltjia
marked this pull request as ready for review
August 2, 2026 03:16
flash_attn_varlen_func softmax LSE output
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
softmax_lseresult to the public packed(num_heads, total_q)layout insrc/torch/ops/flash_attn_varlen_func/flash_attn_varlen_func.cc.tests/test_flash_attn_varlen_func.pyso the existing unequal-length batch covers both padded and packed ATen layouts.Motivation
PR #854 validated against a newer PyTorch that returns packed LSE output, but the pinned NVIDIA CI image uses PyTorch 2.5 and returns
(batch, num_heads, max_seqlen_q). Copying(2, 4, 5)directly into the public(4, 8)output fails with the reported dimension 2 mismatch.This fixes the deterministic NVIDIA failure in:
No issue is linked; this PR directly repairs the failing
masterchecks above.Type of Change
feat- new feature / new operator / new platformfix- bug fixperf- performance improvement (no behavioral change)refactor- code restructuring without behavior changetest- adding or fixing tests onlydocs- documentation onlybuild/ci- build system or CI configurationchore- tooling, formatting, or other non-code changes!in the Conventional Commits prefix or aBREAKING CHANGE:footer)Platforms Affected
WITH_CPU)WITH_NVIDIA)WITH_ILUVATAR)WITH_METAX)WITH_CAMBRICON)WITH_MOORE)WITH_ASCEND)WITH_TORCH)Smoke Test Result
Final commit
05987b44,ssh nvidia,nvcr.io/nvidia/pytorch:24.10-py3, PyTorch2.5.0a0+e000cf0, InfiniRTb548ff5a:Compatibility build,
accelerator-dev/nvidia:latest, PyTorch2.10.0a0+b4e4ee81d3, InfiniRTb548ff5a:Formatting:
Test Results on Supported Platforms
Full `pytest` output (optional)
Benchmark / Performance Impact
N/A - correctness fix. The PyTorch 2.5 compatibility path performs an on-device mask and packing copy only when auxiliary outputs are requested and ATen returns padded LSE storage. The already-packed path used by newer PyTorch versions remains a direct copy.
Notes for Reviewers
(num_heads, total_q); this PR does not change the API or base-class validation.cu_seqlens_q, avoiding a host synchronization or per-sequence CPU loop.s_dmaskremains an empty tensor for the currently required zero-dropout inference path.