Repository navigation
Add Moonshine speech recognition support - #463
Conversation
Performance Comparison
|
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
There was a problem hiding this comment.
Pull request overview
Adds first-class support for the Hugging Face Moonshine raw-waveform ASR architecture to mobius, extending the existing speech-to-text pipeline beyond Whisper while keeping export + test infrastructure consistent with the repo’s task/model/registry stack.
Changes:
- Introduces native
moonshinemodel/config/registry support and ONNX graph construction (encoder + cached decoder). - Generalizes
SpeechToTextTaskand onnx-genai metadata/export paths to support model-declared audio inputs and optional encoder attention-mask routing. - Adds/extends L1–L5 coverage: build/weight-alignment/integration parity tests plus committed real-audio goldens and cases.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/weight_alignment_test.py | Adds speech encoder-decoder weight-alignment parametrization. |
| tests/moonshine_integration_test.py | New parity tests for Moonshine synthetic + real checkpoints (encoder/decoder/cache). |
| tests/e2e_golden_test.py | Generalizes ASR e2e runner to respect encoder input dtypes and optional encoder masks. |
| tests/build_graph_test.py | Adds L1 graph/IO/initializer assertions for Moonshine package build. |
| tests/_test_configs.py | Adds Moonshine to shared SPEECH_CONFIGS test matrix. |
| testdata/golden/audio/moonshine-tiny.json | Adds Moonshine L4 logits golden. |
| testdata/golden/audio/moonshine-tiny_generation.json | Adds Moonshine L5 generation golden. |
| testdata/cases/audio/moonshine-tiny.yaml | Adds Moonshine golden test case definition. |
| src/mobius/tasks/_speech_to_text.py | Generalizes SpeechToTextTask encoder/decoder IO to model-declared audio inputs + optional mask routing. |
| src/mobius/models/moonshine.py | Implements Moonshine encoder/decoder modules (raw-waveform conv stem, partial interleaved RoPE, cache). |
| src/mobius/models/init.py | Exposes Moonshine model in public models API. |
| src/mobius/integrations/ort_genai/auto_export.py | Adds explicit guard for native onnxruntime-genai Moonshine export. |
| src/mobius/integrations/ort_genai/auto_export_test.py | Tests the Moonshine native-runtime rejection path. |
| src/mobius/integrations/onnx_genai/inference_metadata.py | Adds optional encoder_attention_mask routing to speech-to-text composite metadata. |
| src/mobius/integrations/onnx_genai/auto_export.py | Emits audio_processor.json and auto-detects encoder mask dataflow for ASR packages. |
| src/mobius/integrations/onnx_genai/auto_export_test.py | Adds coverage for encoder attention-mask dataflow emission. |
| src/mobius/components/_whisper.py | Makes Conv1d bias optional to support bias-free conv stems. |
| src/mobius/components/init.py | Exports apply_rotary_pos_emb for shared RoPE usage. |
| src/mobius/_testing/generation.py | Updates speech-to-text generator to optionally pass encoder attention masks. |
| src/mobius/_registry.py | Registers moonshine model_type and adds a default model ID mapping. |
| src/mobius/_configs/_base.py | Introduces SpeechToTextConfig base + MoonshineConfig; refactors WhisperConfig inheritance/signature. |
| src/mobius/_configs/init.py | Re-exports MoonshineConfig and SpeechToTextConfig. |
| src/mobius/_config_resolver_test.py | Adds Moonshine config extraction + default task coverage. |
| src/mobius/init.py | Exposes new configs in public package API. |
| scripts/generate_golden.py | Generalizes speech-to-text golden generation to AutoModel/AutoProcessor (not Whisper-only). |
| README.md | Adds Moonshine to supported Speech-to-Text models list. |
Suppressed comments (1)
src/mobius/tasks/_speech_to_text.py:82
- WhisperConfig still carries num_mel_bins, but SpeechToTextTask now sizes the encoder input using encoder_input_channels (default=80). This can silently produce an invalid graph when num_mel_bins != encoder_input_channels (e.g. the tiny Whisper configs in tests set num_mel_bins=16), because Conv1d weights are created for num_mel_bins while the task declares a different channel dimension. Derive the channel dimension from num_mel_bins when building mel-feature encoders to keep task I/O consistent with the module.
input_shape = [batch, audio_seq_len]
if config.encoder_input_channels is not None:
input_shape.insert(1, config.encoder_input_channels)
encoder_input = builder.input(
config.encoder_input_name,
dtype=config.dtype,
shape=input_shape,
)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
justinchuby
left a comment
There was a problem hiding this comment.
Reviewed the current diff for correctness; no additional high-confidence issues found beyond the existing unresolved review threads.
Implement Moonshine's raw-waveform convolutional encoder, interleaved partial-RoPE encoder-decoder attention, cached decoding, config and weight mapping, and generalized speech-to-text packaging. Add synthetic and checkpoint parity tests, real-audio L4/L5 goldens, processor metadata, and explicit native ORT GenAI capability handling. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Decompose Moonshine's single-group normalization into reduction and affine operations so CUDA execution no longer falls back to CPU for the full convolution activation. Add graph coverage that prevents the CPU-only GroupNormalization op from returning. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Synchronize the generic speech encoder channel contract with Whisper's num_mel_bins so 128-bin large-v3 and turbo checkpoints do not retain the legacy 80-channel default. Add resolver and graph-shape regression coverage. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Initialize speech-to-text and seq2seq empty KV caches from each decoder input's declared dtype so fp16 and bf16 CUDA generation do not receive fp32 cache tensors. Update the helper contract documentation accordingly. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Describe the configured encoder input and optional mask dataflow instead of implying that every speech-to-text model follows Whisper-specific I/O. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Clarify configurable speech encoder and mask routing, use the public ONNX GroupNorm component with parity coverage, remove the experimental runtime suggestion from the ORT GenAI error, and validate the declared Moonshine L5 reference. Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
Apply the repository formatter to the L5 golden reference validation added during review. Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
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]>
922628e to
483da44
Compare
Summary
moonshinesupport formoonshine-ai/moonshine-tinywithout aliasing it to WhisperSpeechToTextTaskwhile preserving Whisper, including correct 80/128num_mel_binsinput-channel handlingaudio_processor.json, and composite onnx-genai metadataUpdated from main
Rebased onto
origin/mainat1e6f61f42b0ddbc90f60bccbf00eff26cd484256, including main's fused Swish support. Moonshine now uses the publicSiLUcomponent and emits one ONNXSwishop per decoder layer instead ofSigmoid + Mul.Fusion and optimized-graph audit
Audited fp16 opset-24 graphs with ONNX Runtime GPU 1.28.0 on CUDA EP;
CUDAExecutionProviderwas asserted first for encoder and decoder.Additional structural evidence:
Swish, 0SigmoidQuickGelu(alpha=1.0)[B,C,T]to transformer[B,T,C]The standard ONNX
Attentionop is intentional: encoder and cross-attention require explicit padding bias, which contrib GQA rejects, and Moonshine's head dimension 36 is not XQA-eligible.Validation
CPU and CUDA parity
Environment: NVIDIA RTX A1000, driver 573.44, CUDA 12.8, ONNX Runtime GPU 1.28.0.
Real
652-129742-0006.flac, fp32:Dtype coverage
Test commands/results
python -m pytest tests/build_graph_test.py -k "moonshine or whisper" -q: 17 passedpython -m pytest tests/moonshine_integration_test.py -q: 5 passedtests/e2e_golden_test.py -m "golden or generation" -k moonshine: 2 passedlintrunner -a: no lint issuesChecklist / waivers
lintrunner -a, schema, coverage, and targeted regressionsWaivers: