CANN: support gated linear attn #17814
Open
+109
−0
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.
Description
This PR adds support for the Gated Linear Attention (GLA) operator in the GGML CANN backend. GLA is widely used in efficient attention mechanisms (e.g., RWKV, Linear Transformer variants, etc.), which leverage gating signals and state accumulation to significantly reduce computational complexity while preserving strong modeling capacity.
Summary of Changes:
GGML_OP_GATED_LINEAR_ATTNinggml/src/ggml-cann/ggml-cann.cppand bound it to a newly implemented functionggml_cann_gated_linear_attn.ggml_cann_gated_linear_attninggml/src/ggml-cann/aclnn_ops.cpp, using ACLNN primitives such asRepeat,Mul,Add, andMvto compose the GLA computation.(C, H, T, B), where:C = H * D(total channel dimension),T = B * L(flattened batch × sequence length),gand recurrent statesas additional inputs, enabling joint state update and output generation in a single pass.Testing
Build with CANN backend enabled:
Run GLA-specific backend test (requires adding a test case for
GATED_LINEAR_ATTNintests/test-backend-ops.cpp):./bin/test-backend-ops test -b CANN0 -o GATED_LINEAR_ATTN