Skip to content

feat(nvidia): add flash_attn_with_kvcache#818

Merged
voltjia merged 1 commit into
masterfrom
feat/nvidia-flash-attn-kvcache
Jul 25, 2026
Merged

feat(nvidia): add flash_attn_with_kvcache#818
voltjia merged 1 commit into
masterfrom
feat/nvidia-flash-attn-kvcache

Conversation

@voltjia

@voltjia voltjia commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add the Dao FlashAttention 2.7 flash_attn_with_kvcache API with the InfiniOps trailing-output convention.
  • Add an NVIDIA provider backend that links the installed flash_attn_2_cuda extension without a submodule.
  • Cover dense and paged caches, in-place KV append, scalar and tensor sequence lengths, GQA, and non-default streams.

Motivation

Decode attention needs to update an existing KV cache and consume it in the same kernel. PyTorch SDPA and the existing varlen FA2 operator do not expose this fused mutation contract. This operator follows Dao FlashAttention's public flash_attn_with_kvcache interface, with InfiniOps outputs placed last.

N/A - no linked issue.

Type of Change

  • feat - new feature / new operator / new platform
  • fix - bug fix
  • perf - performance improvement (no behavioral change)
  • refactor - code restructuring without behavior change
  • test - adding or fixing tests only
  • docs - documentation only
  • build / ci - build system or CI configuration
  • chore - tooling, formatting, or other non-code changes
  • Breaking change

Platforms Affected

  • CPU (WITH_CPU)
  • NVIDIA (WITH_NVIDIA)
  • Iluvatar (WITH_ILUVATAR)
  • MetaX (WITH_METAX)
  • Cambricon (WITH_CAMBRICON)
  • Moore (WITH_MOORE)
  • Ascend (WITH_ASCEND)
  • PyTorch C++ bindings (WITH_TORCH)
  • Build system / CMake / CI
  • Python bindings / user-facing API

Smoke Test Result

GitHub Actions: 19 checks passed; documentation deploy skipped as expected.

The default smoke operator set is unchanged because `flash_attn_varlen_func`
already represents the FlashAttention provider. Consequently, standard smoke
CI does not compile or execute `flash_attn_with_kvcache` itself.

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
NVIDIA Yes Main and shadow CI passed on head 0f6af3e Focused operator-pruned runtime and installed-artifact readelf checks remain pending; standard smoke intentionally excludes this second provider operator
Iluvatar No N/A N/A
MetaX No N/A N/A
Cambricon No N/A N/A
Moore No N/A N/A
Ascend No N/A N/A
Static validation
ruff format --check tests/test_flash_attn_with_kvcache.py
1 file already formatted

ruff check tests/test_flash_attn_with_kvcache.py
All checks passed!

clang-format 21 --dry-run --Werror <three changed C++ files>
exit 0

python -m py_compile tests/test_flash_attn_with_kvcache.py
exit 0

GitHub Actions on 0f6af3e:
build, Ruff, clang-format, main CI, and CI v2 shadow passed.

Benchmark / Performance Impact

N/A - this PR adds an existing provider kernel and makes no comparative performance claim.

Notes for Reviewers

  • Full NVIDIA + Torch builds require an installed FlashAttention 2.7 distribution. Operator-pruned builds require it only when this operator is selected.
  • CMake validates the flash::mha_fwd_kvcache symbol before linking. The Python extension has no SONAME, so InfiniOps links by exact basename and installs an $ORIGIN/.. runtime search path.
  • k_cache and v_cache are mutable and follow the upstream in-place append behavior.
  • The upstream return_softmax_lse parameter is retained for parameter-order alignment, but this first representative integration supports only false; a second trailing LSE output is intentionally out of scope.
  • This PR remains a draft until an NVIDIA environment runs the focused
    operator-pruned test and verifies the installed library's NEEDED and
    RUNPATH entries with readelf -d.

@voltjia voltjia changed the title feat(nvidia): add flash_attn_with_kvcache feat(nvidia): add flash_attn_with_kvcache Jul 25, 2026
@voltjia
voltjia marked this pull request as ready for review July 25, 2026 09:20
@voltjia
voltjia requested a review from a team July 25, 2026 09:20
@voltjia
voltjia merged commit 01f63f4 into master Jul 25, 2026
20 checks passed
@voltjia
voltjia deleted the feat/nvidia-flash-attn-kvcache branch July 25, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant