Skip to content

Simplify LinearAttention to single 6-input signature - #226

Merged
gramalingam merged 2 commits into
mainfrom
rama/linear-attn
Apr 30, 2026
Merged

gramalingam merged 2 commits into
mainfrom
rama/linear-attn

Conversation

@gramalingam

Copy link
Copy Markdown
Collaborator

Now that onnx-shape-inference >=0.1.9 accepts trailing optional inputs (matching ONNX C++ behavior), we no longer need per-variant arity specialization for LinearAttention.

Changes:

  • Bump onnx-shape-inference minimum to >=0.1.9
  • Declare all 6 inputs (query, key, value, past_state, decay, beta) unconditionally, using None for unused trailing inputs
  • Replace *args unpacking with named parameters in the body function
  • Remove the TODO about onnx-shape-inference strict arity check

Call sites that omit trailing inputs (e.g. Mamba2Block with 'gated' update_rule passing only 5 inputs) now work correctly without needing a specialized function with fewer formal parameters.

Now that onnx-shape-inference >=0.1.9 accepts trailing optional inputs
(matching ONNX C++ behavior), we no longer need per-variant arity
specialization for LinearAttention.

Changes:
- Bump onnx-shape-inference minimum to >=0.1.9
- Declare all 6 inputs (query, key, value, past_state, decay, beta)
  unconditionally, using None for unused trailing inputs
- Replace *args unpacking with named parameters in the body function
- Remove the TODO about onnx-shape-inference strict arity check

Call sites that omit trailing inputs (e.g. Mamba2Block with 'gated'
update_rule passing only 5 inputs) now work correctly without needing
a specialized function with fewer formal parameters.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: G Ramalingam <[email protected]>
@gramalingam
gramalingam requested review from a team and Copilot April 28, 2026 23:02
@gramalingam
gramalingam enabled auto-merge (squash) April 28, 2026 23:02
@github-actions

github-actions Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 612abc3 → e00221e

Model Sub-model Changes Status

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

@github-actions

github-actions Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 612abc3 → e00221e

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 60 60 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 107 107 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 53 53 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 61 61 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 58 58 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 98 98 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 59 59 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 61 61 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 58 58 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 408 408 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 166 166 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

@codecov

codecov Bot commented Apr 28, 2026

Copy link
Copy Markdown

The author of this PR, gramalingam, is not an activated member of this organization on Codecov.
Please activate this user on Codecov to display this PR comment.
Coverage data is still being uploaded to Codecov.io for purposes of overall coverage calculations.
Please don't hesitate to email us at [email protected] with any questions.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Simplifies the LinearAttention ONNX function signature now that onnx-shape-inference supports trailing optional inputs, aiming to avoid per-variant arity specialization.

Changes:

  • Bump onnx-shape-inference minimum version to >=0.1.9.
  • Refactor LinearAttention function input handling toward a single 6-input signature.
  • Replace *args parsing in the function body with named parameters.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/mobius/functions/linear_attention.py Adjusts function input declaration and body signature for LinearAttention.
pyproject.toml Updates dependency floor for onnx-shape-inference.

Address review comment: declare decay and beta as ir.Value
unconditionally so the ir.Function signature is truly fixed at
6 inputs regardless of update_rule. The body's conditional logic
simply ignores unused trailing inputs.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: G Ramalingam <[email protected]>
@gramalingam
gramalingam merged commit c35d0c1 into main Apr 30, 2026
20 of 21 checks passed
@gramalingam
gramalingam deleted the rama/linear-attn branch April 30, 2026 16:10
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.

3 participants