Moonshine Streaming Model(s) Recipe - #560
Open
nenad1002 wants to merge 8 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new CPU recipe under usefulSensors-moonshine-streaming/ to export the Useful Sensors Moonshine Streaming ASR model (tiny/small) into the five ONNX Runtime GenAI streaming components, with an end-to-end pipeline script and optional INT8 k-quant for encoder/decoder_kv.
Changes:
- Introduces an end-to-end exporter pipeline (
cpu/optimize.py) that runs five Olive conversions, generates GenAI runtime configs, exports tokenizer files, and downloads Silero VAD. - Adds model wrapper modules + dummy inputs for exporting the five-component streaming graph contract (
cpu/moonshine_model_load.py), plus a standalone non-Olive exporter for debugging (cpu/export_moonshine_streaming.py). - Adds Olive JSON configs for FP32 and optional k-quant flows, along with documentation and metadata for the new recipe.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| usefulSensors-moonshine-streaming/cpu/requirements.txt | Declares Python dependencies needed to run the CPU Moonshine streaming export pipeline. |
| usefulSensors-moonshine-streaming/cpu/README.md | Documents the recipe purpose, setup, run commands, quantization options, and expected outputs. |
| usefulSensors-moonshine-streaming/cpu/optimize.py | Implements the full pipeline: Olive runs per component, config generation, tokenizer export, and VAD download. |
| usefulSensors-moonshine-streaming/cpu/moonshine_model_load.py | Provides model loaders and thin wrapper modules used by Olive/standalone export to match the GenAI streaming I/O contract. |
| usefulSensors-moonshine-streaming/cpu/moonshine_frontend_fp32_cpu.json | Olive config to export the frontend component to ONNX (FP32). |
| usefulSensors-moonshine-streaming/cpu/moonshine_encoder_fp32_cpu.json | Olive config to export the encoder component to ONNX (FP32). |
| usefulSensors-moonshine-streaming/cpu/moonshine_adapter_fp32_cpu.json | Olive config to export the adapter component to ONNX (FP32). |
| usefulSensors-moonshine-streaming/cpu/moonshine_cross_kv_fp32_cpu.json | Olive config to export the cross-KV component to ONNX (FP32). |
| usefulSensors-moonshine-streaming/cpu/moonshine_decoder_kv_fp32_cpu.json | Olive config to export the decoder-KV component to ONNX (FP32). |
| usefulSensors-moonshine-streaming/cpu/moonshine_encoder_kquant8_cpu.json | Olive config to export+quantize the encoder using INT8 k-quant. |
| usefulSensors-moonshine-streaming/cpu/moonshine_decoder_kv_kquant8_cpu.json | Olive config to export+quantize the decoder-KV using INT8 k-quant. |
| usefulSensors-moonshine-streaming/cpu/info.yaml | Registers recipe metadata and lists produced artifacts/scripts. |
| usefulSensors-moonshine-streaming/cpu/export_moonshine_streaming.py | Standalone TorchDynamo ONNX exporter for debugging outside Olive. |
| usefulSensors-moonshine-streaming/cpu/init.py | Marks cpu/ as a Python package for imports used by the recipe. |
Comments suppressed due to low confidence (1)
usefulSensors-moonshine-streaming/cpu/moonshine_model_load.py:115
sample_bufferandsample_lenare accepted as inputs but never used. This means any buffered sub-frame audio passed in (e.g., a flush call after a non-multiple-of-frame_len chunk) would be silently dropped, contradicting the module’s stateful interface. If the runtime contract guaranteessample_len == 0, it’s safer to enforce that explicitly to avoid producing incorrect features silently.
# In the genai streaming pipeline chunk_samples is a multiple of
# frame_len, so the carried sample_buffer is always empty on input
# (sample_len == 0). We therefore frame the chunk directly. The
# correct leftover state is still emitted so a final (flush) chunk of
# non-multiple length threads/records its remainder before reset.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+84
to
+86
| Sub-frame audio (``total_samples % frame_len``) is carried in | ||
| ``sample_buffer`` / ``sample_len`` and prepended to the next chunk so the | ||
| framing is contiguous. |
Comment on lines
+7
to
+10
| source /home/nebanfic/miniconda3/bin/activate moonshine | ||
| python export_moonshine_streaming.py \ | ||
| --model usefulsensors/moonshine-streaming-tiny \ | ||
| --output-dir /datadisks/disk3/nebanfic/moonshine-streaming-tiny-mine |
Comment on lines
+120
to
+130
| total = audio_chunk.shape[1] | ||
| n_frames = total // self.frame_len | ||
| used = n_frames * self.frame_len | ||
|
|
||
| frames = audio_chunk.narrow(1, 0, used).reshape(1, -1, self.frame_len) # [1, nf, 80] | ||
| leftover = audio_chunk.narrow(1, used, total - used) # [1, rem] | ||
| rem = leftover.shape[1] | ||
| sample_buffer_out = F.pad(leftover, (0, self.buf_size - rem)) # [1, 79] | ||
| zero_i64 = frame_count * 0 | ||
| sample_len_out = zero_i64 + rem # [1] | ||
|
|
Comment on lines
+193
to
+196
| for layer, (left, right) in zip(self.layers, self.windows): | ||
| mask = self._sliding_mask(seq_len, left, right, hidden.device, hidden.dtype) | ||
| hidden = layer(hidden, attention_mask=mask) | ||
| return self.final_norm(hidden) # [1, T, encoder_dim] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.