Skip to content

Commit 8124071

Browse files
justinchubyCopilot
andauthored
Fix ReduceSumSquare: axes as input per ONNX spec (#76)
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. Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c1cdd3b commit 8124071

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/mobius/components/_gated_deltanet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ def forward(
212212
# TODO: Use op.LpNormalization directly once ORT >=1.25 supports it.
213213
q_4d = op.Reshape(query, qk_4d_shape) # (B, T, num_k_heads, head_k_dim)
214214
q_l2 = op.Sqrt(
215-
op.ReduceSumSquare(q_4d, axes=[-1], keepdims=1)
215+
op.ReduceSumSquare(q_4d, [-1], keepdims=1)
216216
) # (B, T, num_k_heads, 1) — L2 norm per head
217217
query = op.Reshape(op.Div(q_4d, q_l2), qk_3d_shape) # (B, T, key_dim)
218218

219219
k_4d = op.Reshape(key, qk_4d_shape) # (B, T, num_k_heads, head_k_dim)
220220
k_l2 = op.Sqrt(
221-
op.ReduceSumSquare(k_4d, axes=[-1], keepdims=1)
221+
op.ReduceSumSquare(k_4d, [-1], keepdims=1)
222222
) # (B, T, num_k_heads, 1) — L2 norm per head
223223
key = op.Reshape(op.Div(k_4d, k_l2), qk_3d_shape) # (B, T, key_dim)
224224

src/mobius/models/qwen3_tts_tokenizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,9 @@ def forward(self, op: builder.OpBuilder, x: ir.Value):
593593
embedding = self.codebook(op)
594594

595595
# Find nearest: ||x - e||² = ||x||² - 2*x·e^T + ||e||²
596-
x_sq = op.ReduceSumSquare(x_t, axes=[-1], keepdims=1) # (B,T,1)
596+
x_sq = op.ReduceSumSquare(x_t, [-1], keepdims=1) # (B,T,1)
597597
e_sq = op.ReduceSumSquare(
598-
op.Unsqueeze(embedding, [0]), axes=[-1], keepdims=0
598+
op.Unsqueeze(embedding, [0]), [-1], keepdims=0
599599
) # (1, codebook_size)
600600
dot = op.MatMul(x_t, op.Transpose(embedding, perm=[1, 0]))
601601
distances = op.Add(op.Sub(x_sq, op.Mul(dot, op.Constant(value_float=2.0))), e_sq)

0 commit comments

Comments
 (0)