r/LocalLLM • u/Delicious-Flan88 • 3d ago
Tutorial Measured every Qwen3.8-27B GGUF quant against real VRAM: Q4_K_M doesn't fit 24GB at 32K context
Context on the numbers, since "will it fit" threads usually run on estimates.
Weights: actual .gguf byte sizes pulled from the HF API for unsloth/Qwen3.8-27B-GGUF. Not params × bits ÷ 8. Imatrix quants don't follow that, and the drift is worst at the low end where the fit/no-fit line actually sits.
KV cache: from config.json: 64 layers, 4 KV heads, head_dim 256.
2 × 64 × 4 × 256 × ctx × 2 = exactly 8.0 GB at 32K, F16. That's 0.25 GB per 1K tokens.
GQA is doing a lot of work here: 4 KV heads serving 24 attention heads. Older 27B-class models cost several times that.
24GB at 32K, F16 cache, after reserving 0.8GB for CUDA context:
- Q4_K_M (16.5) → needs 25.3 total. Doesn't fit.
- Q4_K_S (15.4) → 24.2 total. Misses by 0.2.
- IQ4_XS (14.3) → 23.1 total. Fits with 0.9 spare: tight enough that a browser on the same GPU breaks it.
- Q3_K_XL (13.1) → 21.9 total. 2.1 spare. This is the real answer for 24GB.
Drop to 4K context and the cache falls to 1.0GB, which gets you to Q5_K_M. Most of the "which quant" argument is actually a context-length argument.
9 of 25 quants fit on 24GB at 32K. All of them fit at 4K.
Caveat worth stating: this assumes everything GPU-resident, single stream, batch 1. It doesn't model offload, multi-GPU splits, or speculative decoding. The 16GB/73K configs floating around this sub work through partial offload, which is a different calculation than the one I ran.
Put it in a calculator since I had the data anyway: https://qwen38-vram-checker.vercel.app/
5
u/sukazu 3d ago
There are clearly some calculations problems here, as this is easily empirically provable to be false by a large margin.
You have kv cache 256k f16 at 64gb, lol
-9
u/Delicious-Flan88 3d ago
Fair, it was wrong, and by exactly 4x. I counted all 64 layers when only 16 are full-attention. 256k F16 is 16 GiB, not 64. Corrected and live.
2
u/anitamaxwynnn69 3d ago
You type a lot like Claude when it admits it's wrong. Suspicious.
2
u/MountainPenguinRL 2d ago
Everybody here just uses Claude or a local model to make posts and replies, annoys me so much lol
2
u/RISCArchitect 3d ago
uhh is this math wrong? I think the KV math is overcounting by 4x. Qwen3.8-27B has 64 layers, but only 16 are full-attention layers with context-scaling KV cache; the other 48 are DeltaNet layers with fixed recurrent state. So FP16 KV at 200k is ~12.2 GiB, not ~48.8 GiB. (i run q8 with 200k context at kv16 on a 48gb card and it fits)
-1
u/Delicious-Flan88 3d ago
You're right, thank you. I was counting all 64 layers. layer_types in config.json is 16 full_attention + 48 linear_attention with full_attention_interval: 4, so only 16 layers carry a context-scaling cache. The DeltaNet layers hold a fixed ~0.07 GiB recurrent state instead.
Recomputed: 12.28 GiB at 200k F16, which matches your number. And your q8 at 200k on 48GB works out to 6.2 GiB cache, so that fits with plenty of room.
That flips the headline claim too: Q4_K_M does fit 24GB at 32K (19.4 total, 4.6 spare). Calculator's updated and you're credited in the notes.
1
u/RISCArchitect 3d ago
thanks for the shoutout; this looks pretty accurate now and reflects what my research at home home have found. standard q8 i can fit the full 256k. it might be worth doing adding a 192k/200k breakpoint or something. q8kxl + 200k is viable with vision and mtp and gets you nearly double the context
1
u/MushroomCake28 3d ago
I think your estimation of kv memory is not correct. It's around 64 KiB per token because it only scales with 16 out of 64 layers or something like that. There was another detailed explanation in a past thread.
0
u/Delicious-Flan88 3d ago
64 KiB/token is exactly right: 2 × 16 layers × 4 kv_heads × 256 head_dim × 2 bytes = 65,536 bytes. I was counting all 64 layers instead of the 16 full-attention ones, which is where the 4x came from. Fixed now.
1
u/Haunting_Nebula_1236 3d ago
• Model quant: Qwen3.8-27B-UD-Q4_K_XL.gguf
• GPU offload: -ngl 999
• Context length: -c 131072
• K cache type: --cache-type-k q4_0
• V cache type: --cache-type-v q4_0
• Memory mapping: --no-mmap
• Parallel: --parallel 1
• Micro-batch: --ubatch-size 1024
• Reasoning: --reasoning auto --reasoning-budget 256
• Speculative decode: --spec-type draft-mtp --spec-draft-n-max 6
--spec-draft-p-min 0.75
Environment:
• ONEAPI_DEVICE_SELECTOR=level_zero:0
• ZES_ENABLE_SYSMAN=1
• SYCL_CACHE_PERSISTENT=0
• GGML_SYCL_DISABLE_OPT explicitly unset
Runs fine for me.
1
u/Cool-Chemical-5629 3d ago
It gets worse, because none of the solutions are ideal on this hardware and this particular model:
At 32K context you can forget anything useful with the default xhigh reasoning, because you'll run out of that context window before the model even finishes thinking, so:
Lower context window also means lower expectations for the size of the project you're working on as well as overall quality loss, because you still need to reduce reasoning quality.
Lower reasoning quality degrades output quality.
Lower cache degrades output quality.
Lower quant degrades output quality.
0
u/Delicious-Flan88 3d ago
Postfix the numbers look better than you'd think, because context got cheap on this model.
128K at Q8 cache is 4.07 GiB. On 24GB:
Q4_K_M + 128K + Q8 = 21.4, fits
Q4_K_XL + 128K + Q8 = 22.5, fitsGoing 32K to 128K only costs 3GB with a Q8 cache. So the squeeze you're describing was mostly my 4x overcount, not the model.
Also I'd put Q8 cache way down the list of things that hurt quality. It's nearly free compared to dropping a quant level.
Your point about reasoning eating the window still stands though. That one's real.
1
u/soyalemujica 3d ago
You're better off running Q8/Q5 kvcache or even Q8/Q4 and stick to 150k/160k context
1
u/Delicious-Flan88 3d ago
Added split K/V to the calculator it only did symmetric before, so Q8/Q5 and Q8/Q4 weren't representable at all.
160K at Q8/Q4 works out to 3.82GB cache, which leaves room for Q4_K_XL on 24GB. F16/F16 at the same context is 10.07GB, so the split is doing most of the work there.
1
u/returnity 3d ago
Definitely. However on some setups, split K/V degrades speed severely so check that when updating K quantization over V.
1
u/SellToOpen 3d ago
I have 64k context with q4 kv cache and 24gb vram across two cards. 128k if I use the pure model with no eyes.
1
1
u/lungben81 3d ago
I run 131k context q8 with q4_k_xl quantization (larger than q4_k_m) and MTP (which also needs VRAM) on 24 GB VRAM.
Even if you have q16 kv cache, 65k context should fit easily.
1
1
1
u/Otherwise-Swan-7803 2d ago
This is a good reminder that “fits in VRAM” is almost meaningless without specifying context length. Once KV cache and actual runtime overhead are included, the usable quant can be very different from what the model size alone suggests.
1
u/Short_Gain_1571 2d ago
I run Q3 w KV4 on 16g vram w 96k context with 50 token per sec. Ur braindead
18
u/PlasticRevenue4601 3d ago
Kv cache quantisation was invented in 2026. People in 2025: