magpie: §6.3 host-owned-cache decoder_step — ANE-safe + ~40% faster/step#78
Open
Alex-Wengg wants to merge 2 commits into
Open
magpie: §6.3 host-owned-cache decoder_step — ANE-safe + ~40% faster/step#78Alex-Wengg wants to merge 2 commits into
Alex-Wengg wants to merge 2 commits into
Conversation
… 40% faster) Follow-up to SWIFT_PORT_FINDINGS.md's open decoder_step ANE item. Applies the Surgical Inference §6.3 boundary: no in-graph cache mutation, no position-driven mask compares — reads past cache read-only, concatenates current K/V, attends against a host-supplied mask, outputs only the current-step K/V slice; host owns append + mask. Results on M5 Pro (random weights; ANE admission is structural): - torch equivalence to current graph: max |Δlogits| = 9.5e-7 over 8 steps - NEW: 100% ANE (555 ops), CPU_AND_NE p50 6.0ms - OLD: 100% ANE (752 ops), 10.2ms — and the documented M2 ANECCompile -14 does NOT reproduce on M5 Pro (older-compiler-specific) - ~40% faster/step + far smaller cache I/O (current-slice vs full-cache out) Proof-of-concept (no NeMo/gated download); productionizing = port boundary into traceable/convert + Swift host cache/mask + real-weight audio parity.
…he ANE blocker exp_unroll.py reconverts the Trial-4a N=2 AR unroll with the §6.3 decoder to find the real blocker. Result (M5 Pro, random weights): - N=1 fused (decoder + LT sampler): 74% ANE, ~200 ops on CPU (the LT sampling tail: topk/cumsum/argmax/one-hot); CPU_AND_NE fails to bind. - N=2: 71% ANE, same bind failure; CPU-only amortizes to 5.3ms/frame. So §6.3 makes the decoder 100% ANE + 40% faster, but does NOT unblock the unroll — the sampler does. Correct architecture is §6.3 decoder on ANE (6.0ms) + host sampler (1.6ms), unfused. ~2.4x->3.0x RTFx is the ANE ceiling; beating it needs an ANE-friendly sampler or frame-stacking (retraining), neither a reconversion.
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.
Follow-up to the top open item in
models/tts/magpie/SWIFT_PORT_FINDINGS.md("try rank-3 K/V + int32 position to unblock decoder_step on ANE"). Applies the Surgical Inference §6.3 boundary to the autoregressivedecoder_step.The change
The current
decoder_stepdoes two ANE-hostile things per the paper: an in-graph full-cache read-modify-write blend (new_k = kv_k*(1-mask) + k_new*mask) and runtime-position-driven mask compares (positions_range == position), ×12 layers. The §6.3 rewrite (HostCacheDecoderStep):[1,1,H,D];This mirrors the falsification-ladder rung that compiled ANE-clean in the paper: cache reads + current-token update outputs are admissible; the in-graph state write is the cliff.
Results (M5 Pro, coremltools 9.0; random weights — ANE admission is structural)
Equivalence (torch fp32): max |Δlogits| across 8 decode steps = 9.5e-7 → pure restructuring, not a new model.
ANECCompile -14does not reproduce on M5 Pro — the current graph already runs 100% on the ANE here through the full incrementing-position loop. The block was older-compiler-specific.[1,512,12,64]×24 full-cache re-emit the old graph does every step — the ~19 MB cache-outPERF.mdflags). Decode runs 50–200×/utterance, so this is a direct RTFx lever.Scope
Proof-of-concept under
experiments/ane_host_cache/(no NeMo / gated download): proves ANE admission, placement, latency, and torch equivalence — not CoreML fp16 end-to-end parity with real weights or the Swift host-side plumbing. Productionizing = port the boundary intotraceable_decoder_step.py/convert_decoder_step.pywith real weights, move the cache append + mask intoMagpieModelStore.swift, and validate audio parity.Build artifacts + logs gitignored.