feat(export): env-gated true-dynamic KV-cache decode graphs (Gemma + Moonshine v2) - #266
Merged
Merged
Conversation
…Moonshine v2) Add opt-in flags that trace the KV-cache seq dim as a real dynamic extent (Dim.DYNAMIC) instead of the fixed/sentinel path, so one compiled vmfb serves every autoregressive decode position: - FunctionGemmaExport: GEMMA_TRUE_DYNAMIC=1 threads Dim.DYNAMIC through the with_past trace and skips the SENTINEL_PAST + relaxSeqDimToDynamic text-hack (which never actually iree-compiled). Default export path unchanged. - MoonshineV2DecoderBakeTest: MOONSHINE_V2_TRUE_DYNAMIC=1 traces both the self-cache seq dim (grows per step) and the cross-cache frames dim (varies per utterance) as Dim.DYNAMIC. Both env-gated and off by default. Requires the core dynamic-shape capability (sk.ainet.core Dim + dynamic-safe tracer/emitter, PR SKaiNET#891) — build with -PuseLocalSkainet=true until that lands in a release. Verified: both graphs self-compile to dynamic vmfbs, and Moonshine v2 growing-cache decode matches onnxruntime cos=1.0 at every step. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…blished) 0.38.0 (cut from develop, on Maven Central) carries the SKaiNET#891 dynamic-shape core (Dim + dynamic tracer/emitter). Lets the true-dynamic decode graphs + Gemma GEMMA_TRUE_DYNAMIC export build against published core, no -PuseLocalSkainet needed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… for streaming decode Streaming ASR finalizes a variable-length encoder memory, but the decoder prefill is fixed-shape (iree rejects dynamic_reshape for the memory head-split). Fix by zero-padding the cross (encoder) memory to a fixed MAX and masking the padding out of cross-attention, so ONE prefill + ONE with_past vmfb pair serve any encoder length ≤ MAX while the self-cache stays dynamic (growing). - transformer-core MultiHeadAttention: optional trailing `crossMask` on attentionImpl + forwardWithKV, applied as SDPA `mask = slidingMask ?: crossMask`. Default null → byte-identical for all existing callers (verified: llm-core 101 + gemma 77 tests green, incl. MHA/SDPA/sliding-window coverage). - MoonshineDecoder: thread `crossMask` through the layer/model forwardPrefill (via MHA.forwardWithKV) and the hand-wired forwardWithPast (sdpaMerge). Backward compatible (trailing default; v1 positional callers untouched). - MoonshineV2DecoderBakeTest: MOONSHINE_V2_MAX_MEM=N pads both prefill memory and with_past cross cache to N and adds a crossMask input [1,1,1,N] to both graphs. Verified end-to-end: masked decode over memory padded 64→96 (with a garbage tail) == onnxruntime unpadded-64 token-for-token on real audio; control (no mask) corrupts. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…memory-mask feat(moonshine,transformer-core): fixed-max cross-memory padding mask for streaming decode
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.
Adds opt-in flags that trace the KV-cache seq dim as a real dynamic extent (
Dim.DYNAMIC) instead of the fixed/sentinel path, so a single compiled vmfb serves every autoregressive decode position.What
FunctionGemmaExport—GEMMA_TRUE_DYNAMIC=1threadsDim.DYNAMICthrough thewith_pasttrace and skips the oldSENTINEL_PAST+relaxSeqDimToDynamictext-hack (which never actuallyiree-compiled).MoonshineV2DecoderBakeTest—MOONSHINE_V2_TRUE_DYNAMIC=1traces both the self-cache seq dim (grows per step) and the cross-cache frames dim (varies per utterance) asDim.DYNAMIC.Both env-gated and off by default — the existing export paths are unchanged.
Requires
The core dynamic-shape capability (
Dim+ dynamic-safe tracer/emitter, SKaiNET#891, now ondevelop). Until a core release ships it, build with-PuseLocalSkainet=true.Verification
Both graphs self-compile to dynamic vmfbs; Moonshine v2 growing-cache decode matches onnxruntime cos = 1.0 at every step.