Repository navigation
gguf: Q2_0, mainline ggml's type 42, is a named type with its sizes and a port of dequantize_row_q2_0 - #67
Merged
Conversation
…ale and 2-bit codes, (q - 1) * d), is a named type with its block size, its type size and a dequant_row port of mainline's dequantize_row_q2_0, so a file of Q2_0 tensors opens instead of stopping at "ggml type ggml-type-42 has no size in this build's table" (midagedev#48) The strict open and ggml_type_info size a named type from GgmlType, so the variant is the whole loader change; strict_tensors is untouched. A code byte holds four values, the low pair first: value j is bits 2 * (j % 4) of qs[j / 4], and codes 0..3 decode to -1, 0, +1, +2 times d. No CPU matmul takes Q2_0 here yet (mainline pairs it with Q8_0 activations), so activation_format refuses it by name, as it does BF16; CardFormat::of and the six card kernel tables give it None, so a Q2_0 tensor that the plan puts on a card is still refused by name. tools/hf-arch-check.py's mirror of from_u32 names 42. The reference is mainline's own decode, since ik has no Q2_0. Q2_0_MAINLINE is dequantize_row_q2_0 of llama.cpp f2cc7282c over the test's four blocks at d = 1.0, printed on an x86_64 Ubuntu 26.04 machine by a short C program linked against that build's libggml-base.so, through ggml_get_type_traits(GGML_TYPE_Q2_0)->to_float; the same library answers q2_0, 64 and 18 for GGML_TABLE's new row. The test then gives the four blocks four different scales a pass, rotated through nine (1.0, subnormal, negative, zero, negative zero and largest finite among them), and in all nine passes mainline's output equals the d = 1.0 value times its block's d bit for bit, signed zeros included, which is what the test computes. UNKNOWN_IDS trades 42 for 43, the first id past mainline's table, and its doc now says what 40, 41 and 99 are in the two tables instead of calling them ids past both. FAIL-first: with the new inventory case and 697790c's gguf source, the strict open of the Q2_0 file is red with `strict open of a supported type: tensor "blk.0.ffn_down.weight": ggml type ggml-type-42 has no size in this build's table`, on x86_64 Linux. q2_0_matches_mainline is red on three dequant mutants: the codes read high pair first ("d 0x3c00 value 0: got 2e0, want -1e0"), (q - 2) * d ("got -2e0, want -1e0"), and every block decoded with the first block's scale ("d 0x0001 value 66: got 1e0, want 5.9604645e-8"). On x86_64 Linux, cargo test -p bloomery-gguf -p bloomery-placement passes (gguf lib 26, inventory 5, placement 119), and just contrib-check --tier t0 has 66 of 66 units green. On aarch64 macOS, just mac-static 697790c passes (check-recipes green, lint at the ratchet's 41). The gguf lib tests do not build on macOS, for libc::RUSAGE_THREAD.
Owner
|
Thank you. This is part 1 as agreed on #48. Review has started. The PR touches |
Owner
|
Thanks. Review found no defect. This goes into the 0.3.2 train now, as a merge of your commit, and lands when the train's gates are green. You do not need to change anything. We will add two small things on main afterwards:
|
7 tasks done
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.
What and why
This is part 1 of the two Q2_0 pull requests agreed on #48: the type, its block size, its type size and its dequant,
with a FAIL-first on today's open error for type 42 and a synthetic-block test against mainline's
dequantize_row_q2_0(ik has no Q2_0). A file of Q2_0 tensors now opens instead of stopping atggml type ggml-type-42 has no size in this build's table. Part 2, the AVX2 host dot incrates/qdot, follows after this one.It does not close #48: the card kernels and the Qwen3.8 body work you named there stay open.
Q2_0 is 64 values in 18 bytes: an f16 scale
d, then 16 bytes of 2-bit codes. A code byte holds four values, the lowpair first, and codes 0..3 decode to -1, 0, +1, +2 times
d.GgmlType::Q2_0(id 42) with its name, block size 64 and type size 18. The strict open andggml_type_infosize anamed type from
GgmlType, so the variant is the whole loader change;strict_tensorsand 0.3.1'sFILE_TABLE_IDSare untouched.dequant_rowdecodes it with a port ofdequantize_row_q2_0(llama.cppf2cc7282c, ggml-quants.c:439). Its oneproduct, an f16 times an integer of magnitude at most 2, is exact in f32.
activation_formatrefuses it by name,as it does BF16.
CardFormat::ofand the six card kernel tables give itNone, so a Q2_0 tensor the plan puts on acard is still refused by name.
tools/hf-arch-check.py's mirror offrom_u32names 42.UNKNOWN_IDStrades 42 for 43, the first id past mainline's table, and its doc now says what 40, 41 and 99 are inthe two tables instead of calling them ids past both.
The test reference is mainline's own decode.
Q2_0_MAINLINEisdequantize_row_q2_0of llama.cppf2cc7282coverthe test's four blocks at
d = 1.0, printed by a short C program linked against that build'slibggml-base.sothrough
ggml_get_type_traits(GGML_TYPE_Q2_0)->to_float(the program and its output are below). The same libraryanswers
q2_0, 64 and 18 forGGML_TABLE's new row. The four blocks' code bytes are chosen so that every positionholds each of the four codes once across the blocks. The test then gives the four blocks four different scales a pass,
rotated through nine (1.0, subnormals, a negative, zero, negative zero and the largest finite among them). In all nine
passes mainline's output equals the
d = 1.0value times its block'sd, bit for bit and signed zeros included,which is what the test computes.
Code shape
ShortSrc,UnalignedDst), and the test holds both.UNKNOWN_IDSloses 42 because the enum names it now; the line carriesPIN(2026-10-12):as the q2_K line before it does.cargo fmtandcargo clippyare clean on what I touched; the lint count did not go up (41, the ratchet).Duplication found or removed (
path:line), or "none": noneWhat I ran
Base
697790c4f, the 0.3.1 tag plus one README commit. Main has since moved by documentation commits only (README, docs/performance.md).FAIL-first: the new inventory case alone on the base, on x86_64 Linux:
q2_0_matches_mainlineagainst three dequant mutants (x86_64 Linux):With the change, x86_64 Linux:
aarch64 macOS:
The lint count is 41, the ratchet's, and the combos step ran 35 shapes with none red.
The gguf lib tests do not build on macOS (
libc::RUSAGE_THREAD), so they ran on Linux only.I could not run the box gates.
just affected 697790c4 --no-boxselects 145 of 150 gate recipes, since every GPU gatebin links
bloomery-ggufand the CPU engine's gates reachbloomery-placementthroughbloomery-model; those are yours to run. No kernel orCPU path changes for an existing type: the new match arms are Q2_0's alone, and a Q2_0 tensor is refused before any
card or CPU kernel sees it.
The mainline reference program and its output
Linked against
libggml-base.soof a llama.cppf2cc7282cRelease build (-DGGML_CUDA=ON; the program uses onlyggml-base), GCC 15.2.0, x86_64 Ubuntu 26.04:
Output:
Hardware (if the change is for a machine)
Not for a machine. The tests ran on x86_64 Linux (AMD Ryzen 9 9950X, Ubuntu 26.04.1, kernel 7.0, glibc 2.43,
nightly-2026-08-28) and the static tier on an aarch64 Mac.