Skip to main content

sglang-kvblockd

SGLang HiCache storage backend for KVStash. KVStash becomes SGLang's third cache tier, under GPU and host memory: a restarted SGLang server, or a second one serving the same model, loads prompt KV from the KVStash daemon instead of recomputing it.

Tested with SGLang 0.5.23 (the official lmsysorg/sglang:v0.5.23 image) and 0.5.15.post1, tensor parallel 1.

Install

pip install sglang-kvblockd

Configure

The backend only shares KV between engines that declare the same weights and cache encoding. Generate that identity in the engine's environment, passing the same settings the engine runs with:

python -m sglang_kvblockd.identity Qwen/Qwen2.5-0.5B-Instruct --page-size 64

It prints five fields (model_revision, model_dtype, kv_dtype, cache_layout, model_config_hash) on stdout and, for a hub id, the commit it pinned on stderr. Launch SGLang with that same --revision and put the fields in the storage extra config next to the connection settings:

python -m sglang.launch_server --model-path Qwen/Qwen2.5-0.5B-Instruct --revision COMMIT \
  --page-size 64 \
  --enable-hierarchical-cache --hicache-size 48 \
  --hicache-mem-layout page_first --hicache-io-backend kernel \
  --hicache-storage-backend dynamic \
  --hicache-storage-backend-extra-config '{
    "backend_name": "kvblockd",
    "module_path": "sglang_kvblockd.backend",
    "class_name": "KvblockdHiCacheStorage",
    "interface_v1": 1,
    "endpoint": "kvblockd://STORE_HOST:9440",
    "namespace": "sglang",
    "token": "YOUR_TOKEN",
    "model_revision": "...", "model_dtype": "...", "kv_dtype": "...",
    "cache_layout": "...", "model_config_hash": "..."
  }'

STORE_HOST:9440 is the daemon's data port; keep it on a private network. The namespace and token must match an entry in the daemon's namespaces.yaml.

Cache identity

Pass the identity command every cache-affecting engine setting:

Engine flag Identity flag
--dtype (default auto: follows the checkpoint) --dtype (default auto, resolved the same way)
--kv-cache-dtype --kv-dtype (default: the dtype)
--page-size --page-size (default 64)
--hicache-mem-layout, --hicache-io-backend direct --layout (page_first, page_first_direct, page_head)
--quantization --quantization
--quantization-param-path (KV scales) --quantization-param-path (its contents are hashed)
--json-model-override-args --config-override
  • A Hugging Face model id is pinned to the commit it resolves to now; launch the engine with that --revision. A local directory needs --revision (a commit or a 64-hex weights digest) or --hash-weights, which digests the weight files, unless it is a Hugging Face snapshot directory.
  • Missing or contradictory identity fields stop the backend from starting. They are declarations, not a check of the loaded weight bytes: regenerate them whenever a setting above or the SGLang version changes. A different identity gives different keys, so old pages are never read and simply expire.
  • The backend also folds the host pool's real layout and dtype into its keys when SGLang registers the pool, so pages written in one byte order or 2-byte format are never read as another, whatever was declared. SGLang keeps every fp8 format as uint8 on the host, so for fp8 the declared --kv-dtype is what separates e4m3 from e5m2: a 2-byte declaration over an fp8 pool makes every operation miss, and fp8 pools also bind CUDA vs ROCm. Upgrading from 0.2.0 starts with a cold cache.

Tuning

streams (default 16) sets the connections to the daemon and get_fanout (default min(16, streams), from 1 through streams) how many of them a load uses in parallel. On an L40S with SGLang 0.5.15.post1 and a 110k-token prefix, 4 shards gave 12x faster time to first token than a cold prefill, 16 gave 18.7x and 32 no more. Measure on your own hosts; machines with fewer CPU cores may do better with smaller values.

Size SGLang's host-memory pool (--hicache-size) for your traffic: every page read from KVStash passes through it.

Limits

  • Host layouts page_first, page_first_direct and page_head. Others (e.g. layer_first) log an error and return misses, so SGLang recomputes.
  • Decode context parallel (dcp_size above 1) is refused at start-up.
  • Tensor parallel above 1 is not tested yet.
  • If the daemon is unreachable, requests recompute at normal speed.

Experimental modules

sglang_kvblockd.redknot (RedKnot fork integration) and sglang_kvblockd.dca_readout (Qwen DCA final-prompt readout) are opt-in and not enabled by importing the package. Ask before using them in production: https://kvstash.com/contact/

Metadata

Release files for sglang-kvblockd 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sglang-kvblockd 0.2.1
File Size Uploaded Provenance Actions
sglang_kvblockd-0.2.1.tar.gz 246.6 kB Without provenance Details for sglang_kvblockd-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sglang-kvblockd 0.2.1
File Interpreter ABI Platform Actions
sglang_kvblockd-0.2.1-py3-none-any.whl Python 3 none any Details for sglang_kvblockd-0.2.1-py3-none-any.whl

Total release size: 290.6 kB

Release files / sglang_kvblockd-0.2.1.tar.gz

Download URL sglang_kvblockd-0.2.1.tar.gz
Size 246.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f8ef4d02dcb3cf786290df835108f5d526d45c1d0fab6c23fc0400d8ed54bb89
BLAKE2b-256 checksum
How to use checksums
e8f5b165258cace3246f763e108a03a22f9c204d15cd8ce216195ae1e785eb3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / sglang_kvblockd-0.2.1-py3-none-any.whl

Download URL sglang_kvblockd-0.2.1-py3-none-any.whl
Size 44.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b420014e1499ab1556cf4d61f004468623cd9f83391a9fc7ad0c462214e9d8ac
BLAKE2b-256 checksum
How to use checksums
b2505bb9971ed2559358f448b5ee3678b352f734a94c9b428331b19206b3b6fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for sglang-kvblockd 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page