ajh-code/Qwen3.8-27B-Escha-W2-16GB-120Kctx-KVarN
<h1 align="center">Qwen3.8-27B Escha W2 · 16 GB · 120K Context · KVarN</h1>
<p align="center"><strong>Run the complete 27B Escha W2 model at up to 120K context on a single 16 GB NVIDIA GPU using a real packed KVarN K4/V4 cache.</strong></p>
<p align="center"><strong>No scored quality loss was observed in the current matched 45-point KV-cache suite; packed-attention numerical similarity is above 0.999999.</strong></p>
<p align="center"> <a href="https://huggingface.co/EschaLabs/Qwen3.8-27B-Escha-W2">Original Escha model</a> · <a href="https://huggingface.co/EschaLabs/escha-runtime-qwen3dense">Escha SGLang runtime</a> · <a href="https://github.com/huawei-csl/KVarN">KVarN</a> · <a href="https://arxiv.org/abs/2606.03458">KVarN paper</a> </p>
Download
This repository intentionally does not duplicate Escha Labs' weights or compiled wheel. The root config.json is a Hugging Face model query file, and the recommended whole-repository download fetches it. This allows Hugging Face to track this package's downloads independently from the upstream model and runtime.
Versioning begins with v1.0 experimental. The implementation works; the hardware matrix and workload-quality matrix will continue to grow.
Quick start
Requirements: Linux x86-64, Python 3.12, CUDA 12.x, a working C compiler and Python development headers, and an NVIDIA sm_80–sm_120 GPU. The default 120K profile requires a 16 GB-class card and about 30 GB free disk space.
hf download ajh-code/Qwen3.8-27B-Escha-W2-16GB-120Kctx-KVarN \
--local-dir qwen38-kvarn
cd qwen38-kvarn
chmod +x setup.sh serve.sh preflight.sh validate.sh
./setup.sh
./validate.sh
CUDA_VISIBLE_DEVICES=0 ./serve.shNothing is installed system-wide. setup.sh creates .venv locally, installs Torch 2.9/cu128 and the pinned Escha runtime, then downloads the pinned model.
The OpenAI-compatible endpoint defaults to http://127.0.0.1:30000/v1, with served model id escha-qwen38-27b-w2-kvarn.
curl http://127.0.0.1:30000/v1/modelsLAN serving must be enabled deliberately and should use authentication:
HOST=0.0.0.0 API_KEY='replace-me' CUDA_VISIBLE_DEVICES=0 ./serve.shDo not expose an unauthenticated raw inference endpoint to the internet.
What KVarN changes
The Escha checkpoint already compresses the weights to about 10.15 GB. This project independently compresses the growing full-attention KV cache.
For this model's 16 full-attention layers, four KV heads, and 256-dimensional heads:
Completed 128-token history tiles use tight K4/V4 records. The first 128 tokens, unfinished live tile, and bounded generated tail remain FP16. Chunked prefill reuses one FP16 layer workspace rather than allocating a full FP16 cache.
Decode uses fused Triton split-K attention that reads packed K/V directly. Batch-one CUDA graphs keep the first 512 generated tokens in an exact FP16 tail. Outputs longer than 512 tokens automatically fold that tail into KVarN and continue safely in eager mode.
Measured performance
RTX 5080 16 GB
Matched single-stream runs use the same Escha W2 checkpoint, INT8-as-stored LM head, Triton attention, one request, no radix cache, and exactly 256 generated tokens:
CUDA graphs recover the fixed launch overhead: v1.0 retains 96% of stock graph decode speed at 2K and 87% at 16K. The remaining long-context gap is the real packed-attention work. Prefill remains about 7% behind the matched stock run because completed chunks must be transformed and packed.
RTX 5060 Ti 16 GB
The packaged release—not the development launcher—also completed model load, KVarN allocation, CUDA-graph capture, fused decode, and generation on an RTX 5060 Ti. A short 2K/16-token check measured 30.06 tok/s. This is a functional portability check, not a complete performance characterization.
Long-context and lifecycle testing
The release therefore defaults to 4,096-token chunks, a 120,000 total sequence limit, and a 120,512-slot physical pool. The sequence limit includes generated tokens; applications must reserve output space inside 120K.
KV-cache quality comparison
The matched quality suite used the same W2 checkpoint, one RTX 5080, INT8 output head, Triton attention, one request, radix disabled, temperature 0, and seed 20260824. KVarN used the real g128 K4/V4 codec mathematics. The proxy was used for the broad paired suite so every cache arm could be compared under the same stock attention implementation; the separately tested packed fused path is covered by the numerical gates below.
No scored FP16 pass became a KVarN failure. All three formats retrieved twelve values distributed across a 12K prompt exactly. Each arm was repeated and reproduced all seven outputs and captured token log probabilities exactly, so the cross-format comparisons were not sampling noise in this setup.
The equal 26/45 result means no measured score loss in this suite, not universal proof that KVarN is quality-neutral. The model itself missed the same arithmetic, code-tracing, and sorting items under FP16. These thinking-off results must also not be compared directly to Escha's thinking-on public benchmarks.
Where text trajectories differed, KVarN was closer to FP16 than FP8 in the small comparison:
Packed-kernel numerical validation
./validate.sh runs the codec, packed decode, exact graph-tail merge, and causal prefill comparison on the selected GPU:
These tests cover packed nibble extraction, K/V metadata, Hadamard rotation, KVarN normalization, grouped-query head mapping, split-K online softmax, log-sum-exp partition merging, dynamic graph-tail length, and causal masking.
Validated scope
Compatibility and limits
- Intended GPU range: NVIDIA Ampere, Ada, Hopper, and Blackwell (
sm_80throughsm_120), matching the compiled Escha runtime. - Not supported: pre-Ampere cards, non-NVIDIA GPUs, Python other than 3.12, CUDA 11, or native Windows serving.
- Only one active request is supported. Batching and prefix/radix caching are refused rather than silently producing incorrect state.
- The cache layout is specific to this model: 16 full-attention layers, four KV heads, head dimension 256, and 128-token groups.
- Only RTX 5080 has completed the full near-limit and reuse stress suite. RTX 5060 Ti has completed packaged launch and short-generation validation.
- Direct packed prefill is included for research but remains off by default: it measured much slower than materialize-then-Triton on the RTX 5080.
- This is a monkey patch against a pinned Escha SGLang fork. New upstream runtime versions must be revalidated before changing the pinned revision.
Useful overrides:
# Another physical GPU
CUDA_VISIBLE_DEVICES=2 ./serve.sh
# Smaller context profile
CTXLEN=65536 MAXTOKENS=66048 ./serve.sh
# Eager debug path
GRAPHS=0 ./serve.sh
# Ampere single-stream users should A/B the alternate Escha route
ESCHA_ROUTE=blackwell ./serve.shReproducibility
setup.sh pins:
- Model revision:
a7329bde673acf42826f17bf525154e633006cbd - Runtime revision:
36bb7bf5faebd4dbe636628ccd087ad5ecf6d0ac - Python 3.12, Torch 2.9.x, CUDA 12.8 wheel index
Override MODEL_REVISION or RUNTIME_REVISION only when intentionally testing a newer upstream release.
Validate the download
Before installing dependencies, verify every distributed file:
python3 validate_release.pyMANIFEST.json records the size and SHA-256 of every release file except itself. After setup, run the GPU and numerical suite:
./validate.shLicense and attribution
This integration is released under Apache-2.0. The KVarN codec equations, record layout, and fused-attention structure derive from Huawei CSL's Apache-2.0 KVarN implementation. The original Escha model and compiled runtime are downloaded from Escha Labs and retain their upstream licenses and third-party notices. See `NOTICE.md`.
