feat(moore): support flash_attn_varlen_func#819
Open
voltjia wants to merge 6 commits into
Open
Conversation
flash_attn_varlen_func
voltjia
marked this pull request as ready for review
July 25, 2026 09:21
voltjia
force-pushed
the
feat/moore-flash-attn-varlen
branch
from
July 25, 2026 14:26
a29db4c to
f8e16ae
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_varlen_funcpublic operator through TorchMusa's PrivateUse1 registration ofaten::_flash_attention_forward.flash_attn_with_kvcache#818 while preserving both the NVIDIA FlashAttention 2.7 and Moore TorchMusa dependency paths.Motivation
The public operator already follows Dao FlashAttention's
flash_attn_varlen_funcAPI. TorchMusa exposes the same ATen operator for PrivateUse1, so InfiniOps should rely on ATen dispatch instead of embedding CUDA/MUSA branches in the operator implementation.N/A - no linked issue.
Torch Backend Architecture
The shared implementation in
src/torch/ops/flash_attn_varlen_funcis deliberately platform-neutral:WITH_NVIDIA/WITH_MOOREpreprocessor branches;ToAtenTensor<kDev>and callsat::_flash_attention_forwardonce;addandgemmTorch backends.ATen dispatch selects CUDA or PrivateUse1 from the tensor device. Moore's real provider limitations are isolated in
src/torch/moore/ops/flash_attn_varlen_func: local windows are rejected, and causal calls require matching per-sequence query/key lengths. The adapter then delegates to the same shared ATen implementation. This is a file-level backend boundary, not an in-file platform branch.find_package(TorchMusa)and--no-as-neededlinkage remain necessary at the CMake layer because TorchMusa registers PrivateUse1 kernels and device guards through library static initialization.WITH_MOOREis also retained only as a build/codegen selection define for Moore explicit instantiations; it is not referenced by the operator implementation.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 changesPlatforms Affected
WITH_CPU)WITH_NVIDIA)WITH_ILUVATAR)WITH_METAX)WITH_CAMBRICON)WITH_MOORE)WITH_ASCEND)WITH_TORCH)Smoke Test Result
The two focused NVIDIA skips are Moore-only provider capability cases. The focused matrix covers FP16/BF16, head dimensions 64/128, MHA/GQA, global/local causal attention, unequal Q/K lengths, and explicit/implicit current-stream execution.
The final-head Moore smoke-pruned build and focused test also pass in the target TorchMusa environment. The operator's own smoke case is
1 passed, 29 deselected. The broader Moore smoke selection, with the unrelated #818 kvcache module excluded because that target image raises an import-time illegal instruction, is48 passed, 15 skipped, 2 failed, 5662 deselected; the only failures are pre-existing FP32 GEMM tolerance cases. GitHub Moore main and shadow CI both pass on the same head.Test Results on Supported Platforms
28 passed, 2 skipped; no full-suite run16 passed, 14 skipped; broader smoke has only two pre-existing FP32 GEMM tolerance failuresValidation environments
Benchmark / Performance Impact
N/A - this PR exposes an existing TorchMusa ATen provider and makes no comparative performance claim.
Notes for Reviewers
at::_flash_attention_forwardcall and no platform macro or vendor stream code.WITH_MOORE=ONplusWITH_TORCH=ONrequires an installed TorchMusa package that providesTorchMusaConfig.cmakeand registersaten::_flash_attention_forwardfor PrivateUse1.WITH_MOOREdefine is required by generated explicit instantiations; removing it produces unresolved generated Moore operator symbols. It does not specialize this operator's behavior.flash_attn_varlen_funcsmoke coverage.