TorchScript greedy decode step + CUDA GC tuning#10
Merged
Conversation
Greedy decoding on CUDA now runs each token's full decoder forward (all layers' self-attention, cross-attention, FFN, and the final LayerNorm) as one jit_compile'd TorchScript call instead of dozens of dispatched R->torch calls per token. Same motivation as chatterbox's t3_inference_jit: even lean eager R hits a per-op dispatch floor, and collapsing the per-token forward into one libtorch call removes it without compiled code. Token-for-token equivalent to the eager path (test_decode_jit.R); ~2.5x faster end-to-end on medium for a short clip. On by default via the new jit arg to transcribe()/whisper_pipeline(); gated to CUDA greedy non-word-timestamp runs, so CPU/beam/word-timestamp paths and R CMD check are unchanged. Also adds whisper_tune_gc(): opt-in helper raising torch's CUDA allocator GC floor to the model's footprint as a fraction of VRAM, so GC stops firing on nearly every allocation during inference. No-op off CUDA, only-if-unset. Bumps to 0.3.0.1.
This was referenced Jun 17, 2026
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.
Applies the GC and JIT speedups from the recent chatterbox work to whisper.
JIT greedy decode (
R/decode_jit.R)Each generated token's full decoder forward (per layer: self-attention, cross-attention, FFN; plus the final LayerNorm) now runs as one
jit_compile'd TorchScript call. R keeps the eager prefill, the sampling/timestamp logic, and the loop shell.Same motivation as chatterbox's
t3_inference_jit: even optimally-written eager R hits a per-op R->lantern dispatch floor (hundreds of ops/token). Collapsing the per-token forward into one libtorch call removes it without compiled code or linking against torch's private libraries.Whisper's step differs from a Llama step in three ways, all handled: LayerNorm with bias (hand-rolled in float for fp16 parity), biases on every projection, and a cross-attention block whose encoder K/V are cached once and passed in as stacked tensors.
jitarg totranscribe()/whisper_pipeline().GC tuning (
whisper_tune_gc())Opt-in helper that raises torch's CUDA allocator GC floor (
torch.cuda_allocator_reserved_rate) to the model's footprint as a fraction of VRAM and liftstorch.threshold_call_gcoff its default, so GC stops firing on nearly every allocation during inference. Call beforeload_whisper_model(). No-op off CUDA; only sets options that aren't already set.Verification
test_decode_jit.R(CUDA + at_home gated).mediumfor the jfk clip; more on longer transcripts where per-token dispatch dominates. Text identical.Version 0.3.0 -> 0.3.0.1.