[CUDA][Muse-Glimmer] Retained prefixes slow fresh-prompt prefill in the off-graph cell KV cache

Aperta
#25,646 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Gasoonjia ci sta già lavorando.

Dal 24/11/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

Describe the bug

On the CUDA off-graph cell KV cache path, retaining unrelated prefixes slows fresh-prompt prefill as the occupied shared pool grows. With the same four-session configuration, disabling prefix retention improves 6K prefill from 1,544 to 2,304 tokens/s (~49%). Prefix reuse should remain useful without making a fresh prompt scan unrelated retained sequences.

This was reproduced while bringing up a Linux CUDA 13.2 Muse-Glimmer text-only solo package. The main report concerns cache-related prefill overhead. Two related export/performance observations are listed below, with their limits.

Versions and model

  • ExecuTorch: 799098d28233ec11cba62c57a3484d48185f741f
  • PyTorch: 2.15.0+cu132; Python 3.12; CUDA toolkit 13.2 (nvcc V13.2.86); driver 610.43.02
  • GPU: NVIDIA PG509-210, sm80, 108 SMs, 80 GB; maximum SM clock 1,410 MHz; configured power limit 330 W
  • Model: meta-models/Muse-Glimmer-30B-GGUF, revision b44f1072cf75e918a1b82a3a17b45c4389b076e7, file Muse-Glimmer-30B-KQuant-17GB-Q4_K_M.gguf
  • GGUF SHA256: 4cc57c0f51040a226e5a72cc47b7613f7772950e460a665f7083de89f183f60e
  • BF16 activations/KV; all layers on GPU; no DFlash or vision

Export

python -m executorch.examples.models.muse_glimmer.export.export_solo \
  --gguf "$GGUF" --backend cuda --activation-dtype bfloat16 \
  --use-offgraph-kv-cache --max-seq-len 131072 \
  --max-step-tokens 512 --max-cells 131072 --max-kv-seqs 4 \
  --forward-sizes 1,4 --output-dir "$OUT"

The export succeeded in 1,813 seconds and produced a 30,911,232-byte PTE plus a 17,857,004,800-byte aoti_cuda_blob.ptd.

Reproduction

Use the Muse-Glimmer batching worker with the exported PTE, companion PTD and model tokenizer. Keep these flags fixed:

muse_glimmer_batching_worker \
  --backend=cuda --pte="$PTE" --data_path="$PTD" --tokenizer="$TOKENIZER" \
  --max_sessions=4 --max_inflight_requests=4 --max_decode_sequences=4 \
  --max_session_tokens=8191 --prefix_cache_entries=8 \
  --prefix_checkpoint_prompt_end=every

Run a second fresh worker with the same flags except --prefix_cache_entries=0, omitting --prefix_checkpoint_prompt_end=every.

Feed JSONL requests through stdin. For each supplied prompt length 512, 2048, then 6144, perform four sequential requests using distinct session IDs and deterministic random token IDs from [3, 199000). Generate one output token with temperature=0.0 and ignore_eos=true. Wait for the terminal done response, then send close and wait for its acknowledgment before the next request. Exclude the first request at each length as warmup and take the median of the remaining three native prefill_tok_s values. The worker adds BOS, giving measured prompt lengths 513/2049/6145. For example:

{"op":"generate","request_id":1,"session_id":"fresh-1","prompt_segments":[{"ids":[123,456,789]}],"max_new_tokens":1,"temperature":0.0,"ignore_eos":true}
{"op":"close","request_id":2,"session_id":"fresh-1"}

Replace the short illustrative ID list with the full prompt. Seeds used were supplied_length + 1 + trial, where trial is 0–3. Closed sessions release their live state; the cached configuration retains prefix snapshots. Only one benchmark actively used the GPU at a time; a separate package server remained resident and idle.

Measurements

Medians after warmup, tokens/s:

Prompt tokens ExecuTorch, no prefix retention ExecuTorch, eight prefix entries llama.cpp, FP16 KV llama.cpp, BF16 KV
2049 2176 1884 1427 1427
6145 2304 1544 1434 1433

Short 513-token timings varied across configurations/warmups; this diagnosis relies on the 2K/6K results and matched 6K traces.

In a separate matched Nsight Systems capture of three fresh 6K prompts, one output token each:

Configuration Total attention kernel time Share of GPU kernel time Request prefill times
Prefix retention disabled 1069.6 ms 14.0% 2782, 2684, 2683 ms
Eight retained prefix entries 1690.9 ms 20.6% 2775, 3067, 3443 ms

Attention time increases 58.1%. The first request is similar; later distinct retained prefixes increase latency. Profiled timings include profiler overhead and are separate from the unprofiled throughput table.

Suspected mechanism

Revision-pinned source:

  • CellCache::step_for / build_mask: step.read_len = used_end_; the mask is allocated and constructed over query tokens × occupied pool extent.
  • CUDA off-graph KV lowering: passes the shared pool, explicit mask and read length to SDPA.
  • Triton SDPA: traverses KV tiles up to that read length and checks/reduces the mask. Invisible tiles can skip K/V dot products, but checking unrelated tiles still costs work.

A separate CPU perf capture found mask construction at 3.44% self samples; driver/copy paths dominated. This does not establish CPU mask construction alone as the bottleneck.

Could the cell path use compact per-sequence KV indices/masks, or another mechanism that avoids traversing unrelated retained prefixes while preserving shared-prefix reuse? A sequence-layout export is a candidate to compare; no fix has been validated yet.

Related observations

  1. Quantized prefill dispatch: the quantized GEMM family specializes through M=64; 512-token prefill materializes BF16 weights and runs BF16 GEMM. In an uncached 2K trace, matrix multiplies/fusions account for 59.1% of GPU kernel time, dequantization 27.8%, and attention 7.9%. A fused low-bit prefill path is an optimization opportunity, but these results do not establish a regression against llama.cpp: ExecuTorch was faster in the measured comparison.
  2. 128K context versus total cell capacity: this export used both --max-seq-len 131072 and --max-cells 131072. The latter is shared total capacity, not per-session capacity. With four sessions, eight prefix slots and four capture slots, the observed supported per-session context was 8191, including the padding-cell constraint. This was an export configuration mistake rather than evidence that CUDA cannot support 128K. Clearer export/serving guidance for sizing the total cell budget would help; a larger export and its memory budget have not been validated.

Roofline and llama.cpp comparison limits

The largest generated BF16 GEMM (M=512, N=39936, K=6656) has 272.194 GFLOP of arithmetic and a median duration of 1.105337 ms: approximately 246 TFLOP/s, or 79% of nominal dense BF16 peak. Separate under-load clock samples were 1365–1395 MHz, suggesting roughly 80–82% of the clock-adjusted compute ceiling. This is a timing-derived estimate, not hardware-counter roofline verification: Nsight Compute failed because a driver profiling resource was unavailable. High GPU utilization can include avoidable cache traversal.

llama.cpp revision 8345f3339 was built for CUDA 13.2 / sm80 without source changes. Its benchmark used the same GGUF, all layers offloaded, Flash Attention, batch/microbatch 512 and three measured repetitions. Increasing microbatch to 1024/2048 gave only a few percent prefill improvement. Native decode around 6K was approximately 63 tok/s for ExecuTorch versus 50 tok/s for llama.cpp; these native timings exclude HTTP overhead and use different sampling boundaries.

Lingua principale
Python
Stelle
5.2k
Fork
1.3k
Merge medio
1g 7h
PR unite (30g)
644

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pytorch/executorch

Tutte le issue di pytorch/executorch

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.