Repository navigation
qwen4exp : load a row-paired per_layer_token_embd for 256-block table types - #484
Open
danielhanchen wants to merge 3 commits into
Open
danielhanchen wants to merge 3 commits into
danielhanchen wants to merge 3 commits into
Conversation
… types A table quantized with a 256-wide block type (Q2_K..Q6_K, IQ2_XXS..IQ3_S, IQ1_S/M, IQ4_XS) cannot be stored as [128, n_rows]. Store it as [256, n_rows/2] instead, stored row r holding rows 2r and 2r+1, and detect that from the tensor shape. The graph gathers stored row id/2 and then keeps half id%2 with a second get_rows on the F32 result. Tables stored as [128, n_rows] take the same path as before.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This branch has not been deployed
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 qwen4exp n-gram table (
per_layer_token_embd.weight, 128 wide, 160,003,584 rows) can today only be stored in a type whose block size divides 128: Q1_0, Q2_0, Q4_0, Q4_1, Q5_0, Q5_1, Q8_0, IQ4_NL, MXFP4, F16, BF16. Every K-quant and every 256-block IQ type is rejected when the GGUF is parsed, so between IQ4_NL (11.52 GB) and Q2_0 (5.76 GB) there is nothing.This change lets the table be stored row-paired: a tensor of shape
[256, n_rows/2], where stored rowrholds table rows2rand2r+1. Any 256-block type then fits (Q2_K, Q3_K, Q4_K, Q5_K, Q6_K, IQ1_S, IQ1_M, IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS, IQ3_S, IQ4_XS). The layout is detected from the tensor shape, so there is no new GGUF key.What changes
One file,
src/models/qwen4exp.cpp:ne[0] == 2*ple_head_dim, the table is created as[2*ple_head_dim, ceil(n_rows/2)]and the existing row-count check runs on the paired row count.get_rowsgathers stored rowid/2; a secondget_rowson the F32 result (viewed as[ple_head_dim, 2*n]) keeps halfid%2. The extra index tensor is only created for a row-paired table.set_inputfills the second index tensor and halves the row ids (also the ids passed to the row prefetch).A table stored as
[128, n_rows]builds exactly the same graph as before. No ggml kernel changes: the table is gathered on the host (lazy table), and the CPU, CUDA and Metal backends all supportGET_ROWSfor these types already; the half select is an F32get_rows.Files are produced by quantizing pairs of rows as one 256-wide row and writing the tensor as
[256, n_rows/2]; a loader without this change refuses such a file at load time (per_layer_token_embd.weight has 80001792 rows, too few for the PLE head ranges), it never reads it wrongly.Exactness
[256, n_rows/2](same data bytes): per-token KLD dumps byte-identical to the unpaired table on all 12 evaluation sets, and wikitext-2 (580 x 512) dump byte-identical.test-backend-ops -o GET_ROWS -b CUDA0: 239/239 pass, including every K and IQ type.--plegives the same result as the table inside the split (KLD 0, top-1 100%).Unchanged for existing files (b13004 base vs b13004 + this change, B200)
wikitext-2
-c 512 --chunks 40, IQ2_XXS quant:The top-1 figure is the floor of the stored base log-probs: base scored against its own stored logits also gives 99.990%.
Accuracy and size (35B-A3B, table swapped, everything else byte-identical)
Mean KLD over 11 evaluation sets vs the full-precision model, change relative to the same quant with the IQ4_NL table.
Speed
The table is memory-mapped and gathered on the host, so the cost is the CPU dequantize of 16 lookups per token. Single-thread gather cost per lookup (random rows, warm page cache): IQ4_NL 0.44 us, Q4_K 0.37 us, Q3_K 0.66 us, Q2_K 0.58 us, IQ3_S 1.44 us, IQ2_S 1.39 us, IQ2_XXS 1.35 us; that is about 22 us per decoded token for IQ3_S against a decode step of about 7 ms, and the prompt path splits it across threads. On a B200 with the table in page cache, tg128 was 146 to 149 t/s for every table in the same uncontended pass; cold page cache tg128 was 52 to 58 t/s for all tables (one page touched per lookup either way). Prompt throughput comparisons were not stable enough on the shared host to report a difference.
Pin model
The unslothai/llama.cpp prebuilt is an aged upstream ggml-org
b####release plus the pins inscripts/unsloth/pr-set.json, merged in order (git diff3, then pure add/add only). This pin is upstreamb13004(a105b1924) plus this one change, branched frombase/upstream-a105b1924. It touches onlysrc/models/qwen4exp.cpp; the other pin on that file (#240, MTP heads) merges with it cleanly. When upstream absorbs this, the pin is deleted.Not covered
llama-quantizedoes not write row-paired tables yet; this change is the loader side only.