Skip to content

Fix ReduceSumSquare: axes as input per ONNX spec - #76

Merged
justinchuby merged 1 commit into
mainfrom
justinchu/fix-reduce-sum-square
Apr 1, 2026
Merged

Fix ReduceSumSquare: axes as input per ONNX spec#76
justinchuby merged 1 commit into
mainfrom
justinchu/fix-reduce-sum-square

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Per ONNX opset 18+, ReduceSumSquare takes axes as an optional input tensor, not an attribute.

Problem

The current code passes axes=[-1] as a keyword argument, which onnxscript interprets as an attribute. This produces an invalid ONNX graph per the spec.

Fix

Change axes=[-1] (attribute) → [-1] (positional input tensor), matching the pattern used by ReduceSum and ReduceMean throughout the codebase.

Files changed

File Sites Context
src/mobius/components/_gated_deltanet.py 2 L2 normalization of Q and K in GatedDeltaNet attention
src/mobius/models/qwen3_tts_tokenizer.py 2 Nearest-neighbor codebook lookup (distance computation)

Testing

2219 passed, 29 skipped. Lint clean.

Per ONNX opset 18+, ReduceSumSquare axes is an optional input tensor,
not an attribute. Changed axes=[-1] (keyword arg → attribute) to [-1]
(positional arg → input tensor) to match the spec.

Affected files:
- _gated_deltanet.py: L2 normalization of Q and K (2 sites)
- qwen3_tts_tokenizer.py: nearest-neighbor codebook lookup (2 sites)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
@justinchuby
justinchuby requested review from a team and Copilot April 1, 2026 20:11
@justinchuby justinchuby added the ai Created by an AI agent label Apr 1, 2026
@justinchuby justinchuby self-assigned this Apr 1, 2026
@justinchuby justinchuby added the ai Created by an AI agent label Apr 1, 2026
@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing c1cdd3b72499e3

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 61 61 +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 360 KB 360 KB +0.0%
mamba (ssm-text-generation) num_nodes 105 105 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 61 61 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 58 58 +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 409 409 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 174 174 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 140 140 +0.0%

No performance regressions.

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

Fixes ONNX opset 18+ compliance for ReduceSumSquare by passing axes as an optional input tensor (not an attribute), aligning graph construction with the ONNX operator schema used at the repo’s default opset (24).

Changes:

  • Update ReduceSumSquare(..., axes=[-1], ...)ReduceSumSquare(..., [-1], ...) in GatedDeltaNet Q/K L2 normalization.
  • Update ReduceSumSquare(..., axes=[-1], ...)ReduceSumSquare(..., [-1], ...) in Qwen3 TTS tokenizer nearest-codebook distance computation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/mobius/components/_gated_deltanet.py Ensures ReduceSumSquare uses axes as an input tensor for opset 18+ when computing per-head L2 norms.
src/mobius/models/qwen3_tts_tokenizer.py Ensures ReduceSumSquare uses axes as an input tensor for opset 18+ in codebook distance calculations.

@github-actions

github-actions Bot commented Apr 1, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing c1cdd3b72499e3

Model Sub-model Changes Status
bert (feature-extraction) model 0
falcon model 0
gemma2 model 0
gpt2 model 0
llama model 0
llama (static-cache) model 0
mamba (ssm-text-generation) model 0
phi3 model 0
phi3 (static-cache) model 0
qwen model 0
qwen (static-cache) model 0
qwen2 model 0
qwen2 (static-cache) model 0
qwen2_moe model 0
qwen2_moe (static-cache) model 0
qwen3 model 0
qwen3 (static-cache) model 0
qwen3_5_moe (hybrid-text-generation) model 0
qwen3_5_text (hybrid-text-generation) model 0
qwen3_5_vl (hybrid-qwen-vl) decoder 0
qwen3_5_vl (hybrid-qwen-vl) embedding 0
qwen3_5_vl (hybrid-qwen-vl) vision 0
qwen3_moe model 0
qwen3_moe (static-cache) model 0
qwen3_next (hybrid-text-generation) model 0
t5 (seq2seq) decoder 0
t5 (seq2seq) encoder 0
whisper (speech-to-text) decoder 0
whisper (speech-to-text) encoder 0

No architecture changes detected.


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

@justinchuby
justinchuby merged commit 8124071 into main Apr 1, 2026
23 of 25 checks passed
@justinchuby
justinchuby deleted the justinchu/fix-reduce-sum-square branch April 1, 2026 22:22
@justinchuby justinchuby linked an issue Apr 1, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Created by an AI agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReduceSquareSum usage needs to be fixed

3 participants