Skip to content

moonshine v2: per-layer attention bands and split encoder/decoder widths - #445

Merged
michalharakal merged 1 commit into
developfrom
feature/moonshine-v2-per-layer-windows
Sep 21, 2026
Merged

michalharakal merged 1 commit into
developfrom
feature/moonshine-v2-per-layer-windows

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

Summary

Two additions to the Moonshine v2 streaming model (llm-inference/moonshine), both with defaults that keep the English tiny checkpoint and its exported graphs unchanged.

Per-layer attention bands. MoonshineV2Config.slidingWindows takes explicit (left, right) context per encoder layer, in the HF encoder_config.sliding_windows convention. The German tiny streaming checkpoint uses [[17,5],[17,5],[17,1],[17,1],[17,5],[17,5]]: its middle layers look one frame ahead, which the existing edge-layer rule (lookahead on the first/last N layers, causal in between) cannot express. null keeps today's behaviour. slidingWindowForLayer maps the HF left context to the DSL window (left + 1).

Split encoder/decoder widths. decoderDim / decoderFfnDim let the decoder run at a different width than the encoder (the small checkpoints: 620 / 512). The adapter then carries the bias-free proj bridging the memory into decoder space, the encoder attention takes an explicit head dim when nHeads * headDim != dim, and the frontend takes the stream width as a parameter.

Why

Without the per-layer bands the released module can describe the English checkpoint only; the German one needs them to export correctly.

Tests

  • New MoonshineV2ConfigTest in commonTest (defaults = English tiny, explicit bands override the edge-layer rule, split widths); commonTest gets kotlin-test.
  • Locally: :llm-inference:moonshine:jvmTest 19/19, :llm-inference:moonshine:linuxX64Test 3/3.

Follow-up (not in this PR)

The StableHLO export and weight baking for Moonshine v2 live in jvmTest only, so they cannot be run from the published artifact. A main-source export CLI, like FunctionGemmaExportCli, is the next step.

MoonshineV2Config gains slidingWindows -- explicit (left, right) context per encoder layer in the HF
encoder_config.sliding_windows convention. The German tiny streaming checkpoint uses
[[17,5],[17,5],[17,1],[17,1],[17,5],[17,5]]: its middle layers look one frame ahead, which the
edge-layer rule (lookahead on the first/last N layers, causal in between) cannot express. Null keeps
the English tiny behaviour unchanged.

decoderDim / decoderFfnDim let the decoder run at a different width than the encoder (the small
checkpoints: 620 / 512); the adapter then carries the bias-free proj bridging the memory into decoder
space, the encoder attention takes an explicit head dim when nHeads * headDim != dim, and the frontend
takes the stream width as a parameter. Defaults are the English tiny values, so existing callers and
the exported graphs are unchanged.

Tests: MoonshineV2ConfigTest (common; JVM + linuxX64).
@michalharakal
michalharakal merged commit 1e590a1 into develop Sep 21, 2026
2 checks passed
@michalharakal
michalharakal deleted the feature/moonshine-v2-per-layer-windows branch September 21, 2026 17:31
@michalharakal michalharakal mentioned this pull request Sep 21, 2026
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