Skip to content

Commit 483da44

Browse files
justinchubyCopilot
andcommitted
Fuse Moonshine decoder activation
Use the public SiLU component added on main so Moonshine emits one ONNX Swish op per decoder layer instead of Sigmoid plus Mul. Add structural coverage that prevents the decomposed activation from returning. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent 8613180 commit 483da44

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎src/mobius/models/moonshine.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@
2121
GroupNorm,
2222
LayerNormNoBias,
2323
Linear,
24+
SiLU,
2425
apply_rotary_pos_emb,
2526
)
2627

2728
_INT64_MAX = 9223372036854775807
2829

2930

30-
def _silu(op: OpBuilder, x: ir.Value) -> ir.Value:
31-
return op.Mul(x, op.Sigmoid(x))
32-
33-
3431
def _padding_attention_bias(
3532
op: OpBuilder,
3633
attention_mask: ir.Value,
@@ -178,6 +175,7 @@ def __init__(self, config: MoonshineConfig):
178175
super().__init__()
179176
self.fc1 = Linear(config.hidden_size, 2 * config.intermediate_size, bias=True)
180177
self.fc2 = Linear(config.intermediate_size, config.hidden_size, bias=True)
178+
self.activation = SiLU()
181179
self._intermediate_size = config.intermediate_size
182180

183181
def forward(self, op: OpBuilder, hidden_states: ir.Value) -> ir.Value:
@@ -188,7 +186,7 @@ def forward(self, op: OpBuilder, hidden_states: ir.Value) -> ir.Value:
188186
axis=-1,
189187
_outputs=2,
190188
)
191-
return self.fc2(op, op.Mul(data, _silu(op, gate)))
189+
return self.fc2(op, op.Mul(data, self.activation(op, gate)))
192190

193191

194192
class MoonshineEncoderLayer(nn.Module):

‎tests/build_graph_test.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2997,6 +2997,9 @@ def test_moonshine_architecture_initializers(self):
29972997
assert "decoder.layers.0.mlp.fc1.weight" in decoder_initializers
29982998
assert "decoder.proj_out.weight" in decoder_initializers
29992999
assert "GroupNormalization" in {node.op_type for node in package["encoder"].graph}
3000+
decoder_ops = [node.op_type for node in package["decoder"].graph]
3001+
assert decoder_ops.count("Swish") == TINY_LAYERS
3002+
assert "Sigmoid" not in decoder_ops
30003003

30013004

30023005
class TestBuildGraphQwen3ASR:

0 commit comments

Comments
 (0)