Skip to content

core: a Checkpoint reads bf16 weights stored in DFloat11's lossless form, decoded at load; GLM on CUDA attaches it - #3807

Merged
ashhart merged 3 commits into
ashhart:mainfrom
Bizuayeu:pr/checkpoint-dfloat11
Nov 20, 2026
Merged

ashhart merged 3 commits into
ashhart:mainfrom
Bizuayeu:pr/checkpoint-dfloat11

Conversation

@Bizuayeu

@Bizuayeu Bizuayeu commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

A Checkpoint reads a bf16 weight stored in DFloat11's lossless form (#3649): get, expect and has answer it under its own name, decoded on the host at load to the bf16 bytes it was coded from. Before this, a checkpoint that stores a weight that way is refused by the missing tensor's name. GLM's loader on CUDA is the one loader wired, by one call; a checkpoint with no coded tensor reads as before.

On two GB10s at TP=2, one stream, a GLM-5.3-Flash-shaped mixed-precision checkpoint stored plain, and the same one with 150 bf16 matrices coded (12,067,012,608 bytes stored as 8,160,579,696):

main, plain this branch, plain this branch, coded
Tensors on disk (GB) 183.67 183.67 179.77
Load, the engine's loaded in (s) 115.1, 114.4 115.5, 115.2, 115.5 153.8, 155.2, 153.5
Peak of the engine's memory outside mapped files, RssAnon, rank 0 / rank 1 (GiB) 3.62 / 3.58, 3.58 / 3.75 3.67 / 3.57, 3.62 / 3.61, 3.83 / 3.61 6.02 / 5.97, 5.97 / 5.96, 6.01 / 5.97
Peak resident set, VmHWM (GiB) 8.62 8.55 to 8.63 10.83 to 10.86
Decode, fibonacci-raw, expert form factored (tok/s) 19.87 19.92, 19.91 19.93, 19.94
Decode, fibonacci-raw, expert form classic (tok/s) 19.49 19.47 19.51
Prompt of 9,600 tokens, the first request after load (s) 6.71, 6.73 6.70, 6.70, 6.67 6.78, 6.75, 6.80
Prompt of 38,400 tokens (s) 26.24, 26.02 26.96, 26.19, 26.04 26.62, 26.45, 26.33

Every number is one launch's, in the launches' order within its cell; nothing is averaged. Ten launches ran in turn at a 40,960-token window: main plain, branch plain, branch coded, main coded (the control below), branch coded, branch plain, main plain, branch coded, main plain, branch plain. Both GPUs held their clock cap with no cap event during any launch.

Tokens. The nine launches that loaded give one set of ten hashes: the token_sha256 of three decode-check prompts of 512 tokens, drafted and with "draft": false, and of the 9,600- and 38,400-token prompts, cold and then resumed three times each; and, for the two decode prompts of 256 tokens with "draft": false, the tool's 12-digit token_sha and the reply's output_sha256. main on plain, the branch on plain and the branch on the coded folder agree on all ten, across both expert forms.

The control. main refuses the coded folder at load, by the first weight it cannot find: error: checkpoint has no tensor model.language_model.layers.0.self_attn.q_proj.weight (MissingTensor). So the three coded launches read those weights through the new reader. The checkpoint digest read 167.5 GiB on the coded folder against 171.1 GiB on the plain one.

What it costs. Load is 38 to 40 s longer on the coded folder: 150 groups, 12.07 GB of bf16, decoded a group at a time (a standalone check of the reader decodes the same 150 in 40 to 42 s on one thread). The engine's memory outside mapped files peaks 2.4 GiB higher for about 8 s at the end of load; the size matches the embedding's and the head's decoded copies (1.27 GB each) held together, though the trace has the size and the time, not the names. It is back to the plain launches' 0.7 GiB before the server is healthy. The lowest MemAvailable on the hosts is the same on every launch (8.5 to 9.0 GiB), but that says nothing here: the KV pool takes the room it measures after load. The pool was 1,905, 1,905 and 1,926 pages on the coded launches and 1,910 to 1,937 on the plain ones; three launches do not tell those apart. RssAnon and VmHWM are read from the engine's /proc status every 0.5 s on both hosts. On the plain checkpoint this branch's three loads are each longer than main's two, by 0.1 to 1.1 s (0.1 and 1.1 s neighbour by neighbour); two main launches do not say whether that is the branch.

