Repository navigation
core: a Checkpoint reads bf16 weights stored in DFloat11's lossless form, decoded at load; GLM on CUDA attaches it - #3807
Conversation
|
Thanks @Bizuayeu, and for answering #3649's gate item by item. The code reads as described:
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.
|
Published, as a branch of the same repository:
Between the two revisions, five checkpoint files differ: 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 |
|
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.
|
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.
e5fd126 to
14c9aaf
Compare
|
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. |
A
Checkpointreads a bf16 weight stored in DFloat11's lossless form (#3649):get,expectandhasanswer 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, plainloaded in(s)RssAnon, rank 0 / rank 1 (GiB)VmHWM(GiB)fibonacci-raw, expert form factored (tok/s)fibonacci-raw, expert form classic (tok/s)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:
mainplain, branch plain, branch coded,maincoded (the control below), branch coded, branch plain,mainplain, branch coded,mainplain, 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_sha256of 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-digittoken_shaand the reply'soutput_sha256.mainon plain, the branch on plain and the branch on the coded folder agree on all ten, across both expert forms.The control.
mainrefuses 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
MemAvailableon 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.RssAnonandVmHWMare read from the engine's/procstatus every 0.5 s on both hosts. On the plain checkpoint this branch's three loads are each longer thanmain's two, by 0.1 to 1.1 s (0.1 and 1.1 s neighbour by neighbour); twomainlaunches do not say whether that is the branch.Read with care.
main), and 26.02 (main) against 26.04 (branch, plain).TF_GLM_EXPERT_FORM=factoredso 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.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
main(af9777b494), two commits: the change (2b8ed8fe64) and its CHANGELOG line (e5fd126b47).atc overlap --base origin/main --json: on 2026-11-18 at 12:43 UTC, againstmain(8cbef9777b), which this merges into without conflicts: no open pull request in the result shares a file with it. The result says it is incomplete (otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit). Beyond it, by hand, among the 300 most recent open pull requests: glm cuda: a dense MLP stored bf16 is read as bf16 in any checkpoint, not only an EXL3 one #3680 and cuda families: refuse a token id at or past the embedding table before the lookup #3044 (draft) changecuda_weights.zig, and zonos3: ZONOS3 Mini text to speech on Metal (stacked on #3720) #3732, zonos3: ZONOS3 Mini text to speech on CUDA (voices, reference codes, cloning from a clip) #3720, core: Drama 3's torch.save reader and WAV code move to core (torch_pth, torch_zip, wav) #3719, core/quant: a GPTQ reader for AutoGPTQ v1 group 128 symmetric weights #3611, kolibri1: the published EAGLE-3 drafter behind --drafter on CUDA (don't land yet: 8 streams and cold prompts slower) #3590, Native SAM3/SAM3.1 segmentation on Metal #3372, lane host: --stall-seconds marks a stalled engine unavailable, --stall-exit restarts it #3165 and speech: wav24, wav32f and FLAC replies, a sample_rate and stereo, each opt-in per request #3138 changecore/root.zig; merged with each of those ten heads, this conflicts in no file it touches. glm cuda: a dense MLP stored bf16 is read as bf16 in any checkpoint, not only an EXL3 one #3680 adds one line at the end ofcuda_weights.zig's test imports, so this branch's line there sits two lines higher and the two merge cleanly in either order (594 lines after this one, 595 after both, under the 600 limit). None of the existing code files this touches changed onmainsince the base. The result was taken on2b8ed8fe64; the CHANGELOG line added since sits away frommain's new lines and from glm cuda: a dense MLP stored bf16 is read as bf16 in any checkpoint, not only an EXL3 one #3680's line, and merges cleanly with both.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'sdfloat11_configsays 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).attachfinds the groups in the headers and lists their members' weight names (<module>.weight, or<module>.<member>.weightfor a group of several).get,expectandhasfall through to that list when the name is not in a header. A group is decoded once into a 64-byte-aligned buffer thatrelease()andclose()drop.attachrefuses 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, soexpectuses the caller's andgetasks the family (CodedShapeUnknownwhen it has none).GLM on CUDA (
families/glm/cuda_dfloat11.zig, two lines incuda_weights.zig). The shapes of the names its loader takes withget(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_configtakes no new path.Limits.
split_positionsafter 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 emptysplit_positionsare listed first as well.Checks on this head
e5fd126b47. It adds the CHANGELOG line to2b8ed8fe64and changes no code, so the tests and the receipt, taken on2b8ed8fe64, were not taken again. The receipt's binary was built from2b8ed8fe64'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 atestblock and is not compiled into the engine, so the receipt was not taken again.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.2b8ed8fe64's tree:zig build test3,294 of 3,339 with 45 skipped (730 of 730 steps),test-golden(5 of 5 steps),test-cuda-host7,161 of 7,194 with 33 skipped (418 of 418 steps),compile-cuda-tests10 of 10,compile-config-server7 of 7,tools/zig/cuda_common_check.pyandzig 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_projandq_projagainst 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 aclang++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.Zig format(fmt) andNo GPUsucceeded:zig,zig-b,zig-windows,zig-macos-dev-tools,pytest,release-pathsand bothbenchmark-clientsjobs; the twohost-nightlyjobs were skipped. The first push'sNo GPUrun was cancelled by the second push.tf-cuda-testbuilt beside the receipt's binary from the same tree: on the coded folderglm-lanes-covergives 46 PASS,glm-lanes-concurrent38 PASS andglm-shared-check1 PASS on rank 0, with 0 FAIL andexit 0on both ranks; the plain folder it was coded from gives the same counts with the same runner. (Run after this was opened.)Receipt
core'sCheckpoint, 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.dfloat11_configchooses.mainaf9777b494and 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 isBizuayeu/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, 12kv_b, the embedding and the head) each rewritten as one DFloat11 group under DFloat11's tensor names, with adfloat11_configof one pattern a module; the vision tower and the bf16 tensors that are not a.weightstay 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 asBizuayeu/Sage-S2.1-Flash-Mixed-NVFP4@25897b161e65609a7341970d938703d22fa582de(branchdfloat11), beside the plain revision it was coded from; the script is not published.core'sCheckpoint(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.tools/bench_concurrent.py --alone --serialortoken_shaagainst"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 insign_mantissaorencoded_exponentgives other bytes, and one flipped ingapsorlutsis refused. The decoder also gives one published group's source bytes:model.layers.0ofDFloat11/Qwen3-4B-DF11@618eddad, seven weights ofQwen/Qwen3-4Bin one group, 201,850,880 bytes.tools/bench_openai.py: its two prompts with"draft": falsein 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 thanmainin the factored form and 0.1% slower in the classic one.ttft_sfromtools/bench_cache.py --require-cold, on the decode-check prompts' tokens repeated to 9,600 and 38,400: the table and "Read with care".The gate of #3649, item by item.
sign_mantissa,gapsandoutput_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).mainagainst head, with and without coded tensors: the table and "What it costs".main: not shown to that precision. 115.5, 115.2 and 115.5 s here against 115.1 and 114.4 s onmain: within 1.1 s, and every one of the three longer than both ofmain's.luts,encoded_exponent,sign_mantissa,output_positions,gapsandsplit_positionsunder the module's name, anddfloat11_configinconfig.json.Checklist
e5fd126b47, two commits onmainataf9777b494: 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.)stdand the fixtures beside them; each mutant fails one, under Checks. Before the changemainrefuses a coded folder, as the control shows.)"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 isglm-lanes-concurrenton the coded folder, under Checks; the served launches admit one stream.)--drafter, no slower than without it, greedy and sampled. (On a checkpoint that loads onmain, one stream, greedy, drafts off: decode within 0.3% ofmaininside an expert form, and the prompts between 0.9% shorter and 0.1% longer thanmain'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--drafterwere 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.pyanddfloat11/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:
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.
config.json, their safetensors headers, andthe 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
iof 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✓].i-th symbol of the Huffman-coded streamencoded_exponent.(sign << 8) | (exponent << 7) | mantissa, withsign = byte & 0x80andmantissa = 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_configobject [F]:version"0.2.0","0.5.0"bytes_per_thread8nof the paper: the bytes of the stream one thread decodes [P 2.3.2]threads_per_block[512]Tof the paper, in a list of one numberpattern_dictpattern_dictmaps a regular expression over module names to a list of member names [F]. A module whose name theexpression matches is a group. With a non-empty list, the group holds the
weightof each listed member underthat module, in the list's order (for example
model.layers.\d+withself_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_headandmodel.embed_tokens).A group's tensors are named by the group's module name as a prefix [F]:
<prefix>.luts(k + 1, 256)klookup tables, then the code lengths (section 3).kfrom 4 to 8 seen<prefix>.encoded_exponent(E)<prefix>.sign_mantissa(N)Nis the group's element count<prefix>.output_positions(4 * (B + 1))B + 1unsigned 32-bit numbers, little-endian [F✓] (section 4)<prefix>.gaps(ceil(5 * B * T / 8))B * T5-bit numbers (section 4)<prefix>.split_positions(members - 1), or(0)for a single weightB, the number of blocks, is whatoutput_positionssays: its length in bytes over 4, less 1. The stream must agree:ceil(ceil(E / n) / T) == B[F✓].Nis at most2^32 - 1, since positions are 32-bit. Tensors that are not coded (norms, biases) are stored undertheir own names as BF16 beside the group's [F]. The member weights' own names (
<prefix>.<member>.weight) are absentfrom 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 entryis 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 (
CodeLengthsin 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]:
b1 .. b4, the first bit being the top bit ofb1.e = luts[0][b1]. A value's depthdstarts at 1.e >= 240:e = luts[256 - e][b]withbthe next ofb2 .. b4, the 8 bits that follow the ones just used (not the next byte of the file), anddgrows by 1. The paper writesLUT(257 - Exponent)with tables counted from 1; counted from 0 as stored, that is256 - e, so 255 names table 1 and 254 table 2 [F✓ for 255, 254 and 253; lower pointers by the paper's rule].eis the exponent. Advance the position byluts[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
dtables by a real code has a code of8(d - 1) + 1to8dbits, so its lengthLhasceil(L / 8) == d[P 2.3.1: subtrees of height 8].Three consequences for a writer and a reader:
one of them (an infinity or a NaN has exponent 255) must stay in BF16.
1 - 2^-L, withLfrom 25 to 31: onecode of
Lbits is nobody's [F].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) == dholds for theelements 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.
reached. Rows no pointer leads to are not read and are not a reason to refuse.
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_codeshalves the counts (never belowThat 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
nbytes, one a thread, and the threads into blocks ofT[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].
gapshas one 5-bit number a thread: the bit offset, from the start of the thread's chunk, of the first code thatbegins in it [P 2.3.2]. The numbers are packed back to back, most significant bit first: entry
jis bits5j .. 5j+4of 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 blockbdecodes;output_positions[B]isN[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 elementindex 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
bstarts at its first thread's gap with elementoutput_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 nextthread'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.
Eneed not be a multiple ofn, and the threads are filled upto 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 anelement 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 memberjends and memberj + 1begins; the last member ends at
N[F✓]. For a single weight the tensor is empty. The positions do not decrease andare from 0 to
N; equal neighbours would be an empty member, which no file looked at has.6. The experiment behind the [F✓] marks
model.layers.0ofDFloat11/Qwen3-4B-DF11at revision618eddad93ca71dacf56cef22e69c5968357dd6e(
model_layers_0.safetensors, 136,721,446 bytes; config version 0.2.0,n8,T512):k4,E33,159,834,N100,925,440,B8,096, seven members.weighttensors ofmodel.layers.0ofQwen/Qwen3-4B, 201,850,880 bytes of BF16.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_positionsequals the members' ends computed from the source's shapes.gapsandoutput_positions, gives the same bytes for the first3,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.
DFloat11/Qwen3-4B-DF11, 36 groups;DFloat11/Llama-3.1-8B-Instruct-DF11at8fcadb86deccc193f0c2f78ae1a7abc456820df5, 34;DFloat11/Qwen-Image-Edit-2509-DF11atc53d7f0196e55bf3007214ac945786f5e9421004, version 0.5.0, 60), fetchedby range:
kfrom 4 to 8, code lengths from 2 to 31 bits, 30 to 58 values with a code; every one is a tree assection 3 says, and the Kraft sums and the 15 groups with odd unreached entries are the ones named there.
sign_mantissataken as zeros and no source model: everycheck of section 7 passes, and the last code ends 0, 6 and 2 bits before the stream's end. They are
model.layers.22of the Qwen3-4B repository (k5, one of the 15),transformer_blocks.53of theQwen-Image-Edit one (
k8, version 0.5.0, 339,738,624 elements) andlm_headof the Llama one (a single weight,empty
split_positions, 525,336,576 elements).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
nor more than one number inthreads_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):
norTis one the reader does not implement (it says which);lutsis not(k + 1, 256)withk >= 1;k, a table is reached twice(or one pointer sits in two entries), or a fifth table is reached (a code past 32 bits);
output_positionsis not a whole number of 32-bit entries, or has fewer than two;output_positionsdoes not start at 0, steps backward, or does not end atN;Eis 0 orceil(ceil(E / n) / T)is notB;gapsis notceil(5 * B * T / 8)bytes (its spare bits, if any, are not looked at);and then, walking the stream:
code begins (for a block's first thread: where the block before it ended);
N) decodes to a value with no code length;Lhasceil(L / 8)different from the number of tables it was found through;where element
N - 1is decoded, whichever block that is.For the members:
split_positionsis not one fewer than the members, decreases, is negative or passesN. With themember 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.