Skip to content

[Bugfix][CPU] Reject unsupported --kv-cache-dtype at CPU attention backend selection - #62665

Merged
bigPYJ1151 merged 7 commits into
vllm-project:mainfrom
patrk:fix/cpu-kv-cache-dtype-validation
Oct 22, 2026
Merged

bigPYJ1151 merged 7 commits into
vllm-project:mainfrom
patrk:fix/cpu-kv-cache-dtype-validation

Conversation

@patrk

@patrk patrk commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Fixes #62664. The CPU platform now rejects --kv-cache-dtype values its attention backends can't handle, at backend selection instead of silently accepting them.

Claims

  • turboquant_*, ultraquant_4bit, nvfp4 and int8_per_token_head on CPU fail at startup with a clear ValueError. Before this, turboquant/ultraquant ran and produced garbage (see the issue).
  • fp8* is accepted only on hosts with AVX-512 or AMX, the same rule the kernel already enforces after weight loading.
  • The MLA path on CPU accepts only unquantized dtypes.
  • auto, bfloat16 and float16 are unchanged.

Validation

macOS arm64 (Apple M4 Pro), CPU source build, on main @ e4a676c.

Check main this PR
pytest tests/kernels/attention/test_cpu_attn.py -k "kv_cache_dtype_validation or rejects_quantized" 6 failed, 5 passed 11 passed
test_cpu_attn.py, tests/platforms/test_cpu.py, test_attention_selector.py, tests/config/test_kv_cache_dtype.py 912 passed, 0 failed (x86-only cases skipped)
pre-commit run --files <changed files> passed
LLM("Qwen/Qwen2.5-0.5B-Instruct", kv_cache_dtype=...) auto OK; turboquant_k8v4 garbage; fp8 fails after weight load auto OK ("Paris"); turboquant_k8v4, ultraquant_4bit, fp8 raise ValueError before weight load

I could not run on x86. The AVX-512 path, where fp8 is accepted, is covered by the test through a monkeypatched ISA check.

Update: @adenzhou1350 independently tested this on Linux x86 with AVX-512 (no AMX): the 11 tests pass, the parent commit fails 6, and turboquant_k8v4 is rejected before weight loading (see their comment).

Details

  • Root cause: unlike CUDA/ROCm/XPU, CpuPlatform.get_attn_backend_cls never checked the backend's supported KV cache dtypes, so CPUAttentionBackend.supported_kv_cache_dtypes was never enforced. The CPU kernel treats any dtype other than fp8 as auto, so the unsupported formats got bf16 writes into a uint8 cache.
  • I override supports_kv_cache_dtype instead of calling the full validate_configuration. The full check also validates head size and block size, which would change behaviour for models that work today.
  • Custom dtypes registered through [Quantizaiton][Feature] Pluggable KV Cache Data Types #52670 are rejected on CPU until the CPU backend declares support for them.
  • Compatible with [CPU] UltraQuant 4-bit KV cache on CPU #61168: its ultraquant_4bit routing returns before this check, and the test doesn't parametrize ultraquant_4bit.
  • CI: the test is in test_cpu_attn.py (CPU kernel tests job). That job doesn't list vllm/platforms/cpu.py as a dependency. I left the CI config alone.

This PR was written with AI assistance (Claude Code). I reviewed every changed line and ran the checks above myself.


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

…ckend selection

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Patryk Mikulski <7378686+patrk@users.noreply.github.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added cpu Related to CPU backends bug Something isn't working labels Oct 20, 2026
@github-actions

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

PRs do not trigger a full CI run by default. Reviewers with write access and configured trusted contributors can comment /ci run for upstream CI or /amd-ci run for AMD CI only whenever CI signals are needed.

Once the PR is approved or has the ready label, the PR author can also use the corresponding /ci run, /ci retry, and /ci cancel commands, or their /amd-ci variants. New commits do not start upstream CI automatically.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

🚀

@adenzhou1350

Copy link
Copy Markdown
Contributor

Independent Linux x86 check (AVX-512 available, no AMX): your unchanged 11 selector tests pass on 4de643c; the parent e2d2680 fails six. An additional unmocked host-ISA selector check also passes.

With the same three-layer tiny random Llama, the parent accepts turboquant_k8v4; your modules reject it in CpuPlatform before weight loading. The default auto control generates identical token IDs. A two-layer fixture is all boundary layers and selects auto everywhere, so it does not exercise this rejection.

Reproduction and limits: exact cpu.py/cpu_attn.py overlays on the official e68 CPU distribution with Torch 2.14, not a full PR build or FP8 numerical qualification. Shared native-pack control failures are retained there. AI assistance was used.

@patrk

patrk commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for running this on x86! That's the AVX-512 path I couldn't test locally. Good to see the six failures on the parent

@mergify

mergify Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @patrk.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Oct 21, 2026
patrk and others added 3 commits October 21, 2026 10:39
…ype-validation

Signed-off-by: Patryk Mikulski <7378686+patrk@users.noreply.github.com>

# Conflicts:
#	tests/kernels/attention/test_cpu_attn.py
@mergify mergify Bot removed the needs-rebase label Oct 21, 2026

@bigPYJ1151 bigPYJ1151 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM

@bigPYJ1151 bigPYJ1151 added the verified Run pre-commit for new contributors without triggering other tests label Oct 22, 2026
@bigPYJ1151

Copy link
Copy Markdown
Member

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #96601 for commit 4e68a14300c2.

ℹ️ This PR is 75 commits behind upstream main. Merged upstream main into this branch as 4e68a14300c2 before starting CI. Pull the branch before pushing more changes.

@bigPYJ1151
bigPYJ1151 merged commit f9b0a11 into vllm-project:main Oct 22, 2026
153 checks passed
bantianyue pushed a commit to bantianyue/vllm that referenced this pull request Oct 28, 2026
…ckend selection (vllm-project#62665)

Signed-off-by: Patryk Mikulski <7378686+patrk@users.noreply.github.com>
Co-authored-by: Patryk Mikulski <7378686+patrk@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: vllm-agent <claw@inferact.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cpu Related to CPU backends verified Run pre-commit for new contributors without triggering other tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: CPU backend accepts unsupported --kv-cache-dtype and silently produces garbage

4 participants