Read with care.

  • Decode: each launch races GLM's classic and factored expert forms at load and keeps the winner, and the two forms differ by 2% here on every arm. Six launches kept factored and three classic, so the table has a row for each. Within a form no arm differs by more than 0.4%.
  • The 38,400-token prompt got shorter with the launches' order, on every arm (27.32, 26.96, 26.62, 26.45, 26.19, 26.24, 26.33, 26.02, 26.04 s in order); not traced. Neighbours read 26.19 (branch, plain) against 26.24 (main), and 26.02 (main) against 26.04 (branch, plain).
  • The first request after load, the 9,600-token prompt, is 1.2% longer on the coded folder in all three launches (6.78, 6.75, 6.80 s against 6.67 to 6.73 on the five plain launches). The second cold prompt, the resumed prompts and decode show no such difference. Not traced. A later run on the receipt's binary, six launches of each folder side by side with TF_GLM_EXPERT_FORM=factored so that the expert form could not differ: that first prompt was longer on the coded folder in all six pairs, by 0.2% to 1.3% (median 0.8%); on the four cold prompts after it (38,400, 2,048, 8,192 and 32,768 tokens) the pairs went both ways (the coded folder the slower one in 4, 3, 5 and 4 of the six, single pairs between -4.7% and +2.0%, medians 0.0% to +0.5%). Decode was not measured in that run.
  • The first launch of the ten (main, plain) is left out of the table: it began with about 70 GiB of the hosts' page cache still held, where the other nine began under 1.5 GiB. It gave the same ten hashes; its numbers were 119.5 s to load, 19.66 tok/s (factored), 6.65 s and 27.32 s.

What this changes

The decoder (core/dfloat11.zig). One group in, bf16 bytes out: it checks the tables, the positions and the gaps before and while it walks the stream, and never reads or writes outside an array. It was written from a description of the format, not from DFloat11's code; the description and where each of its statements comes from are at the end of this text.

The config (core/dfloat11_config.zig). config.json's dfloat11_config says which weights a group holds and in what order. Its patterns are read in the steps the published configs use (literal text, ., \., \d, \d+); a pattern with another step is refused by name, and a module two patterns describe is an error.

The reader (core/checkpoint_coded.zig, core/checkpoint.zig). attach finds the groups in the headers and lists their members' weight names (<module>.weight, or <module>.<member>.weight for a group of several). get, expect and has fall through to that list when the name is not in a header. A group is decoded once into a 64-byte-aligned buffer that release() and close() drop. attach refuses a group it cannot answer for: one no pattern lists, one without its six tensors or with a wrong dtype, one whose member count does not match its split positions, and a name stored both plain and coded. The files do not carry the coded weights' shapes, so expect uses the caller's and get asks the family (CodedShapeUnknown when it has none).

GLM on CUDA (families/glm/cuda_dfloat11.zig, two lines in cuda_weights.zig). The shapes of the names its loader takes with get (q, k, v, o, kv_b, the embedding and the head), and the attach on the loader's two checkpoints when the config has the object.

What stays. No kernel source and no option: the stored layout chooses, and after load the engine holds the bytes it holds today. A checkpoint with no dfloat11_config takes no new path.

