Skip to content

Moonshine Streaming Model(s) Recipe - #560

Open
nenad1002 wants to merge 8 commits into
microsoft:mainfrom
nenad1002:nebanfic/moonshine-recipe
Open

Moonshine Streaming Model(s) Recipe#560
nenad1002 wants to merge 8 commits into
microsoft:mainfrom
nenad1002:nebanfic/moonshine-recipe

Conversation

@nenad1002

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 24, 2026 22:38

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

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_buffer and sample_len are 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 guarantees sample_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
Copilot AI review requested due to automatic review settings July 24, 2026 22:52

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

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

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants