Skip to content

Decode speed of KV-cache LLMs through ExecuTorch: measured gaps in Torch-TensorRT and TensorRT #5078

Open

Description

@shoumikhin

We exported Muse Glimmer 30B (52 layers, grouped-query attention with 32 query heads and 2 KV heads) through ExecuTorch with Torch-TensorRT, and compared it with the ExecuTorch CUDA backend on the same GPUs. The answers match eager PyTorch, but decoding is much slower. This issue lists where the time goes and what would close the gap. The first two Torch-TensorRT items have their own issues with small repros.

Decode, ms per token (about 4K tokens of context)

GPU TensorRT bf16 TensorRT INT4 ExecuTorch CUDA backend (4-bit)
A100 80GB 59.7 108.9 14.7
DGX Spark 220 74
Jetson Thor 601 71

Where the time goes

On the A100, per bf16 decode step: layer matmuls 37 ms, copying the KV cache to all 32 query heads 9.6 ms, attention 5.4 ms, the rest 7 ms. The matmuls run tiles tuned for 512 rows at 1 row. For INT4, a separate kernel turns every INT4 weight into a bf16 copy on each step (39.5 ms), then a bf16 matmul runs on that copy (46.8 ms).

On Jetson Thor, a one-layer INT4 slice takes 13.4 ms per step: matmul 6.2, dequantize to bf16 4.9, KV copy 1.2, attention 1.2.

Gaps in Torch-TensorRT

  1. Input(opt_shape=...) is ignored for exported programs, so decode runs prefill-tuned kernels. With opt 2 instead of 512, the one-layer INT4 slice on Thor goes from 13.4 to 5.4 ms. See 🐛 [Bug] Input(opt_shape=...) is ignored when compiling an ExportedProgram, so decode steps run prefill-sized kernels #5076.
  2. Grouped-query attention copies the KV cache to every query head on each step. Folding query heads into rows removes the copy (2.1x faster in the repro). See ✨[Feature] Grouped-query attention at decode copies the KV cache to every query head on each step #5077.
  3. One engine with a decode profile and a prefill profile, selected per call, is what a KV-cache LLM needs. With a single profile, decode-tuned kernels make 512-token prefill 1.7 to 2.2x slower. A documented path for this through ExecuTorch would help.
  4. CUDA graph replay for engines that update the KV cache in place saves 1 to 3 ms per token (in progress in perf(executorch): replay KV cache engines, cut per-call copies and work #5075).

Items 1 and 2 together, tried on the full model on the A100 by exporting with a 2-token example and folding the heads in the model: INT4 108.7 to 39.1 ms per token, bf16 59.2 to 45.6 ms. bf16 tokens were identical; INT4 had one near-tie token flip. As model-level workarounds they cost prefill speed and about 18 GiB of GPU memory, which is why they belong in Torch-TensorRT.

Open fixes that the numbers above already include: INT4 dequantize in the requested dtype, so it can fuse into the matmul (#5061), and attention with a one-row query ignoring its mask (#5074).

Gaps in TensorRT (for NVIDIA)

  • The INT4 weight-only matmul at 1 token reaches about 15% of memory bandwidth on the A100, even when fused. The CUDA backend's 4-bit kernel reaches about 66%.
  • The decode attention kernel costs about 0.1 ms per layer on the A100 whatever the cache length (measured with 4608 and 16384 slots), and about 1.1 ms per layer on Thor.
  • A static 1-token engine with an in-place KV cache builds but crashes at run time, and builder optimization level 5 fails on the in-place alias check. Both were seen with TensorRT 11.4.

Environment

Torch-TensorRT 2.15 with #5044, #5052, #5061 and #5074, TensorRT 11.4.0.106, PyTorch 2.15, ExecuTorch 1.6. A100 (x86_64), DGX Spark and Jetson Thor (aarch64).

Activity

  1. narendasan commented on Nov 19, 2026

    @narendasan
    Collaborator

    Input(opt_shape=...) is ignored for exported programs, so decode runs prefill-tuned kernels. With opt 2 instead of 512, the one-layer INT4 slice on Thor goes from 13.4 to 5.4 ms. See #5076.

    @apbose didnt you look at this issue?

  2. added this to the v2.16.0 milestone on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions