Repository navigation
core/quant: a GPTQ reader for AutoGPTQ v1 group 128 symmetric weights - #3611
Conversation
|
Thanks @BadAd84. This is a careful first step. The reader is host only and nothing calls it yet, so no served path changes. The dequant is Two small commits of ours sit on top of your head. Neither changes behaviour:
Must fix:
Optional:
Device checks: none. The reader is host only and has no caller, so this PR has no device cell. The device checks will come with step 4 (the int4 kernel).
|
|
Thanks. Both must fixes and both optionals are in Must fix 1, escapes. The new test block Must fix 2, g_idx. The published checkpoint stores no For dtype and shape, the three stored tensors of So the reader already accepts every module of that export, and the refusal of a non-empty Optional, checkpoint_format. It is refused by name unless it is The Optional, desc_act. A value that is not a bool is refused by name, saying what it found, so Description. The body is rewritten on the new head: eight files against the merge base, your two commits named, this commit, the new test and mutant counts, and the g_idx listing above. Checks on
The two commits of yours are untouched. |
36c9885 to
749cd8c
Compare
|
Thanks @BadAd84. Every ask from our last review is resolved at this head:
Our two commits are kept, and the shared helpers come from The red
|
AutoGPTQ v1 stores a 4-bit symmetric weight as qweight int32 [k / 8, n] with eight inputs a word, scales fp16 [k / 128, n], and qzeros int32 [k / 128, n / 8] whose every nibble is 7, so a weight is (nibble - 8) * scale. core/quant/gptq.zig reads that form. The config side admits quant_method gptq with bits 4, group_size 128, sym, no act order and a quantized lm_head, and keeps its dynamic rules in declaration order, so the last rule matching a module decides whether it is stored quantized. A rule is matched with Python's re.match over the subset the rules use: literals, '.', '\x' escapes, '*' and '+' after an atom and a final '$'. A rule outside that subset, an unprefixed rule key and a rule whose own bits or group_size differ are refused by the rule's name rather than guessed at. Anything else stops the load naming the field, the rule or the tensor: bits, group_size, sym, desc_act, lm_head, a missing or malformed dynamic, a qweight, scales or qzeros of another dtype or shape, a qzeros byte other than 0x77 with its offset and value, and a non-empty g_idx, because act order is not read. read returns the three stored tensors as views and reference writes every dequantized weight as binary64: q - 8 is an integer and the scale an fp16 value, so each product is exact. Host only: no family calls it, no kernel reads it and no setting is added, so every checkpoint served today takes the path it took before. The test builds a synthetic GPTQ checkpoint (config.json and a safetensors image packed by the format's own definition) and checks a binary64 fixture of hand-derived values, every refusal by name, the matcher on the rules a real export writes, and the reader on both modules of the checkpoint. Refs ashhart#3368
…nd a non-bool desc_act
A rule's backslash escape was read as the character that followed it, whatever that was,
so ".*layers\.\d+\.mlp.*" matched "layers.d.mlp" here while Python's re matches
"layers.12.mlp" there: a module the rule leaves BF16 could read as int4, or the reverse,
with no error. supported admits an escape only before a non-alphanumeric character, which
is that character itself in Python's re and here, and refuses "\d", "\w", "\s", "\b" and
the rest by the rule's name as "(" and "[" already were.
desc_act went through flag, which answers null for a value that is not a bool, so
"desc_act": "false" was read as false. It is refused by name now, saying what it found in
place of a bool, for the reason sym is.
checkpoint_format was ignored. It is admitted as "gptq" only and refused by name
otherwise, and dialect's doc comment no longer claims every field the reader does not read
is refused.
The tests add the rule above and "\w" and "\s\b" beside it, an escape of a non-alphanumeric
character read as the character, a rule using one admitted, the desc_act refusals, the
checkpoint_format refusals, and checkpoint_format "gptq" on the admitted config.
The published AutoRound export (Qwen3.8-Flash-Next-125B-A5B-INT4-AutoRound, revision
1464274) stores no g_idx tensor: 70 shards, 224454 tensors, none named *.g_idx, so the
refusal of a non-empty one is unchanged.
749cd8c to
fb1678a
Compare
|
Thank you @BadAd84. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
Terms used below: "base" is upstream TensorFold's
mainat077998f7d9b14adebec3a2acc2caa47ff7ae6ec7(its tip of 2026-11-16T15:26:10Z,changelog: #3572 under Unreleased), and "the head" is this pull request's head36c98854f6b53b3bbff741ede301349849539fda. Upstreammainhas moved on since; a merge of it into this head conflicts only inCHANGELOG.md, the branch does not merge it, and every count below is against077998f7d.What this changes
core/quantgains a reader for AutoGPTQ v1 weights as stored: 4-bit symmetric groups of 128, no act order, aqweightof int32 words holding eight inputs each, fp16scales, andqzeroswhose every nibble is 7, so a stored weight is(code - 8) * scale.gptq.admitreads a checkpoint'squantization_configand keeps itsdynamicrules in declaration order, the last rule matching a module deciding whether that module is stored quantized;gptq.readreturns one module's three tensors as views into the checkpoint's map, andgptq.referencewrites every weight as binary64, where each product is exact. A field, rule or tensor whose value the reader does not admit stops the load naming it; a GPTQ field it does not read is ignored. Before,core/quanthad no GPTQ reader:git grep qzeros zig/src/corefound nothing, and XPU's loader read these tensors on its own.077998f7d: the readerd947e03e7, the changelog linecc6bd49c2, two of the maintainer's (fc8402fa3, which makes three JSON helpers public incore/modelopt.zigand reads them from the reader, and3894f6b10, which drops a test-only wrapper the reader no longer needs), and this round's36c98854f. Nothing else is needed to apply it. Step 4 (the int4 kernel) can stack on it, since the reader owns the layout constants that kernel packs.atc overlap --json: run last, on this head, completing 20:23Z (its output's own mtime), exit 0:complete: falsewith its own four limits (otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), 8 changed files, 134 overlaps. 96 of those are sourced from our own pull requests 2044 and 3218, not from a working tree. Of the 38 working-tree overlaps, a three-way merge of this head against each pull request's head produces exactly the conflicts that base alone produces (0 differ): 34 share onlyCHANGELOG.mdwith this change, 3 share no history with base at all, and 1 sharesCHANGELOG.mdandzig/src/core/quant/quant.zigand merges clean. This change adds no conflict to any of them.How the stored form is read:
qweighti32 [k / 8, n],scalesf16 [k / 128, n] andqzerosi32 [k / 128, n / 8], each checked for dtype, shape and whole bytes, each refusal naming the tensor and what it found rather than the number expected alone.qzerosmust be 7, so every zero point the format reads is 8. A byte that is not 0x77 stops the load naming the tensor, the byte's offset and its value.g_idxis refused naming the tensor, because the admitted config'sdesc_actis false, and an emptyg_idxis read and kept out of the way. The published export for this reader,azampatti/Qwen3.8-Flash-Next-125B-A5B-INT4-AutoRoundat revision1464274120d36a4d8fcaa934552334a7d83ce0fd, stores nog_idxat all: 70 shards, 224,454 tensors, none whose name containsg_idx, and 73,729 modules carryingqweight,qzerosandscales: 24,576 each ofmlp.experts.{E}.gate_proj,up_projanddown_proj, pluslm_head(layers.0.mlp.experts.0.gate_projisqweightI32 [320, 640],qzerosI32 [20, 80],scalesF16 [20, 640]).quant_methodgptq in any case,bits4,group_size128,symtrue,desc_actfalse or absent and any other value refused by name saying what it found,checkpoint_formatgptqexactly and any other value refused by name, a quantized head, and adynamicobject of rules. The head counts as stored int4 when thelm_headflag is true or a+:rule forces it, and a-:rule matching it overrides both. Each rule's ownbitsandgroup_size, when it has them, must be the admitted ones. A field it does not read, such asstatic_groupsordamp_percent, is ignored.re.matchover the subset the real rules use, which is literals,., an escape of a non-alphanumeric character,*and+after an atom and a final$. An escape of an alphanumeric character is a class or an anchor in Python's re, so\d,\w,\s,\band the rest are refused by the rule's name rather than read as the letter, which is what makes a Python rule miss here without an error. A rule outside that subset, or a key without a+:or-:prefix, is refused by the rule's name instead of being guessed at, and a checkpoint with nodynamicis refused by that field rather than assumed to quantize everything, because a two-thirds BF16 checkpoint read as quantized would decode to wrong weights silently.zig/src/xpu/load.zig'sprojectionGptq) and the kernel that repacks its tensors (zig/kernels/xpu/qwen27/glue_quant.cl,repack_gptq, which readsQW[w * N + n], source nibble8 * pand8 * p + 4, and computes the biass * (-8.0f * G / ASC), whose -8 is the zero point thatqzerosstores) read the same word layout, the same nibble order, the same fp16[k / 128, n]scales and the same zero point of 8, so this is that format in core. XPU itself is untouched.Formatentry: asfp8.zigandnvfp4.zig, this module is host only, since the kernels that will read these weights are each backend's.core/quant/quant.ziggains one line,core/root.zig's test list gains one so the suite reaches the reader, andzig/build/checkpoint_io_host.ziggains one test-only step.zig/src/xpu/load.zig) is untouched, as you asked: moving it onto this reader is a separate pull request with XPU receipts.Checks on this head
36c98854f6b53b3bbff741ede301349849539fda, signed, author and committerBadAd84 <[email protected]>; its tree is1199951a93ca7a49c4115cddb17f6f416a0981e8, and against base it changes 8 files, 958 insertions and 3 deletions. The commits under it are3894f6b10andfc8402fa3of the maintainer's,cc6bd49c2andd947e03e7of ours.python3 tools/zig/lean_check.py, run once from each tree's own root with that tree's own copy: base 6,575 files, 221 problems; this head 6,577 files, 221 problems;lean_new.py:lean: 221 problems, 221 on the base, 0 new.python3 tools/pr_check.py --base 077998f7d9b14adebec3a2acc2caa47ff7ae6ec7 --pr 3611:merge base 077998f7d9b14adebec3a2acc2caa47ff7ae6ec7; 8 changed files; lean 221 vs 221, 0 new, 0 errors and 0 warnings, so the Unreleased bullet naming core/quant: a GPTQ reader for AutoGPTQ v1 group 128 symmetric weights #3611 is found.git archivetrees of the head and of base, each checked blob by blob against its commit (11,835 and 11,832 blobs, 0 missing, 0 extra, 0 different), natively on an aarch64 Ubuntu 24.04 machine (NVIDIA GB10, 20 CPUs, Zig 0.17.0 from.zig-version,-j8 --maxrss 6000000000except-j4where noted, umask 022, no GPU visible to the tests):test-gptq-reader-host52/52 tests (its test binary52 pass (52 total) 33ms, the step 12 s with its compile),test-environment-host25/25 (25 pass (25 total) 94ms);test-gradient-serving test-qwen-serving-host3/3 on this head and 3/3 on base;compile-config-server7/7 andcompile-cuda-tests10/10 steps foraarch64-linux-gnu;zig fmt --check build.zig zigrc 0 on both trees, andgit diff --checkrc 0 against base.gptq: an escape of an alphanumeric character is refused, as Python's re reads it as a class or an anchor, killed byescape-class; thedesc_actandcheckpoint_formatcases live in the existing refusal block, killed bydesc-act-anyandformat-any. Every new test passes on the unmutated tree, which is step 1 of the gate list below.test-gptq-reader-host: 23 of 23 killed, each failing between one and five of the 52 tests, every kill naming one of the reader's own nine test blocks, as the table below lists, scored from each mutant's own build log. The control is the same step on the same tree without a mutant, 52/52.config.jsoncompiled in, printedPROBE rules 11 why ""andquantizedtrue forlanguage_model.lm_head,layers.0.mlp.experts.0.gate_projandlayers.0.mlp.experts.0.down_proj, false forlayers.0.linear_attn.in_proj_qkv,layers.3.self_attn.q_projandlayers.0.mlp.shared_expert.gate_proj(53/53 tests on that copy, its 52 plus the probe). So the reader admits that export's config as written, including the empty objects itsdynamicrules carry.36c98854f(this head), run on this pull request:fmt,zig,zig-b,zig-windows,pytest,benchmark-clients(ubuntu and windows),release-pathsandzig-macos-dev-toolsall completed successfully;host-nightly-linuxandhost-nightly-macosare skipped by their own conditions.compile-config-serverandcompile-cuda-teststype-check the backends that importcore/quantfor aarch64.Each mutant is the complement of one check the reader makes, applied to its own fresh tree of this head and scored from its own build log; the middle column is the count of the 52 tests that still passed:
bits-anya config outside the dialect is refused by its field or rule namecolumn-stridethe stored tensors dequantize to the binary64 fixturedefault-unquantizedthe synthetic checkpoint's config is admitted and names the modules it stores quantized;an escape of an alphanumeric character is refused, as Python's re reads it as a class or an anchor;a config outside the dialect is refused by its field or rule name;a config that declares no gptq block is not this reader's, and the head rule may stand alone;the last rule matching a module decides, and no rule leaves it quantizeddesc-act-anya config outside the dialect is refused by its field or rule namedtype-anyevery tensor it refuses is named, the zero point and act order includeddynamic-optionala config outside the dialect is refused by its field or rule nameescapethe synthetic checkpoint's config is admitted and names the modules it stores quantized;the matcher reads the rule subset and anchors as Python's re.match does;an escape of an alphanumeric character is refused, as Python's re reads it as a class or an anchorescape-classan escape of an alphanumeric character is refused, as Python's re reads it as a class or an anchorfirst-matchthe last rule matching a module decides, and no rule leaves it quantizedformat-anya config outside the dialect is refused by its field or rule nameg-idx-anyevery tensor it refuses is named, the zero point and act order includedgroup-anya config outside the dialect is refused by its field or rule namegroup-stridethe stored tensors dequantize to the binary64 fixturelm-head-anya config outside the dialect is refused by its field or rule namematcher-endthe synthetic checkpoint's config is admitted and names the modules it stores quantized;the matcher reads the rule subset and anchors as Python's re.match doesmethod-anya config that declares no gptq block is not this reader's, and the head rule may stand alonenibble-orderthe stored tensors dequantize to the binary64 fixture;every tensor it refuses is named, the zero point and act order includedrule-bits-anya config outside the dialect is refused by its field or rule namerule-group-anya config outside the dialect is refused by its field or rule namesubset-anyan escape of an alphanumeric character is refused, as Python's re reads it as a class or an anchor;a config outside the dialect is refused by its field or rule namesym-anya config outside the dialect is refused by its field or rule namezero-pointthe stored tensors dequantize to the binary64 fixture;every tensor it refuses is named, the zero point and act order includedzeros-anyevery tensor it refuses is named, the zero point and act order included;the zero point check reads both nibbles of every wordReceipt
grep -rln 'quant\.gptq\|quant/gptq\|gptq\.zig' ziglists the reader, its test,core/quant/quant.zig(one module line),core/root.zig(one line in its test list) andzig/build/checkpoint_io_host.zig(the test-only step), and no family, kernel, server or recipe file.zig/src/platform/environment.zigis untouched and so isdocs/environment.md.077998f7d9b14adebec3a2acc2caa47ff7ae6ec7, head36c98854f6b53b3bbff741ede301349849539fda, Zig 0.17.0, no backend toolchain involved, an aarch64 Ubuntu 24.04 machine with an NVIDIA GB10 of which no device was used, no checkpoint for the tests (the fixture is synthetic and built by the test), and the published export read for its tensor headers and itsconfig.jsononly.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: n/a, no served path. The exactness this change does own is the binary64 fixture in the test, checked bit for bit against values derived by hand from the stored nibbles and fp16 scales.tools/bench_openai.py: n/a, no served path.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo: not applicable as above.