Skip to content

fix(sglang): use storage dtype for FP8 KV pools - #388

Open
shipiyouniao wants to merge 1 commit into
ovg-project:mainfrom
shipiyouniao:fix/sglang-fp8-storage-dtype
Open

fix(sglang): use storage dtype for FP8 KV pools#388
shipiyouniao wants to merge 1 commit into
ovg-project:mainfrom
shipiyouniao:fix/sglang-fp8-storage-dtype

Conversation

@shipiyouniao

Copy link
Copy Markdown
Contributor

Summary

Closes #387.

Use SGLang's physical KV-cache store_dtype consistently when kvcached constructs MHA and MLA backing pools.

Root cause

SGLang separates the model-facing logical dtype from the physical store_dtype. FP8 KV storage can therefore use one-byte physical elements while the logical dtype remains wider. The kvcached patches used the logical dtype for tensor allocation, page cell geometry, and physical byte accounting, allowing the allocator contract and the actual storage layout to disagree.

Changes

  • allocate MHA and MLA backing KV tensors with self.store_dtype
  • derive MHA and MLA allocator cell sizes from store_dtype.itemsize
  • report physical MHA and MLA bytes using store_dtype.itemsize
  • add focused regression tests where logical and storage dtypes intentionally differ

The logical self.dtype remains unchanged for model-facing behavior.

Validation

  • python -m pytest tests/test_sglang_storage_dtype.py -q -> 2 passed
  • complete pre-commit run --all-files under Python 3.11 -> all hooks passed
  • manual mypy matrix under Python 3.9, 3.10, 3.11, 3.12, and 3.13 -> all passed
  • CI containers used standard runc with GPU devices explicitly hidden

This is independent from vLLM hybrid mapping and scheduler policy.

Copilot AI review requested due to automatic review settings July 16, 2026 10:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a dtype/layout mismatch in the SGLang integration by consistently using SGLang’s physical KV-cache store_dtype (instead of the logical dtype) when kvcached allocates and accounts for MHA/MLA KV backing buffers—important for FP8 storage where physical element width differs from the logical dtype.

Changes:

  • Update SGLang MHA/MLA pool patches to size allocator cells and physical byte accounting using store_dtype.itemsize.
  • Allocate MHA/MLA backing KV buffers using store_dtype.
  • Add regression tests covering the case where logical and storage dtypes intentionally differ.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
kvcached/integration/sglang/patches.py Switches MHA/MLA physical allocation + sizing/accounting to store_dtype semantics.
tests/test_sglang_storage_dtype.py Adds targeted regression tests for logical-vs-storage dtype divergence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread kvcached/integration/sglang/patches.py
Comment thread kvcached/integration/sglang/patches.py
Comment thread kvcached/integration/sglang/patches.py
Comment thread tests/test_sglang_storage_dtype.py
@shipiyouniao
shipiyouniao force-pushed the fix/sglang-fp8-storage-dtype branch 2 times, most recently from 5d5c8e1 to 358288b Compare July 16, 2026 11:05
@shipiyouniao
shipiyouniao requested a review from Copilot July 16, 2026 11:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread kvcached/integration/sglang/patches.py
@shipiyouniao
shipiyouniao force-pushed the fix/sglang-fp8-storage-dtype branch from 358288b to 6936972 Compare July 16, 2026 11:31
@shipiyouniao
shipiyouniao force-pushed the fix/sglang-fp8-storage-dtype branch from 6936972 to 0f8d3d5 Compare July 22, 2026 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SGLang FP8 KV cache uses logical dtype for physical storage

2 participants