Repository navigation
Conversation
The 27B's attention caches can hold int8 rows packed by the new cuda/kernels/kvpack.py: each (position, KV head) row is ExLlamaV3's -cq 8 codes (H32-rotated groups of 32, midpoint grid, Flash Next's quantizer) followed by the groups' fp16 scales, so a cache is still one tensor a layer that grows, slices, copies and clones by position. - Decode windows pack their keys and values before attention, and the shared tree attention dequantizes committed and path rows alike, so a drafted row reads what serial decoding reads after a commit (which is now a byte copy of the accepted rows): drafts equal serial at int8. - Prompts store packed rows and attend over the dequantized prefix, so every key passes through its codes and any chunking keeps its bits. - The query is rotated once into the cache's rotation and the merged output rotated back; int8 plans take 32 (row, head) pairs an item. - The bf16 path is unchanged, byte for byte against 0.6.1. - Admission counts the packed bytes and one layer's dequantized prompt read; two ranks refuse --kv-dtype int8. Co-Authored-By: Claude Opus 5.5 <[email protected]>
8 tasks done
Owner
|
Thank you, @Arminova, for this and for #268, which ships in 0.6.4 today. We're closing this one. TensorFold keeps one rule on every engine: a speed or memory feature can't change the reply, and an int8 cache does, even with the bf16 default left identical. The problem you measured is real. A drafted round at about 100k tokens costs about 145 ms against about 106 ms near the start, because every round reads the whole bf16 cache. A change that cuts those reads while keeping the bf16 output byte-identical would land, and we'd be glad to help with it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The 27B's CUDA engine can now keep its attention caches in int8 with
--kv-dtype int8(one GPU). The default stays bf16, and the bf16 path's output is byte-identical to 0.6.1/0.6.2 (checked on fixed inputs, 1 to 128 rows, up to 90k keys).Why: on a DGX Spark the 27B's decode slows with depth because every round reads the whole bf16 cache (64 KiB a position over the 16 attention layers). Real long agentic sessions here sit at ~100k tokens, where a drafted round costs ~145 ms against ~106 ms at 3k. int8 halves those bytes.
Design
-cq 8(each group of 32 values rotated by a 32-point Hadamard, fp16 absmax scale, midpoint grid). The quantizer is Flash Next's ownkvquant.quant_groups_8/dequant_group_8, so the codes and scales are bit-identical tokvcache.quantize_ref.tensorfold/cuda/kernels/kvpack.py): a (position, KV head) row ishead_dimint8 codes followed byhead_dim/32fp16 scales (272 bytes at head dim 256). A layer's cache is still one tensor indexed by position, sogrow,reserve, commit copies, clones, kept states and the KV room work unchanged.kvpack.unpack, rotated back to the model's basis). Every key, the chunk's own included, passes through its codes, so a resumed prompt equals a fresh one. The CUDA prefill attention kernel is unchanged.kvpack.rotate) and the merged output rotated back in_merge.PACKED_TILE). With 16, a 16-row window over 24 heads dequantizes each key tile six times and int8 gained nothing over bf16 at 16 rows. 64 pairs spilled registers. 32 with Flash Next's reshape dequant was the fastest of the variants measured on GB10.--tp 2refuses--kv-dtype int8.Measured on one DGX Spark (GB10)
Two public checkpoints:
Vontra/Qwen3.8-27B-MLX-4bit, the docs' standard checkpoint;armin1/Qwen3.8-27B-NVFP4-FP8-Mixed-LH, a ModelOpt mixed checkpoint (NVFP4 MLP with the last 8 layers in FP8, FP8 attention/DeltaNet/head), served with--precision full.Both used
z-lab/Qwen3.8-27B-DFlash2and--parallel 3 --thinking --prefill-fp8, with both cache dtypes in the same build (0.6.2 + this branch). Round time = decode seconds over rounds from/health(it separates the cache's cost from acceptance). Prompts are seeded non-repeating log lines plus one 512-token code request, greedy.ms a drafted round:
"draft": false, ms a token: MLX 4-bit 96.4 → 86.5 at 90k and 143.1 → 114.4 at 242k (−10%, −20%); NVFP4/FP8 mixed 118.4 → 108.3 and 164.3 → 136.5 (−9%, −17%). Prompt fill is within 2% of bf16. The startup estimate at the 262,144 window drops from 37.39 to 30.38 GiB (MLX) and from 43.60 to 36.59 GiB (NVFP4/FP8). Short-context decode is unchanged (code / prose tok/s, bf16 vs int8: MLX 78.8 / 50.2 vs 81.2 / 50.1, NVFP4/FP8 mixed 66.5 / 39.4 vs 66.3 / 38.6).Tree attention alone (24 q heads / 4 KV heads, head dim 256, median of 50), ms a layer:
Quality (100 local tasks, greedy, thinking off, 1,024 tokens; needle at 194,893 tokens):
Items change in both directions:
The EXL3 path shares the same forward and cache code but was not run end to end here.
Tests
tests/cuda/test_qwen27_kv_int8.py(22 tests):kvcache.quantize_refbit for bit;unpackandrotateequal the reference H32;tests/test_cuda_cli.pynow expects the 27B to acceptint8. GLM still refuses it, andint4stays refused for the 27B. On one GB10, the attention, prefill-attention, Flash Next kvquant, alltest_qwen27_*, CLI, geometry and KV-room suites pass (415 passed, 20 skipped).Not in this PR
int4for the 27B._sharedwrites and_mergereads back. They cost int8 and bf16 alike, about 0.6 ms a layer at 90k with 16 rows, and are a separate change.