Repository navigation
core: one copy of the TFQ3 records and wire constants (TFQ3 format move, piece 1) - #5281
Merged
Merged
Conversation
The TFPW header, TFPW expert record and TFPN header, and the magics, version and section and table sizes, were declared three times: Flash Next's and GLM's tfq3_check.zig and CUDA's tfq3_format.zig. They now live in core/tfq3_format.zig, wired into every module by zig/build/tfq3_format.zig like bf16_round. Each backend keeps its public names as aliases, its constants' types, its TFPN tensor record and every check; test-tfq3-format pins the records' offsets and bytes.
ashhart
force-pushed
the
core-tfq3-format
branch
from
November 27, 2026 03:50
2ee35c5 to
cbb0a01
Compare
Owner
|
Thank you @jschmied. 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. |
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.
Head:
2ee35c56a5on main93dd46c33c.TFQ3's file format lives in three copies today:
families/flashnext/tfq3_check.zig(Metal Flash Next),families/glm/tfq3_check.zig(Metal GLM) andcuda/tfq3_format.zig(#4986). This is the first piece of moving itinto one core module, on the #2118/#4860 terms: one piece per PR, nothing a user sees changes.
This piece moves only what the three copies already agree on byte for byte:
LayerHeader(TFPW),ExpertMetaandNonMoeHeader(TFPN);They now live in
zig/src/core/tfq3_format.zig, a std-only file with one module owner.zig/build/tfq3_format.zigwires it into every module the build compiles, the same way
zig/build/bf16_round.zigdoes, frombuild.zigand fromproduct.zig(-Dgpu). Every backend keeps each public name as an alias, including the CUDA names (TfpwHeader,TfpnHeader,TfpwExpertMeta,magic_tfpw,tables_min_bytes) and the type of each constant (CUDA'ssection_alignstaysu64, GLM's staysusize). No caller changes, and no check, loader, kernel or refusal changes.Left in place on purpose:
R/CandnameSlice(*const). CUDA's hasr/candnameSlice(*align(1) const), which it needs because it borrows names out of unaligned views. One alias can't keepboth field APIs.
NonMoeLayoutdown (line 166 on main) is untouched. cli: add tensorfold tfq3 MODEL subcommand for TFQ3 conversion and inspection #5018 rewrites that part. Its CLI imports GLM'srecord names through the
glm_tfq3_checkshim, and those names are still there.Where the copies disagree (each backend keeps its own rule; unifying any of these is its own issue)
R/C(GLM) vsr/c(CUDA), and thenameSlicereceiver alignment.UnsupportedQuantization/Tfq3*. CUDA usesInvalidTfq3Shard,InvalidTfq3Tables,MisalignedTfq3TensorandTfq3LayerMismatch, and its TFPN/TFPW header arithmetic can raisestd's
error.Overflow.Tfq3Tablebefore it reads the magic. GLM gives
Tfq3Truncatedunder 8 bytes, thenUnsupportedQuantization, thenTfq3Table. CUDA checks the length first and calls every faultInvalidTfq3Tables. Example from codex: an 8-bytehead with a bad magic and file_len 8 gives
Tfq3Table,UnsupportedQuantizationandInvalidTfq3Tables.num_tensors == 0and an empty tensor name (Tfq3Geometry); CUDA admits both.mappedLen), andsections are pairwise disjoint and off the header.
mapping rule.
off_metaoff the record's 8-byte alignment. Flash Next and CUDA don't; CUDA readsthe records
align(1).Tfq3Layer.Tfq3Layer), then the fixed 4096/2048.Tfq3LayerMismatch.num_tensorsis not checked.matWords = floor(R*C*b/32)with overflow refusals. CUDA usestensorWords = (R/16)*(C/128)*(2b)*32in u64. They agree whenever R % 16 == 0 and C % 128 == 0 (every shape thevalidators admit) and differ elsewhere (R=17, C=129, b=4: 274 vs 256, from codex). Scales: GLM uses a checked
Error!usize, Flash Next a plainusize, CUDA u32 to u64.bad_name).layer_NN/mtp_00, checks every shard present, and refuses shards thathave no table.
*.tffpwsorted and probes a header count (hasRecords); a table alone never selects TFQ3.canonicalNameexists only in CUDA (its tensor lookup), and only CUDA hasvalidBits.Evidence
test-tfq3-format(new,zig/src/core/tfq3_format_test.zig) pins every field's offset and size, each record'ssize and alignment, the magics' spelling and the sizes. It also checks one numbered record of each kind against
main's bytes as hex.
gate_sc_offandup_sc_offswapped inExpertMeta(same size, so everyvalidator on main still passes),
test-tfq3-formatfails "every record's fields sit where main's three copies put them" (3/4 passed, 1 failed). Restored, it passes again.test-glm-tfq3-host,test-flashnext-memory-host(Flash Nexttfq3_check_test.zig, the sidecar scan),test-flashnext-load-admission,test-cuda-tfq3-hostandtest-cuda-host(tfq3_formatandtfq3_lifecycle_test).One build on the GB10 (aarch64, head
2ee35c56a5): 527/527 steps, 10,038/10,086 tests passed (48 skipped).cbe8769e, merged onto this branch for review only (not pushed): the merge is clean, andtest-tfq3-host test-glm-tfq3-host test-tfq3-format test-flashnext-memory-hostpass. Mergecaf4f5d2a3: 17/17 steps, 62/62 tests.-Dfixed-cpu, full CI set,--final, head2ee35c56a5):test-host test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths: 2680/2680 steps, 28,647/28,828 testspassed (181 skipped);
check-native-cuda-host compile-cuda-tests: 21/21 steps. X86-ALL-GREEN.zig fmt --check,tools/pr_check.py0 errors (lean 123 vs 123, 0 new; import-cycle edges 24 vs 24), andgit diff --check.Not run, and why:
the host fixtures above are the comparison against main.
extern structs at the sameoffsets, and every use site resolves to the same type.
.cu/.cuhfile and no kernel source is in the diff.through the same host roots above.
Next pieces (each its own PR, in this order)
matWords/matScales/tensorWords/validBits, the 16 B predicate), each signature and domain keptby name.
tfq3_files, CUDAlistShards/hasTables/hasRecords).After cli: add tensorfold tfq3 MODEL subcommand for TFQ3 conversion and inspection #5018 lands, the per-kind walkers move only once one rule has been picked for each disagreement above.
Proposed CHANGELOG line (Unreleased): Internal: the TFQ3 file records and wire constants live once in
core/tfq3_format.zigfor theCUDA, Metal Flash Next and Metal GLM backends; nothing a user sees changes.
The split, the decision to keep the TFPN tensor record in two copies, the product-mode wiring and the #5018
integration check came from a review with codex.