From the dequantize_row_* functions of ggml/src/ggml-quants.c, the tables of ggml/src/ggml-common.h and the helper functions of
ggml/src/ggml-impl.h in llama.cpp (master, read 2026-11-13). The block layouts (field order and sizes) are on the
tensor types page. Each function turns k values stored as blocks into k floats, y, block after block; d and m are
binary16 values converted to 32-bit floats, qs means the block's quant array, and the bit tests are on bytes read in file order (little-endian where a larger integer is read, as in the
memcpy of qh). Output is written in the order the values are listed here.
Unquantised types
F32, F16 (IEEE binary16), BF16 (bfloat16: the upper 16 bits of a binary32), F64, I8, I16, I32, I64 are plain little-endian values, one per element; F8_E4M3 is decoded by ggml_f8_e4m3_to_fp32 (below).
Legacy types (32-value blocks)
| Type | Value j of the block |
|---|---|
| Q4_0 | for j = 0 to 15: y[j] = d × ((qs[j] & 0xF) − 8) and y[j+16] = d × ((qs[j] >> 4) − 8). |
| Q4_1 | y[j] = d × (qs[j] & 0xF) + m, y[j+16] = d × (qs[j] >> 4) + m. |
| Q5_0 | qh is read as a little-endian 32-bit integer; for j = 0 to 15: bit 4 of value j is bit j of qh (((qh >> j) << 4) & 0x10), and bit 4 of value j+16 is bit j+16 of qh ((qh >> (j+12)) & 0x10); y[j] = d × (((qs[j] & 0xF) | xh0) − 16), y[j+16] = d × (((qs[j] >> 4) | xh1) − 16). |
| Q5_1 | the same bits, y[j] = d × ((qs[j] & 0xF) | xh0) + m, y[j+16] = d × ((qs[j] >> 4) | xh1) + m. |
| Q8_0 | y[j] = d × qs[j] with qs signed bytes. |
| Q8_1 | no dequantize_row function exists for it in the file; the layout (d, s, 32 signed bytes) is that of Q8_0 plus the stored sum s, and a reader can use y[j] = d × qs[j] (an inference from the layout, not stated in the source). |
| Q1_0 (128 values) | bit j of the block (bit j mod 8 of byte j div 8, low bit first) gives y[j] = +d if 1 and −d if 0. |
| Q2_0 (64 values) | value j is the 2 bits at bit offset 2·(j mod 4) of byte j div 4, q = 0 to 3: y[j] = (q − 1) × d (codes 00, 01, 10, 11 mean −1, 0, +1, +2). |
| Q8_K (256 values) | y[j] = d × qs[j] with d a 32-bit float; bsums are not used. |
k-quants (256-value super-blocks)
- Q2_K.
danddminbinary16. Four passes j = 0 to 3 over each 128 values, withshift= 2j; two 16-value groups per pass, group 0 fromq[0..15], group 1 fromq[16..31](qadvances by 32 after every four passes). For a group with scale bytesc(the 16 scale bytes in order):dl = d × (sc & 0xF),ml = dmin × (sc >> 4);y = dl × ((q[l] >> shift) & 3) − ml. - Q3_K.
dbinary16. The 12scalesbytes are copied into the first three of four 32-bit wordsaux[0..3]and unpacked into 16 signed bytes (the 16 bytes ofaux, in memory order, are then the scales, each used as a signed byte) withkmask1 = 0x03030303,kmask2 = 0x0F0F0F0F:tmp = aux[2];aux[2] = ((aux[0] >> 4) & kmask2) | (((tmp >> 4) & kmask1) << 4);aux[3] = ((aux[1] >> 4) & kmask2) | (((tmp >> 6) & kmask1) << 4);aux[0] = (aux[0] & kmask2) | (((tmp >> 0) & kmask1) << 4);aux[1] = (aux[1] & kmask2) | (((tmp >> 2) & kmask1) << 4). Then, with the same loop shape as Q2_K (passes of 128 values,shift0, 2, 4, 6, and a maskmstarting at 1 and doubled each pass):dl = d × (scale − 32)andy = dl × (((q[l] >> shift) & 3) − (hmask[l] & m ? 0 : 4)), wherehmaskis indexed with the same l (0 to 15 or 16 to 31) asq. - Q4_K.
d,dminbinary16. For j = 0, 64, 128, 192 (indexis= 0, 2, 4, 6):get_scale_min_k4(is)gives (sc, m) andget_scale_min_k4(is+1)gives the second pair; the first 32 values ared × sc1 × (q[l] & 0xF) − dmin × m1and the next 32d × sc2 × (q[l] >> 4) − dmin × m2, withqadvancing by 32 per step.get_scale_min_k4(j, q): for j < 4,sc = q[j] & 63andm = q[j+4] & 63; otherwisesc = (q[j+4] & 0xF) | ((q[j−4] >> 6) << 4)andm = (q[j+4] >> 4) | ((q[j] >> 6) << 4). - Q5_K. As Q4_K, but each value adds 16 when a bit of
qh[l]is set: the low-nibble values test bit masku1and the high-nibble valuesu2, which start at 1 and 2 and are shifted left by 2 after every 64 values; value =d × sc × ((nibble) + (qh[l] & u ? 16 : 0)) − dmin × m. - Q6_K.
dbinary16,scalessigned bytes. In two halves of 128 values, for l = 0 to 31 andis = l/16:q1 = ((ql[l] & 0xF) | (((qh[l] >> 0) & 3) << 4)) − 32,q2 = ((ql[l+32] & 0xF) | (((qh[l] >> 2) & 3) << 4)) − 32,q3 = ((ql[l] >> 4) | (((qh[l] >> 4) & 3) << 4)) − 32,q4 = ((ql[l+32] >> 4) | (((qh[l] >> 6) & 3) << 4)) − 32;y[l] = d × sc[is] × q1,y[l+32] = d × sc[is+2] × q2,y[l+64] = d × sc[is+4] × q3,y[l+96] = d × sc[is+6] × q4; theny += 128,ql += 64,qh += 32,sc += 8.
Ternary types (256 values)
- TQ1_0.
dbinary16. The 48 bytes ofqshold 5 ternary digits each (base 3, as multiples of the powers 1, 3, 9, 27, 81). For each byte takeq = (byte × pow3[n]) mod 256(as an 8-bit product) and the digit isxi = (q × 3) >> 8(0, 1 or 2); the value is(xi − 1) × d. Order: for the first 32 bytes (the part ofqsup to the largest multiple of 32, 32 here), for each n = 0 to 4, all 32 bytes in order; then for the remaining 16 bytes n = 0 to 4 over the 16; then the 4 bytes ofqhfor n = 0 to 3. - TQ2_0.
dbinary16; for each 32-byte group ofqs, for l = 0 to 3 (bit offset 2l), all 32 bytes:y = (((qs >> 2l) & 3) − 1) × d.
i-quants
These look the values up in tables of ggml-common.h. kmask_iq2xs is {1, 2, 4, 8, 16, 32, 64, 128}. ksigns_iq2xs has 128 entries and entry i is the 7-bit number i with bit 7 set so that the whole byte has an even number of set bits (the values begin 0, 129, 130, 3, 132, 5, 6, 135, ... and end 126, 255). The grid tables hold the values packed in integers: iq2xxs_grid 256 entries of 64 bits, iq2xs_grid 512 and iq2s_grid 1024 entries of 64 bits (eight unsigned bytes each, read byte by byte in memory order, little-endian); iq3xxs_grid 256 and iq3s_grid 512 entries of 32 bits (four unsigned bytes); iq1s_grid 2048 entries of 64 bits (eight signed bytes). The tables' contents are fixed numbers in ggml-common.h; all 4,608 values are listed on the quantisation grids page.
- IQ2_XXS:
dbinary16; per 32-value groupib32, read two 32-bit wordsaux32[0..1]fromqs + 4·ib32(qsviewed as bytes; the layout is 4 index bytes then a 32-bit word).db = d × (0.5 + (aux32[1] >> 28)) × 0.25. For l = 0 to 3: the grid row isiq2xxs_grid[aux8[l]], the sign byte isksigns_iq2xs[(aux32[1] >> 7l) & 127], and value j (0 to 7) isdb × grid[j] × (signs & kmask_iq2xs[j] ? −1 : +1). - IQ2_XS:
qsis 16-bit words. Per group:db[0] = d × (0.5 + (scales[ib32] & 0xF)) × 0.25,db[1] = d × (0.5 + (scales[ib32] >> 4)) × 0.25; for l = 0 to 3, wordw = qs[4·ib32 + l]: grid rowiq2xs_grid[w & 511], signsksigns_iq2xs[w >> 9], scaledb[l/2]; value as IQ2_XXS. - IQ2_S:
qsbytes (the first 32 are grid low bytes),qh, and the sign bytes are the next 32 bytes ofqs(signs = qs + 32in a 64-byteqs). Scales as IQ2_XS. For l = 0 to 3 in each group: grid rowiq2s_grid[qs[l] | ((qh[ib32] << (8 − 2l)) & 0x300)]; sign bytesigns[l](not looked up); valuedl × grid[j] × (signs[l] & kmask_iq2xs[j] ? −1 : +1); after each groupqsandsignsadvance by 4. - IQ3_XXS:
dbinary16;qs(64 bytes of grid indices, 8 per 32-value group) followed by 32 bytes of scales and signs (a 32-bit wordaux32per group).db = d × (0.5 + (aux32 >> 28)) × 0.5; for l = 0 to 3: sign byteksigns_iq2xs[(aux32 >> 7l) & 127], grid rowsiq3xxs_grid[qs[2l]]andiq3xxs_grid[qs[2l+1]]giving values 0 to 3 and 4 to 7; valuedb × grid × signwith the sign bitskmask_iq2xs[j](j 0 to 7 across the two rows). - IQ3_S:
dbinary16;qs,qh,signs,scales. Two 32-value groups per step:db1 = d × (1 + 2 × (scales[ib32/2] & 0xF))anddb2 = d × (1 + 2 × (scales[ib32/2] >> 4)). For the first group l = 0 to 3: grid rowsiq3s_grid[qs[2l] | ((qh[0] << (8 − 2l)) & 256)]andiq3s_grid[qs[2l+1] | ((qh[0] << (7 − 2l)) & 256)], sign bytesigns[l]; valuedb1 × grid[j] × sign(rows give j 0 to 3 and 4 to 7). Thenqs += 8,signs += 4; the second group usesqh[1]anddb2; thenqh += 2,qs += 8,signs += 4. - IQ1_S:
dbinary16,qsbytes,qh16-bit words,IQ1S_DELTA = 0.125. Per 32-value groupib:dl = d × (2 × ((qh[ib] >> 12) & 7) + 1);delta = −0.125if bit 15 ofqh[ib]is set, else+0.125; for l = 0 to 3: grid rowiq1s_grid[qs[l] | (((qh[ib] >> 3l) & 7) << 8)]and valuedl × (grid[j] + delta), j 0 to 7;qs += 4per group. - IQ1_M: no separate scale field. The 16-bit scale
d(binary16) is assembled from the four 16-bit wordssc[0..3]ofscales:u16 = (sc[0] >> 12) | ((sc[1] >> 8) & 0x00F0) | ((sc[2] >> 4) & 0x0F00) | (sc[3] & 0xF000). Per 32-value groupib:dl1 = d × (2 × ((sc[ib/2] >> (6·(ib mod 2) + 0)) & 7) + 1)anddl2 = d × (2 × ((sc[ib/2] >> (6·(ib mod 2) + 3)) & 7) + 1); grid indicesidx[0] = qs[0] | ((qh[0] << 8) & 0x700),idx[1] = qs[1] | ((qh[0] << 4) & 0x700),idx[2] = qs[2] | ((qh[1] << 8) & 0x700),idx[3] = qs[3] | ((qh[1] << 4) & 0x700); deltas ±0.125 from bitsqh[0] & 0x08,qh[0] & 0x80,qh[1] & 0x08,qh[1] & 0x80(set means negative); valuesdl1 × (grid + delta)for the first two rows anddl2 × (grid + delta)for the last two; thenqs += 4,qh += 2. - IQ4_NL (32 values):
kvalues_iq4nl = {−127, −104, −83, −65, −49, −35, −22, −10, 1, 13, 25, 38, 53, 69, 89, 113};y[j] = d × kvalues_iq4nl[qs[j] & 0xF]andy[j+16] = d × kvalues_iq4nl[qs[j] >> 4]. - IQ4_XS (256 values): per 32-value group
ib: 6-bit scalels = ((scales_l[ib/2] >> 4·(ib mod 2)) & 0xF) | (((scales_h >> 2ib) & 3) << 4),dl = d × (ls − 32);y[j] = dl × kvalues_iq4nl[qs[j] & 0xF]andy[j+16] = dl × kvalues_iq4nl[qs[j] >> 4]withqsadvancing 16 bytes per group.
FP4 and FP8 types
kvalues_mxfp4(the same table iskvalues_fp4) is{0, 1, 2, 3, 4, 6, 8, 12, 0, −1, −2, −3, −4, −6, −8, −12}: the E2M1 values doubled (index bit 3 is the sign).- MXFP4 (32 values):
d = ggml_e8m0_to_fp32_half(e): fore< 2 the 32-bit pattern0x00200000 << e, otherwise the pattern(e − 1) << 23, read as a float (that is 2e−128, so it includes the factor 1/2 that undoes the doubled table).y[j] = d × kvalues_mxfp4[qs[j] & 0xF]andy[j+16] = d × kvalues_mxfp4[qs[j] >> 4]. - NVFP4 (64 values): four 16-value sub-blocks s, each with scale
d[s]decoded byggml_ue4m3_to_fp32;y[j] = d × kvalues_mxfp4[qs[8s+j] & 0xF]andy[j+8] = d × kvalues_mxfp4[qs[8s+j] >> 4]within the sub-block, j 0 to 7.ggml_ue4m3_to_fp32(x): 0 ifxis 0 or0x7F;exp = (x >> 3) & 0xF,man = x & 7; ifexpis 0 the value isman × 2−9, otherwise(1 + man/8) × 2exp−7; the result is multiplied by 0.5 (to match the doubled table). - F8_E4M3 (one byte per value):
ggml_f8_e4m3_to_fp32(x): NaN ifx & 0x7Fis0x7F;exp = (x >> 3) & 0xF,man = x & 7; magnitudeman × 2−9ifexpis 0, else(1 + man/8) × 2exp−7; negative if bit 7 is set (OCP FP8 revision 1.1).