Hi AMD Developer Community,
Sharing vramkit — an open-source toolkit that shrinks the two things that eat VRAM during LLM
inference: model weights and the KV-cache. Posting here because long-context inference memory is a
known ROCm pain point, and this is pure PyTorch + numpy, so it drops straight into a ROCm stack.
Every number below comes from a runnable benchmark with a bit-exact roundtrip assertion.
== Weights - lossless, beats zstd ==
A from-scratch 32-bit range coder with a 2-D adaptive context (each 4-bit weight conditioned on its
left+up neighbour - structure zstd/xz can’t see). Across EVERY weight-tensor type of Qwen2.5-0.5B
(q/k/v/o-proj, mlp gate/down): mean 2.92 bits/weight, −27% vs raw 4-bit, lossless, beating zstd-19
on 4 of 5 (best tensor: o_proj at −33%). Sits on the 2-D entropy floor.
== KV-cache — drop-in, device-agnostic ==
from vramkit.kvquant import quantize_kv, dequantize_kv
packed = quantize_kv(key, mode=“outlier-int4”) # ~3.6x smaller than fp16
key_hat = dequantize_kv(packed)
Per-token int8 = 1.97x at cos-sim 0.9998. Naive int4 loses quality on KV’s outlier channels; keeping
just 4 of 128 channels in int8 (“outlier-aware int4”) recovers cos-sim 0.958 → 0.999 at ~int4 memory
(3.66x). Runs on ROCm/CUDA/MPS/CPU since it’s plain PyTorch.
== Why it matters on AMD ==
On ROCm, decode throughput degrades hard past ~64k context and FP8-KV is still maturing. KV-cache
memory is the lever: 2-3.6x smaller KV = more concurrent requests or longer context per Instinct/
Radeon GPU, directly on $/token.
== Honest limits + the ask ==
I built and benchmarked this entirely on an Apple-Silicon MacBook (+ torch CPU). The logic is
ROCm-ready but I have NOT yet benchmarked it on Instinct/Radeon. I’d love to collaborate with anyone
who has MI300X / W7900 time to:
- measure real end-to-end VRAM + throughput at 64k-256k context with KV compression on,
- validate KV quality as perplexity on a real model (via vLLM-ROCm),
- prototype a HIP/Triton dequant kernel so the compressed form is used live in attention.
Question for the room: at long context on ROCm, what’s hurting more right now - KV-cache memory,
attention-backend selection, or FP8 accuracy? That’s where I’d point the next kernel.
Thanks - happy to answer anything.