Conversation
…ttention Recurrent lightning attention with an indexed state pool: S <- exp(-slope) * S + k^T v ; out = q @ S. Includes the operator interface, a CPU reference implementation, an NVIDIA CUDA kernel, and pytest coverage for float32/float16/bfloat16 on both backends (validated on sm_120).
Compose aclnn Mul, Matmul and Add over a per-request workspace row. The source state row is staged before the recurrence and written back only after all tokens, preserving the read-only source-row contract for MiniMax lightning attention on Ascend.
Use KEEP_DTYPE for float32 aclnnMatmul so the 910B output projection does not silently downcast FP32 and exceed the operator tolerance.
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
LightningAttentionInfinilm, an InfiniLM-specific indexed-pool lightning attention operator.src/base/lightning_attention_infinilm.h.src/native/cpu/ops/lightning_attention_infinilm/lightning_attention_infinilm.h.src/native/cuda/andsrc/native/cuda/nvidia/.src/native/ascend/ops/lightning_attention_infinilm/kernel.h.tests/test_lightning_attention_infinilm.py.Motivation
MiniMax-style linear attention uses a recurrent lightning-attention state with a per-head decay and an indexed state pool:
PyTorch has no directly corresponding operator. The closest public reference is Flash-Linear-Attention's
fused_recurrent_lightning_attn, but this implementation also has the InfiniLM-specific indexed state-pool contract.The operator is needed by the MiniMax model support work in InfiniLM.
Closes # (N/A: internal MiniMax model-support work; no tracking issue in this fork)
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
Affected-platform builds succeeded.
Operator-specific smoke commands and results:
The repository-wide
pytest tests -m smoke -qrun was not executed on this branch; CI should run the full affected-platform smoke set.Test Results on Supported Platforms
Full `pytest` output (optional)
Benchmark / Performance Impact
N/A. This PR is a correctness-first implementation. The Ascend path composes ACLNN operators and does not claim fused-kernel performance; an AscendC fused kernel is a possible follow-up.
Notes for Reviewers
initial_stateis intentionally passed as a mutableTensorbecause the destination row is updated.initial_state_indicesis never modified; the source row is copied into a workspace state first and the destination row is written only after all tokens have been processed.int32state indices. The operator interface implementsint64as well, but that path is not currently parameterized in the test matrix.aclnnMul,aclnnMatmul, andaclnnAddwith the existingWorkspacePool. FP32 matmul usescube_math_type=0to avoid FP32 downcast on 910B.head_dimfits within one block.