Skip to content

[https://nvbugspro.nvidia.com/bug/6886263] Fix FlashInfer sparse attention packed KV cache support - #2697

Merged
yingguo-trt merged 2 commits into
NVIDIA:mainfrom
yingguo-trt:yiguo/fix-flashinfer-packed-kv-cache
Oct 13, 2026
Merged

yingguo-trt merged 2 commits into
NVIDIA:mainfrom
yingguo-trt:yiguo/fix-flashinfer-packed-kv-cache

Conversation

@yingguo-trt

@yingguo-trt yingguo-trt commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

Fixes FlashInfer skip-softmax calibration and serving with packed KV caches, including the layout used by vLLM 0.30.0 and 0.31.0. The adapter assumed a five-dimensional [blocks, 2, page, heads, dim] cache, but these versions provide [blocks, heads, page, 2 * dim]. As a result, calibration fails during engine warmup with:

ValueError: FlashInfer KV cache must have logical shape [blocks, 2, page, heads, dim]

A shared helper now extracts logical [blocks, page, heads, dim] K/V views for both calibration and serving. Packed caches use transpose(1, 2).split(head_size, dim=-1) without copying the cache; legacy five-dimensional caches retain their existing indexing.

Usage

Use the existing FlashInfer calibration command. <CKPT_COPY> should be a private writable checkpoint copy/view because --update_checkpoint_config updates its config.json; <RULER_DATA_DIR> is the prepared calibration data directory.

python examples/vllm_serve/calibrate_sparse_attn.py "<CKPT_COPY>" \
  --calib_data_dir "<RULER_DATA_DIR>" \
  --calib_samples 64 --calib_max_seqlen 16384 \
  --target_sparse_ratio 0.5 --decode_tokens 32 \
  --max_model_len 32768 --dtype bfloat16 \
  --attention_backend FLASHINFER --tensor_parallel_size 4 \
  --update_checkpoint_config

Testing

Environment: BF16 Llama-3.1-8B-Instruct, 4 H200 GPUs, TP4, FLASHINFER, with 32 decode steps.

Before the fix: Jenkins #4044 reproduced the cache-shape error during engine warmup with vLLM 0.30.0.

With the fix: the FlashInfer calibration-and-serving E2E passed on both versions:

vLLM CI run Result
0.30.0 #4045 1 passed, 0 failed, 0 skipped
0.31.0 #4047 1 passed, 0 failed, 0 skipped

Each run completed prefill/decode calibration, exported and merged the sparse configuration, then loaded the checkpoint in a fresh HTTP server and generated a response. The 0.31.0 artifacts also confirm ModelOptSparseFlashInferImpl during calibration and serving on all 32 attention layers.

Both passing runs used commit 698154ff0d0266270235f98d57246f616e20eeff. The rebased production fix in 92c48f240781dd70af4581f1a059089d4d288c2d has the identical fix patch and an identical plugins/vllm.py file. Commit b052e671b9ec303c4306b9187997656282a9fd6d only extends regression tests; the current head has not been E2E rerun.

Regression coverage: extended two existing FlashInfer adapter tests under tests/gpu_vllm/torch/sparsity/attention_sparsity/, adding one packed-cache variant each to calibration and serving while retaining the legacy variants. Small CPU tensors check K/V values, logical shape, strides, and shared storage at the downstream kernel boundary; the actual adapter/view conversion is used and the downstream kernels remain mocked. No model load or additional E2E matrix is introduced.

Pre-commit and git diff --check passed for the test changes. A limited CPU check of the real cache-view helper with the five test input layouts passed. Full pytest could not collect locally because nvidia-modelopt package metadata is absent; vLLM/Triton are also unavailable. GPU/vLLM CI is pending fork-runner vetting for this head.

The E2E validates the calibration/serving flow; it does not measure actual serving tile skips, accuracy, or performance.

Before your PR is "Ready for review"

Make sure you read and follow Contributor guidelines and your commits are signed (git commit -s -S).

Make sure you read and follow the Security Best Practices.

  • Is this change backward compatible?: ✅ — preserves the legacy five-dimensional cache layout.
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A — no copied code or new dependency.
  • Did you write any new necessary tests?: ✅ — extended two existing calibration/serving adapter tests with packed-cache regression coverage.
  • Did you update Changelog?: ❌ — no changelog entry included.
  • Did you get Claude approval on this PR?: ❌ — not yet obtained.

Additional Information

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility with FlashInfer key/value caches in supported layouts, including packed layouts, during calibration and regular operation. Cache views preserve expected values, strides, and shared storage, helping prevent errors when processing these configurations. Unsupported cache shapes continue to raise an error rather than being handled as valid layouts.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-0.48.0 cherry-pick-done Added by bot once PR is cherry-picked to the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants