feat!: return flash attention KV cache softmax LSE - #852
Merged
Conversation
voltjia
force-pushed
the
feat/align-flash-attn-kvcache-returns
branch
from
July 29, 2026 07:30
9174351 to
a650563
Compare
voltjia
changed the base branch from
fix/wrapper-optional-tensor-overloads
to
master
July 29, 2026 07:30
voltjia
force-pushed
the
feat/align-flash-attn-kvcache-returns
branch
from
July 29, 2026 09:51
a650563 to
a3fd3e9
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
flash_attn_with_kvcache(q, k_cache, v_cache, out)overload unchanged and out-only.cache_seqlensinterfaces with a trailing optionalsoftmax_lseoutput.softmax_lseexactly whenreturn_softmax_lse=true, and copy the FlashAttention LSE into the caller-provided buffer.Motivation
return_softmax_lsewas already public, but the corresponding auxiliary output was absent, so the full interface could not represent FlashAttention's conditional return contract. The basic overload should continue to model the default out-only call.API Alignment
flash_attn_with_kvcache(q, k_cache, v_cache, out)outflash_attn_with_kvcache(..., return_softmax_lse, out, softmax_lse?)(out, softmax_lse)only whenreturn_softmax_lse=TrueType of Change
featfixperfrefactortestdocsbuild/cichorePlatforms Affected
WITH_CPU)WITH_NVIDIA)WITH_ILUVATAR)WITH_METAX)WITH_CAMBRICON)WITH_MOORE)WITH_ASCEND)WITH_TORCH)Smoke Test Result
Test Results on Supported Platforms
cache_seqlens, paged, basic/default, and stream paths passedBenchmark / Performance Impact
N/A.
Notes for Reviewers
The basic overload remains out-only. The full overload uses
std::optional<Tensor>only for the conditional auxiliary output.Five scalar-
cache_seqlensPython cases were deselected because the currentmasterwrapper generator already classifies that scalar overload asstd::optional<Tensor>. A cleanmasterCMake generation reproduced the same binding. Fixing tensor/scalar overload generation is intentionally deferred from this return-contract PR.The NVIDIA adapter keeps InfiniOps' caller-provided
outcontract by letting FlashAttention 2.7 produce its internal result and copying it intoout; directly passing the external buffer is rejected by FlashAttention in the targeted environment.