Limits.

  • The format has no checksum. Structural damage is refused by name and nothing is read or written out of range, but a changed byte inside a stream can decode to other values with every check passing (the test with random single-byte changes holds "refused or decoded, never anything else"). The file's hash tells the rest.
  • A coded tensor with an infinity or a NaN cannot be written in this form (exponents 240 to 255 are the tables' pointers); that binds the writer.
  • The early refusal before load sums the files' sizes, so on a coded folder it is 3.9 GB more lenient than the bytes loaded. Not changed here; the room after load is measured as before.
  • The content digest refuses a header that lists a group's empty split_positions after the tensor that starts at the same offset (BadHeader, from its ordering of ranges). The writer used here lists it first, and a host test holds that order; the digest's check is not changed. The same check replayed in Python on the headers of three published DF11 repositories (73 files) refuses none: their two empty split_positions are listed first as well.
  • The decode is one thread and a whole group at a time.

Checks on this head

  • Head commit: e5fd126b47. It adds the CHANGELOG line to 2b8ed8fe64 and changes no code, so the tests and the receipt, taken on 2b8ed8fe64, were not taken again. The receipt's binary was built from 2b8ed8fe64's tree with one line elsewhere: cuda_weights.zig's _ = @import("cuda_dfloat11.zig");, a test registration, sat two lines lower. That line is in a test block and is not compiled into the engine, so the receipt was not taken again.
  • Lean checker, python3 tools/zig/lean_check.py, on the base and on this head: 221 problems on both, 0 new. python3 tools/pr_check.py --base af9777b494 --pr 3807: 11 changed files, lean 221 against 221 with 0 new, 0 errors, 0 warnings.
  • Tests run, with the command and pass, fail and skip counts: on x86_64 (WSL), in a fresh copy of 2b8ed8fe64's tree: zig build test 3,294 of 3,339 with 45 skipped (730 of 730 steps), test-golden (5 of 5 steps), test-cuda-host 7,161 of 7,194 with 33 skipped (418 of 418 steps), compile-cuda-tests 10 of 10, compile-config-server 7 of 7, tools/zig/cuda_common_check.py and zig fmt --check build.zig zig. The 27 new tests are host tests: 13 for the decoder, 3 for the config, 8 for the reader, 3 for GLM (its shapes, its attach, and the loader's cuts of a coded head, o_proj and q_proj against the plain bytes). Run directly, core's host test binary lists the 24 core ones as passing (720 passed, 10 skipped) and the GLM CUDA host test binary the GLM ones (251 tests, all pass). The pytest suite CI runs, from the root with a clang++ stand-in and Zig on PATH: 523 passed and 86 skipped with 622 subtests; main's CI on the same base reads 525 passed and 84 skipped with 622 subtests; two of the skips here give this interpreter's older Unicode table as their reason, which matches the difference in count (CI's log does not print skip reasons). Mutants, each failing a test (one that does not compile is not counted): 16 of the decoder, 17 of the reader, 5 of the config and 7 of GLM's file; they were run on this code at an earlier base.
  • CI: on this head Zig format (fmt) and No GPU succeeded: zig, zig-b, zig-windows, zig-macos-dev-tools, pytest, release-paths and both benchmark-clients jobs; the two host-nightly jobs were skipped. The first push's No GPU run was cancelled by the second push.
  • Lanes, on the two GB10s at TP=2, with the tf-cuda-test built beside the receipt's binary from the same tree: on the coded folder glm-lanes-cover gives 46 PASS, glm-lanes-concurrent 38 PASS and glm-shared-check 1 PASS on rank 0, with 0 FAIL and exit 0 on both ranks; the plain folder it was coded from gives the same counts with the same runner. (Run after this was opened.)
  • Not run, and why: Metal, HIP and XPU, which I have no machine for. TP=3 or wider was not run for this.

Receipt

  • Main against branch: the table above.
  • Boxes it reaches: every family through core's Checkpoint, with no effect until a loader attaches the coding; GLM-5.3-Flash on CUDA attaches it. Ran on GB10 (sm_121) at TP=2.
  • New switch? None; the checkpoint's dfloat11_config chooses.
  • Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: main af9777b494 and this branch's tree on it (see Head commit), each built from an empty Zig global cache. Zig 0.17.0, nvcc 13.3 for sm_121. Driver 580.178.04, NCCL 2.30.7. Two GB10s at TP=2 over a direct link. The plain checkpoint is Bizuayeu/Sage-S2.1-Flash-Mixed-NVFP4@3cc01182 (the later commits there change its card alone), read from a local copy whose 144 files have that revision's hashes. The coded checkpoint is the same files with 150 bf16 matrices of the language model (136 attention projections, 12 kv_b, the embedding and the head) each rewritten as one DFloat11 group under DFloat11's tensor names, with a dfloat11_config of one pattern a module; the vision tower and the bf16 tensors that are not a .weight stay plain. It was written by a script of mine that is not in this pull request, the same bytes on three machines. The coded folder is published as Bizuayeu/Sage-S2.1-Flash-Mixed-NVFP4@25897b161e65609a7341970d938703d22fa582de (branch dfloat11), beside the plain revision it was coded from; the script is not published.
  • Paths and platforms the change reaches, which I ran and which I could not: core's Checkpoint (host code, any platform; host tests on x86_64, the real folder on aarch64) and GLM's CUDA load. Ran on GB10 (sm_121). Could not run any other CUDA chip, or another backend.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: the paragraph "Tokens" above. Below the tokens, on the real coded folder and with no GPU: all 150 coded tensors, read through this reader with GLM's attach, have the sha256 of the bf16 tensors they replaced, and so do they through a reference decoder in Python written from the same description; a bit flipped in sign_mantissa or encoded_exponent gives other bytes, and one flipped in gaps or luts is refused. The decoder also gives one published group's source bytes: model.layers.0 of DFloat11/Qwen3-4B-DF11@618eddad, seven weights of Qwen/Qwen3-4B in one group, 201,850,880 bytes.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): the table above. For a second backend: the reader takes DFloat11's published layout (its published configs' patterns are read in the tests, and one published group decodes to its source), so another family needs its loader's attach and its shapes; the coded folder above is published as a fixed input for that (see Environment).
  • Decode speed before and after, from tools/bench_openai.py: its two prompts with "draft": false in each request, 256 tokens five times each, one stream: the table (the second prompt, gpu-chat-no-think, reads within 0.03 tok/s of the first on every launch in it). On the plain checkpoint this branch is 0.2 to 0.3% faster than main in the factored form and 0.1% slower in the classic one.
  • Prompt speed before and after: the cold first request's ttft_s from tools/bench_cache.py --require-cold, on the decode-check prompts' tokens repeated to 9,600 and 38,400: the table and "Read with care".
  • Licence of any new weights or drafter, or "n/a": n/a, no weights in this change. The decoder holds no code of the DFloat11 project.

