TriAttention supports SGLang as an inference backend, in parallel with the vLLM path. KV cache compression is installed via scheduler-side monkey-patches, so no upstream SGLang changes are required.
pip install -e . # from the triattention repo root
pip install sglang[all] # or follow SGLang's official install guideLaunch an SGLang server with TriAttention enabled:
# Required: path to precomputed frequency statistics
export TRIATTN_RUNTIME_SPARSE_STATS_PATH=triattention/calibration/qwen3_8b.pt
# KV budget (default: 2048)
export TRIATTN_RUNTIME_KV_BUDGET=2048
python -m triattention.sglang \
--model-path <model_path> \
--dtype bfloat16 \
--context-length 32768 \
--trust-remote-codeThe python -m triattention.sglang entry point wraps SGLang's server launcher. It:
- Sets
ENABLE_TRIATTENTION=1. - Installs scheduler / worker / input-patch hooks in the main process and in every TP child.
- Appends
--disable-radix-cacheif you did not pass it explicitly (radix cache is incompatible with KV compression). - Forwards all remaining CLI arguments to SGLang.
| Variable | Purpose | Default |
|---|---|---|
TRIATTN_RUNTIME_SPARSE_STATS_PATH |
Path to .pt file with precomputed Q/K frequency statistics |
(required) |
TRIATTN_RUNTIME_KV_BUDGET |
Max KV tokens kept per sequence after compression | 2048 |
TRIATTN_RUNTIME_DIVIDE_LENGTH |
Trigger: compress when kv_len >= kv_budget + divide_length |
512 |
ENABLE_TRIATTENTION |
Master switch (launcher sets this automatically) | 1 |
See Calibration Guide for how to generate the stats file.
If you prefer to call SGLang's launcher yourself, install the hooks before starting the server:
import os
os.environ["ENABLE_TRIATTENTION"] = "1"
os.environ["TRIATTN_RUNTIME_SPARSE_STATS_PATH"] = "triattention/calibration/qwen3_8b.pt"
from triattention.sglang import install_sglang_integration, install_tp_hooks
install_sglang_integration() # main process
install_tp_hooks() # TP child processes
# ... start SGLang server as usual, with --disable-radix-cache ...- Radix cache must be disabled. KV compression rewrites the KV pool in-place; radix cache's content-addressed reuse would hit stale entries.
- Prefix caching is not supported for the same reason.
- Tensor parallelism is supported; stats are automatically sharded per TP rank.