Repository navigation
Parakeet-TDT NPU acceleration on the Apple Neural Engine - #729
Merged
Merged
Conversation
Export a fixed-shape Parakeet-TDT Conformer audio encoder the Apple Neural Engine can compile: replace the relative-position torch.gather with a static Transformer-XL rel-shift over precomputed reversed position keys, registered as a separate npu_module captured at a fixed sequence length via a new npu_example_inputs spec field. No-op the torch.export _assert_tensor_metadata node coremltools cannot translate. Signed-off-by: Noah Cylich <noahcylich@gmail.com>
Record an optional npu_audio_compute_units hint in the bundle manifest and honor it when loading the NPU audio encoder, so the Parakeet encoder runs on the Neural Engine while other audio encoders keep their default. The transpiler writes CPU_AND_NE for parakeet_tdt; only audio longer than one NPU window falls back to the CPU encoder. Signed-off-by: Noah Cylich <noahcylich@gmail.com>
The fixed-shape NPU encoder zero-pads short clips to its window, but the Conformer's global attention had no padding mask, so the padded frames leaked into every real frame across all layers and drifted the transcript. Derive the exact valid frame count from the input and apply it as an additive attention key bias and a depthwise-conv mask, matching the unpadded CPU encoder (cos 0.9997 vs 0.959 before). Signed-off-by: Noah Cylich <noahcylich@gmail.com>
Parakeet-TDT transcribes the 20s sample in 0.2s on the Mac Neural Engine, ~6x faster than the 1.2s CPU fallback; also records the Gemma4 text/vision and Galaxy S26 numbers. Signed-off-by: Noah Cylich <noahcylich@gmail.com>
ncylich
force-pushed
the
parakeet-npu-ane
branch
from
June 16, 2026 08:13
10ad94c to
30c229f
Compare
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.
Benchmarks
Records the Mac M4 Pro and Galaxy S26 README numbers (consolidates #725), with Parakeet-TDT now transcribing on the Apple Neural Engine on Mac.
On the M4 Pro the Parakeet 20s clip drops from ~1.2s (CPU encoder) to ~0.2s on the Neural Engine — ~6× faster — with the CPU path unchanged and the transcript matching CPU.
Parakeet NPU acceleration
Adds Apple Neural Engine (ANE) acceleration for the Parakeet-TDT audio encoder.
ANE-friendly encoder export. The Conformer relative-position attention used a
torch.gather(plus a runtimereverse) that the ANE compiler rejects. It's replaced with a static Transformer-XL rel-shift over precomputed, reversed position keys — numerically identical to the gather — captured at a fixed sequence length as a separatenpu_module. A newnpu_example_inputsspec field lets the NPU export shape be set independently of the CPU graph. Thetorch.export_assert_tensor_metadatanode, which coremltools can't translate, is registered as a no-op.Padding mask (transcript fix). The encoder exports at a fixed window and the engine zero-pads shorter clips, but the Conformer's global attention had no padding mask, so the padded frames leaked into every real frame across all layers and drifted the transcript. The ANE encoder now derives the exact valid-frame count from the input (real mel frames are non-zero, padding is exact zero) and applies it as an additive attention key bias plus a depthwise-conv mask, matching the unpadded CPU encoder (cos 0.9997 vs 0.959 before). What previously looked like fp16 "drift" was unmasked padding — not precision or quantization.
Compute-units routing. The bundle manifest records the audio encoder's CoreML compute units (
npu_audio_compute_units), threaded through to the encoder loader and honored when resolving compute units. The transpiler writesCPU_AND_NEforparakeet_tdt; the default is empty, so other encoders are unaffected. Audio longer than one NPU window falls back to the CPU encoder to preserve global attention.Notes.
MILCompilerForANE … ANECCompile() FAILEDlog line is emitted but is non-fatal: one sub-region falls back while the bulk runs on the ANE. Cold ANE compilation of the 24-layer Conformer is slow and variable (Apple-compiler-side, independent of the mask); it is cached as.mlmodelcafter the first load.