Skip to content

feat(cambricon): add varlen flash attention provider - #970

Draft
baominghelly wants to merge 1 commit into
masterfrom
feat/cambricon-flash-attn-varlen-func
Draft

feat(cambricon): add varlen flash attention provider#970
baominghelly wants to merge 1 commit into
masterfrom
feat/cambricon-flash-attn-varlen-func

Conversation

@baominghelly

@baominghelly baominghelly commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add the Cambricon linked provider at implementation slot 16 for flash_attn_varlen_func.
  • Invoke the Cambricon flash-attn extension's mha_varlen_fwd entry point for packed variable-length attention.
  • Support cumulative sequence lengths, grouped-query attention, causal/window masking, ALiBi, paged KV-cache gathering, softmax LSE output, and non-default MLU streams.
  • Extend the operator tests with Cambricon references for FP16 and BF16 while preserving the NVIDIA and Moore platform-specific test behavior.

Motivation

Cambricon model prefill and variable-length batches need the FlashAttention varlen interface selected by the model operator manifest. This provider complements the KV-cache decode provider merged in #969 and reuses the linked-library declaration and paged-cache helper now available on master.

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 (requires a ! in the Conventional Commits prefix or a BREAKING CHANGE: footer)

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

Not run — the repository's official Cambricon smoke suite was not run. A fresh slot-specific Cambricon linked build and operator test were run instead.

export INFINI_OPS_DISPATCH_BATCH_SIZE=64
cmake \
  -S /workspace/src/InfiniOps-cambricon-flash-attn-varlen-func-pr \
  -B /workspace/build/pr-publish-flash-attn-varlen-func-20260904-master24bf \
  -G Ninja \
  -DAUTO_DETECT_DEVICES=OFF \
  -DAUTO_DETECT_BACKENDS=OFF \
  -DWITH_CPU=OFF \
  -DWITH_CAMBRICON=ON \
  -DWITH_NVIDIA=OFF \
  -DWITH_TORCH=OFF \
  -DWITH_LINKED=ON \
  -DGENERATE_PYTHON_BINDINGS=ON \
  -DINFINI_OPS_OPS=flash_attn_varlen_func \
  -DINFINI_RT_ROOT=/workspace/install/infinirt-master-test \
  -DINFINI_OPS_TORCH_COMPILE_JOBS=2 \
  -DPython_EXECUTABLE=/torch/venv3/pytorch/bin/python3.10 \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/workspace/build/pr-publish-flash-attn-varlen-func-20260904-master24bf-site/infini
cmake --build /workspace/build/pr-publish-flash-attn-varlen-func-20260904-master24bf --parallel "$(nproc)"
cmake --install /workspace/build/pr-publish-flash-attn-varlen-func-20260904-master24bf
PYTHONPATH=/workspace/build/pr-publish-flash-attn-varlen-func-20260904-master24bf-site \
LD_LIBRARY_PATH=/workspace/build/pr-publish-flash-attn-varlen-func-20260904-master24bf-site/infini:/workspace/install/infinirt-master-test/lib \
/torch/venv3/pytorch/bin/python3.10 -m pytest -q \
  tests/test_flash_attn_varlen_func.py --devices cambricon --maxfail=1

26 passed, 5 skipped, 1 warning in 0.45s

Test Results on Supported Platforms

Platform Affected Build / Smoke Result Full Result / Notes
NVIDIA No N/A - not affected N/A - not affected; shared test behavior preserved during rebase
Iluvatar No N/A - not affected N/A - not affected
MetaX No N/A - not affected N/A - not affected
Cambricon Yes Slot-specific fresh linked build passed; official smoke not run 26 passed, 5 skipped; one test-reference int64-to-int32 warning
Moore No N/A - not affected N/A - not affected; Moore-specific skips and reference behavior preserved during rebase
Ascend No N/A - not affected N/A - not affected
Targeted pytest output
26 passed, 5 skipped, 1 warning in 0.45s

Benchmark / Performance Impact

N/A - no benchmark was run.

Notes for Reviewers

  • The Cambricon linked flash-attn library declaration and src/common/op_utils/paged_kv_cache.h were added by feat(cambricon): add flash attention KV-cache provider #969 and are now in master.
  • The shared paged KV-cache header intentionally depends on ATen because its current consumers are linked Torch FlashAttention providers; this scope is documented inline.
  • The provider was validated with dropout disabled. softcap and deterministic are currently accepted but not forwarded to the Cambricon extension.
  • When return_attn_probs is enabled, the provider copies softmax LSE; the optional s_dmask output is not populated.
  • Paged inputs are gathered into contiguous packed K/V tensors before calling mha_varlen_fwd.
  • clang-format --dry-run --Werror and git diff --check passed.
  • The official smoke suite and performance benchmarks remain validation gaps.

@baominghelly
baominghelly force-pushed the feat/cambricon-flash-attn-varlen-func branch from 8a7adbd to db8dfc7 Compare September 3, 2026 02:10
@baominghelly
baominghelly force-pushed the feat/cambricon-flash-attn-with-kvcache branch from 6e71e4b to c7c7836 Compare September 3, 2026 02:10
@baominghelly
baominghelly force-pushed the feat/cambricon-flash-attn-varlen-func branch from db8dfc7 to fd462fc Compare September 3, 2026 02:22
@baominghelly
baominghelly marked this pull request as ready for review September 3, 2026 02:27
@baominghelly
baominghelly force-pushed the feat/cambricon-flash-attn-varlen-func branch from fd462fc to fd80cb5 Compare September 3, 2026 07:14
@baominghelly
baominghelly force-pushed the feat/cambricon-flash-attn-with-kvcache branch from c7c7836 to 4a750ac Compare September 3, 2026 07:14
Base automatically changed from feat/cambricon-flash-attn-with-kvcache to master September 4, 2026 01:59
@voltjia
voltjia requested a review from a team September 4, 2026 01:59
@baominghelly
baominghelly force-pushed the feat/cambricon-flash-attn-varlen-func branch from fd80cb5 to db40b50 Compare September 4, 2026 02:20
voltjia
voltjia previously approved these changes Sep 4, 2026
@baominghelly
baominghelly force-pushed the feat/cambricon-flash-attn-varlen-func branch from db40b50 to 59bd90d Compare September 4, 2026 03:00
@baominghelly
baominghelly marked this pull request as draft September 4, 2026 03:02
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.

2 participants