Skip to content

fix(moonshine_asr): reject audio beyond the position-embedding limit instead of crashing - #662

Merged
0xShug0 merged 1 commit into
0xShug0:mainfrom
Faazil-jpg:fix/moonshine-asr-long-audio-crash
Sep 23, 2026
Merged

0xShug0 merged 1 commit into
0xShug0:mainfrom
Faazil-jpg:fix/moonshine-asr-long-audio-crash

Conversation

@Faazil-jpg

@Faazil-jpg Faazil-jpg commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #661

Fixes the GGML_ASSERT(i01 >= 0 && i01 < ne01) crash reported in #661 when running moonshine_asr on audio longer than ~82s (16kHz), in both offline and streaming mode.

Root cause: the encoder adds a learned absolute position embedding (model.decoder.pos_emb.weight, a real GGUF weight tensor with a fixed row count of max_position_embeddings = 4096 for the released tiny/small/medium checkpoints) to its per-frame memory output before decoder cross-attention. Nothing validated that the actual number of post-conv encoder memory frames fit within that table before the ggml_get_rows lookup ran, so long-enough audio read out of bounds and hit the GGML assertion instead of a clean error.

This is a genuine fixed-context-length limit of the released checkpoints (the embedding table itself has only 4096 rows) rather than a fixable off-by-one, so this PR turns the crash into an actionable runtime_error raised before the expensive encoder-transformer/decoder work runs, rather than attempting internal auto-chunking (a larger change out of scope here).

Verified:

  • Crash reproduces on unpatched code for 90s+ audio (confirmed by stashing this fix and rebuilding).
  • With the fix, 90s/105s/125s/245s clips now fail cleanly with a descriptive message, e.g.:

    moonshine_asr: input audio is too long for this model. The encoder produced 4500 memory frames, but this checkpoint's decoder position-embedding table only supports 4096 frames (approximately 82s of audio for this model). Please split the input into shorter segments (around 82s or less each) and transcribe them separately.

  • 75s audio (below the limit) is unaffected, in both offline and streaming mode — no regression.
  • Frame counts in the error message are internally consistent with the real downsample math (4500 / 6236 / 12252 / 5252 frames for the four longer test files respectively).

No existing test in tests/ references moonshine_asr, so none needed updating.

@0xShug0

0xShug0 commented Sep 23, 2026

Copy link
Copy Markdown
Owner

@Faazil-jpg I don't think this is the right solution. I forgot to wire the audio chunker into the model, so for tiny it will fail about 81.9 seconds. I will update this PR directly.

@0xShug0
0xShug0 force-pushed the fix/moonshine-asr-long-audio-crash branch from f4919f5 to b2ed457 Compare September 23, 2026 08:51
@0xShug0
0xShug0 force-pushed the fix/moonshine-asr-long-audio-crash branch from b2ed457 to 75bc55e Compare September 23, 2026 08:52
@Faazil-jpg

Copy link
Copy Markdown
Contributor Author

Thanks for the context — makes sense. I dug into it after your comment: I can see Canary's session.cpp already uses engine::audio::plan_audio_chunks()/AudioChunkMode to split long input before hitting the encoder, and Moonshine's streaming-chunk path is a different thing entirely (incremental input buffering, not pre-encoder splitting), so that's exactly the gap. Happy to take a pass at wiring it in the same way Canary does if that's useful, or I'll leave it to you since you're already on it — whichever's less friction for you.

@0xShug0
0xShug0 merged commit ab26890 into 0xShug0:main Sep 23, 2026
6 checks passed
@0xShug0

0xShug0 commented Sep 23, 2026

Copy link
Copy Markdown
Owner

@Faazil-jpg It should work now.

@0xShug0

0xShug0 commented Sep 23, 2026

Copy link
Copy Markdown
Owner

@Faazil-jpg Thanks for offering to help! Sorry, I missed your message earlier.

I also added a more explict error message. The Silero VAD model currently used by the chunker requires 16 kHz audio. For 48 kHz or other sample rates, VAD cannot be used, and a different chunking mode should be selected.

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.

moonshine_asr crashes with GGML_ASSERT(i01 >= 0 && i01 < ne01) on audio longer than ~75-90s (offline and streaming mode)

2 participants