Skip to content

feat: fine-tune Moonshine's streaming models - #29

Merged
Rebreda merged 2 commits into
mainfrom
feat/moonshine-streaming
Aug 26, 2026
Merged

feat: fine-tune Moonshine's streaming models#29
Rebreda merged 2 commits into
mainfrom
feat/moonshine-streaming

Conversation

@Rebreda

@Rebreda Rebreda commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Lemonade now serves Moonshine-Medium-Streaming, and the streaming models carry their own neural VAD, which makes them the interesting target for this project. They are a separate architecture in transformers, moonshine_streaming with MoonshineStreamingForConditionalGeneration and MoonshineStreamingProcessor, not a flag on the offline model.

They fit the existing seq2seq path: same raw waveform in input_values, same Wav2Vec2 feature extractor, English-only, and unlike offline Moonshine the tokenizer already carries a pad token.

Two things had to change, and only running it found them

Frame alignment. The encoder reshapes its input to [batch, -1, 80], one 5 ms frame at 16 kHz, and raises on any other length. Padding a batch to its longest clip lands on a multiple of 80 only by luck. Architecture gained pad_to_multiple and the collator honours it.

A synthetic test passed because 16000 and 24000 both divide by 80. The first real batch gave:

RuntimeError: shape '[4, -1, 80]' is invalid for input of size 4246272

Name detection. moonshine-streaming-small resolved to offline Moonshine, because hub ids use hyphens, model_type uses underscores, and moonshine is a prefix of moonshine_streaming. It would have silently trained with the wrong processor. Detection now flattens separators and takes the longest match.

Verified on real hardware

gfx1151, ROCm torch, real MDC dataset:

Architecture: moonshine_streaming
Trainable params: 327,680 / 140,644,025 (0.23%)
torch 2.9.1+rocm7.2.0 (rocm build), device: AMD Radeon Graphics

Training runs and the loss moves. Two honest caveats.

Throughput is roughly 46 s/step at batch 4 on this iGPU, so a real run is hours.

The mid-training eval crashed the GPU queue:

HSA_STATUS_ERROR_EXCEPTION: An HSAIL operation resulted in a hardware exception. code: 0x1016

at batch 34 of 193, during predict_with_generate. That is the gfx1151 instability AMD's own support matrix implies, not something this PR introduces, and Whisper runs on the same box have completed eval fine. Worth knowing before planning a long run: consider --eval-steps beyond --max-steps to skip mid-training eval on this hardware.

Not covered

moonshine-ai/moonshine-streaming, the medium model Lemonade serves, ships as ONNX graphs with no PyTorch weights and cannot be fine-tuned. moonshine-streaming-small is the transformers checkpoint. Serving and fine-tuning are different artifacts here.

406 tests pass.

g added 2 commits August 26, 2026 00:24
Lemonade now serves Moonshine-Medium-Streaming, and the streaming models carry
their own neural VAD, which makes them the interesting target for this project.
They are a separate architecture in transformers, moonshine_streaming with
MoonshineStreamingForConditionalGeneration and MoonshineStreamingProcessor,
not a flag on the offline model.

They fit the existing seq2seq path: same raw waveform in input_values, same
Wav2Vec2 feature extractor, English-only, and unlike offline Moonshine the
tokenizer already carries a pad token, so no fallback is needed there.

Two things had to change.

The encoder reshapes its input to [batch, -1, 80], one 5 ms frame at 16 kHz,
and raises on any other length. Padding a batch to its longest clip lands on a
multiple of 80 only by luck. Architecture gained pad_to_multiple and the
collator honours it. This did not show up in a synthetic test because 16000
and 24000 both happen to divide by 80; it appeared on the first real batch as
"shape '[4, -1, 80]' is invalid for input of size 4246272".

Name-based detection resolved moonshine-streaming-small to offline Moonshine,
because hub ids use hyphens while model_type uses underscores and "moonshine"
is a prefix of "moonshine_streaming". Detection now flattens separators and
takes the longest match.

Verified against the real checkpoint on gfx1151 with ROCm torch: architecture
detected as moonshine_streaming, LoRA at 327,680 of 140,644,025 parameters
(0.23%), batches collated to a frame-aligned length with an attention mask,
and training running on the GPU.

Note the medium model Lemonade serves, moonshine-ai/moonshine-streaming, ships
as ONNX graphs only and cannot be fine-tuned. moonshine-streaming-small is the
transformers checkpoint.
They build a real Wav2Vec2FeatureExtractor, so they need torch and
transformers. CI installs only the dev extra, where they failed with
ModuleNotFoundError.
@Rebreda
Rebreda merged commit cb0593f into main Aug 26, 2026
6 checks passed
@Rebreda
Rebreda deleted the feat/moonshine-streaming branch August 26, 2026 04:27
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.

1 participant