The gate of #3649, item by item.

  • Every decoded tensor byte-identical to the plain checkpoint's, by hash, for every coded tensor of a real checkpoint: 150 of 150 (Exactness above).
  • Replies token-equal to the plain checkpoint, drafted and plain: yes on CUDA (Tokens above). On more than one backend: not here.
  • A malformed or truncated file refused with a clear error, bounds on every table, position and gap, tests built from damaged files: the decoder's tests (a stream of the wrong length; shapes of sign_mantissa, gaps and output_positions; positions that do not count the blocks; tables that are not a tree of at most four levels; a code with no length or the wrong depth; a gap that names another offset; split positions out of order; an output of the wrong size; random single-byte changes), and the reader's (a damaged group gives the decoder's refusal by name and holds nothing, and the other group still reads).
  • Load time and peak host memory, main against head, with and without coded tensors: the table and "What it costs".
  • A checkpoint with no coded tensor loads no slower than on main: not shown to that precision. 115.5, 115.2 and 115.5 s here against 115.1 and 114.4 s on main: within 1.1 s, and every one of the three longer than both of main's.
  • An engine without the reader refuses the checkpoint by the missing tensor's name: the control.
  • DFloat11's own tensor names: luts, encoded_exponent, sign_mantissa, output_positions, gaps and split_positions under the module's name, and dfloat11_config in config.json.
  • The decoder is my own, from the format's description: below.

Checklist

  • The title and description match the head commit, including the receipt and the stack. (e5fd126b47, two commits on main at af9777b494: the change and its CHANGELOG line. The receipt's binary differs from the change's tree by the place of one test registration, under Checks.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. (The 27 tests are new files' and need only std and the fixtures beside them; each mutant fails one, under Checks. Before the change main refuses a coded folder, as the control shows.)
  • Comments and docstrings are one line. No measurements or history in the source. (lean: 221 against 221, 0 new problems.)
  • No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines. (The diff, the commits' messages and this description, searched; none.)
  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (Nothing after load changes; the lanes groups pass on the coded folder with the plain folder's counts, under Checks.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (On the coded folder: the three decode-check prompts drafted against plain, and the two long prompts cold and resumed, each with one hash. Concurrent against solo is glm-lanes-concurrent on the coded folder, under Checks; the served launches admit one stream.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (No bit changes: the decoded tensors have the plain tensors' sha256 and the replies the plain checkpoint's tokens.)
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled. (On a checkpoint that loads on main, one stream, greedy, drafts off: decode within 0.3% of main inside an expert form, and the prompts between 0.9% shorter and 0.1% longer than main's, neighbour by neighbour. On the coded folder the first request after load was 1.2% longer, under "Read with care". The widest admitted, sampled and --drafter were not measured: this changes no lane, launch or kernel.)
The format's description the decoder was written from, and where it comes from

How it came about, plainly: on 16 November 2026, before #3649 was opened, I surveyed the format from the DFloat11 project's README and two of its Python files (dfloat11/dfloat11.py and dfloat11/dfloat11_utils.py); its decode kernel (decode.cu) was never opened. The text below and a reference decoder in Python were then written from the paper and from published files read as data, without the project's source open. The Zig decoder in this pull request was written from sections 1 to 7 of the text and four small groups with their expected values, and nothing else; what its writer found unclear went back into the text. No code of the DFloat11 project is copied or adapted.

This describes how a DFloat11 (DF11) checkpoint stores BF16 weights and how to decode them, so that a reader can be
written from this text alone. Every statement below is traced to one of two sources:

  • [P] the paper: Zhang et al., "70% Size, 100% Accuracy: Lossless LLM Compression for Efficient GPU Inference via
    Dynamic-Length Float (DFloat11)", arXiv:2504.11651v3 (1 Jan 2026, CC BY 4.0): sections 2.3.1 to 2.3.3, Algorithm 1
    (Appendix D) and Appendix I.
  • [F] the files of published DF11 checkpoints, read as data: their config.json, their safetensors headers, and
    the bytes of one group (section 6 lists the repositories and revisions).

[F✓] marks a statement that is not in the paper and was settled by the experiment of section 6: decoders that do
what this text says, and nothing more, decode a published group to the source model's bytes.

1. What is coded

A BF16 value has 1 sign bit, 8 exponent bits and 7 mantissa bits [P 2.1]. DF11 codes the exponent with a Huffman
code and stores the sign and mantissa as they are [P 1, 2.3]. Nothing is lost: decoding gives the BF16 bits back.

For element i of a group, in the group's order:

  • sign_mantissa[i] is one byte: the sign in bit 7 (0x80) and the mantissa in bits 6 to 0 (0x7F) [P Alg. 1, lines 34-35; F✓].
  • the exponent is the i-th symbol of the Huffman-coded stream encoded_exponent.
  • the BF16 value is (sign << 8) | (exponent << 7) | mantissa, with sign = byte & 0x80 and
    mantissa = byte & 0x7F [P Alg. 1, line 36]. As stored BF16 it is little-endian [F✓].

2. Where it is stored

A checkpoint is a folder of safetensors files and a config.json [F].

The config has a dfloat11_config object [F]:

Key Seen Meaning
version "0.2.0", "0.5.0" the writer's version
bytes_per_thread 8 n of the paper: the bytes of the stream one thread decodes [P 2.3.2]
threads_per_block [512] T of the paper, in a list of one number
pattern_dict an object which weights are coded, and how they are grouped

pattern_dict maps a regular expression over module names to a list of member names [F]. A module whose name the
expression matches is a group. With a non-empty list, the group holds the weight of each listed member under
that module, in the list's order (for example model.layers.\d+ with self_attn.q_proj, ..., mlp.down_proj:
seven matrices of a layer in one stream [P 2.3.3]). With an empty list, the group is that module's own weight
(seen for lm_head and model.embed_tokens).

A group's tensors are named by the group's module name as a prefix [F]:

Name dtype, shape Holds
<prefix>.luts U8, (k + 1, 256) k lookup tables, then the code lengths (section 3). k from 4 to 8 seen
<prefix>.encoded_exponent U8, (E) the Huffman-coded exponents, bit-packed
<prefix>.sign_mantissa U8, (N) one byte an element; N is the group's element count
<prefix>.output_positions U8, (4 * (B + 1)) B + 1 unsigned 32-bit numbers, little-endian [F✓] (section 4)
<prefix>.gaps U8, (ceil(5 * B * T / 8)) B * T 5-bit numbers (section 4)
<prefix>.split_positions I64, (members - 1), or (0) for a single weight where the members end (section 5)

B, the number of blocks, is what output_positions says: its length in bytes over 4, less 1. The stream must agree: ceil(ceil(E / n) / T) == B [F✓]. N is at most 2^32 - 1, since positions are 32-bit. Tensors that are not coded (norms, biases) are stored under
their own names as BF16 beside the group's [F]. The member weights' own names (<prefix>.<member>.weight) are absent
from the file, and so are their shapes: the file says only how many elements each member has [F].

A group may sit in a file of its own, named after the module with dots as underscores (model_layers_0.safetensors),
or all groups in one file; the names inside are the same [F].

3. The code and its tables

The code is a Huffman code over the exponent values present, at most 32 bits a code [P 2.3.2]. It is written into the
stream most significant bit first: the first bit of a code is the highest unused bit of the current byte [F✓].

luts[0 .. k-1] are tables of 256 entries, one for each subtree of height 8 of the code's tree [P 2.3.1]. An entry
is either an exponent value, or, from 240 to 255, a pointer to another table [P 2.3.1; Alg. 1, line 15]. luts[k]
maps an exponent value to the length of its code in bits (CodeLengths in the paper) [P 2.3.1; F✓ that it is the last row].

To decode one exponent at a bit position [P Alg. 1, lines 12-19]:

  1. Take the next 32 bits of the stream as four bytes b1 .. b4, the first bit being the top bit of b1.
  2. e = luts[0][b1]. A value's depth d starts at 1.
  3. While e >= 240: e = luts[256 - e][b] with b the next of b2 .. b4, the 8 bits that follow the ones just used (not the next byte of the file), and d grows by 1. The paper writes LUT(257 - Exponent) with tables counted from 1; counted from 0 as stored, that is 256 - e, so 255 names table 1 and 254 table 2 [F✓ for 255, 254 and 253; lower pointers by the paper's rule].
  4. e is the exponent. Advance the position by luts[k][e] bits.

The tables are a tree: table 0 is the root, each pointer leads one level down and sits in one entry, and a path has
at most four tables, since a code has at most 32 bits [P 2.3.1, 2.3.2; F: true of all 130 groups of section 6]. A
value found through d tables by a real code has a code of 8(d - 1) + 1 to 8d bits, so its length L has
ceil(L / 8) == d [P 2.3.1: subtrees of height 8].

Three consequences for a writer and a reader:

  • Exponents 240 to 255 cannot be coded, since a table entry with such a value is a pointer [P 2.3.1]. A weight with
    one of them (an infinity or a NaN has exponent 255) must stay in BF16.
  • The code is not complete. In all 130 groups the lengths' Kraft sum is 1 - 2^-L, with L from 25 to 31: one
    code of L bits is nobody's [F].
  • Entries no code leads to hold any value below 240. In 15 of the 130 groups a deep table has entries whose value has a
    shorter code than the table's depth allows (a value with a 17-bit code in a table four deep, say) [F]. Those
    entries are reached only by bits that are no element's code. So the rule ceil(L / 8) == d holds for the
    elements decoded, not for every entry of the tables, and a reader checks it there. Such an entry can also hold a
    value with no code length (the paper does not forbid it), so a walk that goes past the last element can meet a
    length of 0 and must not loop on it.
  • Only tables reached from table 0 matter. A pointer can name tables 1 to 16, so at most 17 tables are ever
    reached. Rows no pointer leads to are not read and are not a reason to refuse.
  • A writer's Huffman code may not fit 17 tables. A code whose long codes begin with many different bytes wants a
    table for each of them. One real tensor (a 33,554,432-element attention matrix with 73 exponent values) gave such a
    code. A writer then needs another code for the same values: df11_enc.fitted_codes halves the counts (never below
    1. and builds the code again until its tables fit, which at worst is a flat code of 8 bits or fewer in one table.
      That tensor fits in 16 tables after it, 0.6778 of its BF16 size. How the published writer handles the case is not
      known here; a reader does not care, since any prefix code laid out in at most 17 tables decodes the same way.

4. Threads, blocks, gaps and output positions

The stream is cut into chunks of n bytes, one a thread, and the threads into blocks of T [P 2.3.2; Alg. 1, lines 2-5].
A thread decodes the codes that begin in its chunk; its last code may run into the next chunk [P 2.3.2].

  • gaps has one 5-bit number a thread: the bit offset, from the start of the thread's chunk, of the first code that
    begins in it [P 2.3.2]. The numbers are packed back to back, most significant bit first: entry j is bits
    5j .. 5j+4 of the tensor's bit string, the first of them the highest [F✓].
  • output_positions[b] is the index, in the group, of the first element block b decodes; output_positions[B] is
    N [P 2.3.2; Alg. 1, line 41; F✓]. The first is 0.

A thread starts at its gap and decodes while its bit offset is below 8 * n [P Alg. 1, lines 10-21]. The element
index of a thread's first code is its block's output position plus the number of codes of the block's earlier
threads [P Alg. 1, line 23]. So a reader can decode serially from bit 0 and ignore both arrays, by thread, or by
block: block b starts at its first thread's gap with element output_positions[b], and is independent of the others.

The gaps are redundant, and a reader holds them to the stream. The stream is one run of codes from bit 0: the
first thread's gap is 0, and where a walk leaves a thread (the bit after its last code, less 8 * n) is the next
thread's gap [F✓: 124,189 threads of the group of section 6]. A wrong gap does not always change a count: Huffman
codes fall back into step, so a walk started a bit off can decode the same number of codes with other values. A
reader therefore checks, for every thread in which an element's code begins, that the first such code begins at the
thread's gap, the first thread of each block included (by where the block before it ended). Threads after the last
element are not checked. A gap never exceeds 31, since a code has at most 32 bits and a chunk 64.

The end of the stream [F]. The stream ends on a byte boundary after the last code; in the group looked at, 7 bits
followed the last code, and they were not all zero. E need not be a multiple of n, and the threads are filled up
to a whole block: the threads past the stream's end have gap 0 and no bytes. A decoder that walks by thread therefore
reads past E (as zeros, say) and decodes things that are not elements, in the last block only: it must keep an
element only while its index is below output_positions[b + 1] [P Alg. 1, line 41, which writes only that range].
In every other block the decoded count equals the positions' step exactly [F✓]. What is decoded after the last
element is not checked: there a lookup may land on an entry no code leads to. The simplest reader stops the last
block at element N - 1; one that walks on must end a thread when it meets a value with no code length.
Two positions may be equal (a block in which no code begins, which only the last block can be).

The last element's code ends in the stream's last byte: after it come fewer than 8 bits [F: the groups decoded in
section 6]. A reader that checks this catches a stream cut short or grown by whole bytes, which the counts alone
can miss.

5. Several weights in one group

A group's elements are its members' elements, each member flattened in row-major order, one after another in
pattern_dict's order [F✓]. split_positions[j] is the element index where member j ends and member j + 1
begins; the last member ends at N [F✓]. For a single weight the tensor is empty. The positions do not decrease and
are from 0 to N; equal neighbours would be an empty member, which no file looked at has.

6. The experiment behind the [F✓] marks

  • Group: model.layers.0 of DFloat11/Qwen3-4B-DF11 at revision 618eddad93ca71dacf56cef22e69c5968357dd6e
    (model_layers_0.safetensors, 136,721,446 bytes; config version 0.2.0, n 8, T 512): k 4, E 33,159,834,
    N 100,925,440, B 8,096, seven members.
  • Source: the seven weight tensors of model.layers.0 of Qwen/Qwen3-4B, 201,850,880 bytes of BF16.
  • A decoder by thread, written from the paper's Algorithm 1 and the observations of sections 2 to 5, with every check
    of section 7, gives 100,925,440 values whose little-endian bytes are the source's seven tensors back to back, byte
    for byte; split_positions equals the members' ends computed from the source's shapes.
  • A second decoder, serial from bit 0 and blind to gaps and output_positions, gives the same bytes for the first
    3,000,000 elements. Along that walk, each of the 124,189 threads passed begins a code at the offset its gap names,
    and each of the 243 blocks passed begins at the element its output position names.
  • The tables of all 130 groups of three repositories (DFloat11/Qwen3-4B-DF11, 36 groups;
    DFloat11/Llama-3.1-8B-Instruct-DF11 at 8fcadb86deccc193f0c2f78ae1a7abc456820df5, 34;
    DFloat11/Qwen-Image-Edit-2509-DF11 at c53d7f0196e55bf3007214ac945786f5e9421004, version 0.5.0, 60), fetched
    by range: k from 4 to 8, code lengths from 2 to 31 bits, 30 to 58 values with a code; every one is a tree as
    section 3 says, and the Kraft sums and the 15 groups with odd unreached entries are the ones named there.
  • Three more groups decoded for structure alone, with sign_mantissa taken as zeros and no source model: every
    check of section 7 passes, and the last code ends 0, 6 and 2 bits before the stream's end. They are
    model.layers.22 of the Qwen3-4B repository (k 5, one of the 15), transformer_blocks.53 of the
    Qwen-Image-Edit one (k 8, version 0.5.0, 339,738,624 elements) and lm_head of the Llama one (a single weight,
    empty split_positions, 525,336,576 elements).
  • Also read, headers and config only: DFloat11/FLUX.1-dev-DF11, DFloat11/gemma-3-4b-it-DF11.

Not settled by an experiment yet: the bytes of a group other than the first against its source model, and whether
any writer uses another n or more than one number in threads_per_block.

7. What a reader must check

A file may be damaged or cut short. A reader never reads or writes outside an array. It refuses when (1 to 7 in
this order, the first that applies naming the refusal; 8 to 12 as the walk meets them):

  1. n or T is one the reader does not implement (it says which);
  2. luts is not (k + 1, 256) with k >= 1;
  3. the tables reached from table 0 are not a tree: a pointer names a table at or past k, a table is reached twice
    (or one pointer sits in two entries), or a fifth table is reached (a code past 32 bits);
  4. output_positions is not a whole number of 32-bit entries, or has fewer than two;
  5. output_positions does not start at 0, steps backward, or does not end at N;
  6. E is 0 or ceil(ceil(E / n) / T) is not B;
  7. gaps is not ceil(5 * B * T / 8) bytes (its spare bits, if any, are not looked at);

and then, walking the stream:

  1. the first thread's gap is not 0, or a thread in which an element's code begins has a gap other than where that
    code begins (for a block's first thread: where the block before it ended);
  2. an element (an index below N) decodes to a value with no code length;
  3. an element's code length L has ceil(L / 8) different from the number of tables it was found through;
  4. a block other than the last decodes a count different from its positions' step, or the last block decodes fewer;
  5. the last element's code does not end in the stream's last byte (after it, fewer than 8 bits). This is checked
    where element N - 1 is decoded, whichever block that is.

For the members: split_positions is not one fewer than the members, decreases, is negative or passes N. With the
member shapes taken from the model's own description, the reader also checks that each member's element count is
its shape's product.

A damaged byte inside the stream can still decode to other values with every check above passing, and so can a
gap of a thread after the last element: the format carries no checksum. The file's own hash is what tells.

Bizuayeu added a commit to Bizuayeu/TensorFold that referenced this pull request Nov 18, 2026
@ashhart

ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Thanks @Bizuayeu, and for answering #3649's gate item by item.

The code reads as described:

  • Plain checkpoints are untouched: without dfloat11_config, GLM's attach returns at once (cuda_dfloat11.zig). Checkpoint.find tries the stored headers first, as get did before, and nothing changes after load. No kernel and no option is added.
  • The decoder: it bounds every table, position and gap before and while it walks a stream, and the damaged-file tests refuse by name. The fixtures are small groups you encoded, not published weights.
  • Exactness: all 150 coded tensors hash to the bf16 tensors they replace, and the replies hash the same as the plain folder's, drafted and plain, cold and resumed. main refuses the coded folder by the missing tensor's name.
  • Sizes: every file stays under 600 lines (cuda_weights.zig at 594).

The one open item is #3649's "more than one backend". That is ours to settle on the issue, since only GLM on CUDA is wired here, and we'll answer there. Meanwhile, please publish the coded folder you offered, with its revision and the plain revision it was coded from. That gives a second run a fixed input.

It applies to current main as it is.

  • Synthena

@Bizuayeu

Copy link
Copy Markdown
Contributor Author

please publish the coded folder you offered, with its revision and the plain revision it was coded from. That gives a second run a fixed input.

(#3807 (comment))

Published, as a branch of the same repository:

  • coded: Bizuayeu/Sage-S2.1-Flash-Mixed-NVFP4@25897b161e65609a7341970d938703d22fa582de (branch dfloat11)
  • plain, which it was coded from: Bizuayeu/Sage-S2.1-Flash-Mixed-NVFP4@3cc01182290fd307bce365b7ce483d859413f1fa

Between the two revisions, five checkpoint files differ: config.json (it gains dfloat11_config), model.safetensors.index.json and model-shell-0000{1,2,3}-of-00004.safetensors (16.07 GB together plain, 12.16 GB coded). The branch also adds df11-manifest.json (each coded tensor's part sizes and the sha256 of the bf16 tensor it was coded from), and its card and SHA256SUMS are its own. The other 139 checkpoint files are the same blobs. This is the folder the receipt's launches read: the three machines that hold it agree on the sha256 of those six files.

The description now names the two revisions, and under "Read with care" it has a later run of the prefill comparison (six launches of each folder side by side, with the expert form pinned).

On the changelog line: after 1.2.10 this branch still merges into main (at f5765b5125) without a conflict, but its line lands inside the ## 1.2.10 section and not under the new Unreleased. I have not touched the branch. I can move the line in one commit that changes nothing else; say so if you want that rather than placing it when you land it.

@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Hi @Bizuayeu, thanks for publishing both checkpoint revisions. The coded and plain revisions and the six differing files now give a second run a fixed input, and the description names them and includes the pinned-expert-form comparison. The #3649 second-backend question is ours to settle on the issue. On the CHANGELOG line, please leave the branch as it is; we will place the entry under Unreleased when we land it. Nothing else is needed from you.

  • Synthena

Bizuayeu and others added 3 commits November 20, 2026 13:46
core: dfloat11.zig decodes one coded group, written from the format's description; dfloat11_config.zig reads
config.json's dfloat11_config (the pattern steps the published configs use, others refused by name);
checkpoint_coded.zig finds the groups in the headers, answers their members' weight names, decodes a group once and
frees it at release; checkpoint.zig's get, expect and has fall through to it. A checkpoint with no coding attached
reads as before.

glm: cuda_dfloat11.zig gives the shapes the files omit (q, k, v, o, kv_b, the embedding, the head) and attaches the
coding to the loader's two checkpoints; cuda_weights.zig's load calls it.

Refs ashhart#3649.
@ashhart
ashhart force-pushed the pr/checkpoint-dfloat11 branch from e5fd126 to 14c9aaf Compare November 20, 2026 13:46
@ashhart
ashhart merged commit 124052c into ashhart:main Nov 20, 2026
10 of 11 checks passed
@ashhart

ashhart commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Thank you @Bizuayeu. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants