Repository navigation
Conversation
|
@BadAd84 @ashhart I reproduced the documented host check on I confirmed both conflicts against That is a tested host-side route through the two conflicts. The merged CUDA control image still needs its nvcc build and device run. Igor Lessio - AIFLOW LABS |
|
The kernel arithmetic looks sound, and this leaves every current serving path unchanged. It still needs changes before landing. Please rebase onto current main and resolve the control-image, CUDA-root, limits-image and generated-pin conflicts, preserving the newer registrations and regenerating pins from the actual merged bytes. Also add gates 1–4 and byte-replacement coverage for the compiled prompt-down BF16 form, and either add the missing dense-FP32 contract case or narrow that public wrapper to BF16 ( The receipt's filtered command ran zero kernels, while the useful standalone verb was an uncommitted local edit. Please commit a real
|
582994e to
5aced6d
Compare
|
The refreshed zig build test-int4-host test-gradient-serving test-environment-host \
-Dcpu=apple_m1 -j3 --summary all
zig build compile-cuda-tests -Dtarget=x86_64-linux -j3 --summary allThe environment target reports the same failure on the trial and on main alone: the inventory expects 24 Flash Next switches and finds 25. For the remaining contract work, Igor Lessio - AIFLOW LABS |
…LM head fn_int4.cu multiplies AutoGPTQ v1 weights as stored: a code enters the bf16 MMAs as itself, a group's products run in one fp32 MMA chain and the groups add with fmaf in group order, so a row's bits depend on its own inputs and weights alone. cuda/int4.zig packs the qweight words and fp16 scales for it and launches its three epilogues (gate/up with SwiGLU, down to fp32 and bf16), the head's dense rows and the two prompt forms. A host test pins the packer against the stored codes and the binary64 reference, and the kernel-contract suite runs every form at the checkpoint's shapes with two planted controls and a plan whose shared expert's slot is skipped. The kernel is MiaAI-Lab's dual-Spark recipe at 04f2b53826, patches/0002-kernels.patch, Apache-2.0; TensorFold's two changes are marked TF and recorded in THIRD_PARTY_NOTICES.md. The settings the recipe read are dropped with the family's caller, and the groups-of-64 instantiations a two-rank serve would need are not built. No family loads it yet, so every checkpoint served today takes the path it took before. The device run and the compiled-limit receipts are pending a GPU window.
…te 4's provable margins The int4 suite failed three gates and two checks of its own on the device. Each cause was in the test, none in the kernel: - The skipped-slot check judged bytes: an all-live row whose correct bf16 value holds a 0xff byte read as a row the skip run had written. It judges rows now: the skip run leaves all of a skipped pair's bytes at 0xff, and the all-live run wrote the row. - The unshuffled head was registered as an eighth kernel, so gate 3's expected failure counted as a gate failure. It is a control at gate 3, which the pull request's body and docs/kernel-contract.md already said it was. - Gate 3: the declared bound counts fn_int4.cu's three bf16 roundings at the output's size, but the kernel rounds the gate sum, the up sum and silu each at its own size, and a rounded gate sum reaches the output through silu's slope times the up value. At 64x640x128 that came to 1.04 of the bound. zig/tests/cuda/int4_ref.zig derives every output's allowance from its own terms: both fp32 sums through silu's slope over the rounding's interval, the three bf16 roundings and the store at their own values, and expf's fp32 overflow, where the kernel's silu is 0 and float64 keeps a denormal-sized value. Checked against the kernel's own arithmetic on 40,000 outputs at k 128, 256 and 2,560, the derived allowance holds at 0.74 to 0.87 of itself where the generic formula is short by up to 75x; its test holds 4,000 epilogue draws inside it and requires the generic bound to be short on some of them. - Gate 4: a mirrored row's terms cancel in pairs, so its total is small and a low-precision chain loses the whole of it; how far depends on the chain's partial sums, which scale with the inputs. At 4 to 508 the f16 chain of the down's bf16 output missed by only 85x of a one-unit bound. The cancelling inputs now carry 8 to 2,040, and the eight nudged ones stay at 4 to 16, where the mirror's nudge 4 is exact in bf16: a chain's partial sums reach 2^19 to 2^21 while a row's total stays below 2^24, so fp32 sums remain exact in any order and the f16 proof grows with the partials' ulp. - Gate 4's bf16 proof of a bf16 SwiGLU output cannot pass 1 / (4.1 u) = 62x: a mirrored row cancels exactly in the halves order, so a low-precision sum's largest miss is `want` itself, and the epilogue's three bf16 roundings and the store already allow 4.1 u of it. The registration states 60 with that arithmetic in its `why`. nvcc 13.3's usage of the 21 int4 launches joins measurements/pending_133.zig, as docs/kernel-contract.md keeps each later release's receipts apart from 13.0's; a 13.0 record stays pending.
…come from common/ The shared cuda_common_check rejects local copies of these primitives. The kernel now includes common/cp_async.cuh and common/qmm_frag.cuh and calls their forms, whose instruction text is the one the file carried: cp.async.cg with the source-size operand, commit_group, wait_group, ld.global.nc.L1::no_allocate.v4.u32 and mma.sync m16n8k16 bf16. The header and THIRD_PARTY_NOTICES.md state the change.
5aced6d to
d1d763c
Compare
|
Thanks @BadAd84 for the int4 W4A16 kernel and the detailed derivation. One thing before this can land: gate 3 failed on device at 1.04 of its bound, and the next commit adds a per-output allowance and a custom bf16 margin of 60. Our contribution guide asks that tolerances are not loosened after seeing results, so could you show these limits follow from the arithmetic alone, independent of the failing run, with a control that still goes red? We'll review the bound once that evidence is here.
|
kernel-contract's WORD filter selects registered kernels, and no int4 kernel is registered there, so a filtered run over this family gated nothing. The verb runs contract_int4.run on the built runner, the build step runs the runner with it, and the usage text and the contract's page name it. Its summary counts the suite's registrations: each form a kernel, each control at its own gate.
…ts arithmetic pinned gateUp added gamma(depth) times a magnitude on top of an epilogue line that already carries both sums' error inside dg and du. That line was a second count of the same error: on the fixture's term magnitudes it made the allowance a median 11 percent looser at the served width (50 percent on some outputs), 2 percent at k 640 and under 1 percent at k 256 and below. It is removed, and the up's line is (s + d dg) du, so the cross term of the gate's and the up's errors is covered by name. The allowance is now the epilogue's worst case term for term: at the served width it is 1.05 to 1.09 times the generic bound by median for a gate above 1 (the up sum's error through silu, which the generic magnitude never had) and smaller for a gate below 0. Three host tests pin what no device run moves: a stated gate (g -10.53, u -28.75, exact sums) lands the epilogue at 2.15 times boundExact and at 0.66 of the derived allowance, and the gate's bf16 rounding alone past boundExact; the exact-sum allowance is 4.039307 u on every stress sum of the form, so 63.38 is the most provable bf16 margin and 100 is past it; and the planted faults are outside the allowance on seeded draws. Gate 4's margin text states that exact-sum allowance (4.0393 u, 63.4x) where it rounded it up to 4.1 u.
…lar model, and the allowances derived The gate/up form's allowance is derived and gate 4's bf16 margin for the form is 60, so the form carries controls that must go red under both. The controls image's tf_ctl_int4_swiglu is the form as one thread an output and a block row a pair. At fault 0 it is fn_int4.cu's epilogue on fp32 sums, registered as a kernel: it passes gates 1 to 4, so a control's red is its fault alone. At fault 1 it takes silu of the up sum times the gate sum, and at fault 2 it cuts gate, up and silu toward zero where the kernel rounds to nearest; both are red at gate 3. At fault 3 it rounds each group's sums to bf16, red at gate 4. The cut control is one rounding mode from the kernel: its four errors all shrink the output, each by up to twice the unit the allowance grants that rounding. docs/int4-contract-allowances.md derives the allowance term by term from the kernel's arithmetic, names the generic bound's two gaps with a stated gate, and derives gate 4's ceiling: a bf16 sum that returns 0 misses by want itself, which is 1 / (4.0393 u) = 63.38 times the exact-sum allowance, so 100 asks for a miss larger than the output and 60 is the largest multiple of 10 under it. Each control's fault is derived there too. The contract's page lists the verb's suite, the model and the five controls, and links the derivation.
|
Thanks for the re-cut! I have read the head at The head already carries the kernel and its launches ( On top of that head I have one branch, three commits, local only. It keeps to the bound question. The allowance stops counting the sums' error twice. Gate 4's margin is derived. On the stress sums the exact-sum allowance is The gate/up form now carries controls that must go red under that allowance.
The prompt-down BF16 gate coverage and the dense wrapper narrowing from the earlier review are not in this head, and this branch keeps to the bound question. I am not claiming them here. The arithmetic and its host tests are in the branch. The compile, host and device lines are queued with the GPU window, so I am not quoting a summary or a control line yet. I will post the |
|
Both limits follow from the kernel's arithmetic, and neither needed the failing run. The full derivation is on the branch now: Head is The gate/up allowanceThe kernel rounds the gate sum, the up sum and silu to bf16 before the store. An output's allowance is the worst case of that arithmetic, term by term:
The constants are The generic bound is not a bound for this epilogue. It counts the 3 roundings at the output's size, but the gate is rounded at the gate's size, and that rounding reaches the output as With exact sums and no device, at Where the generic bound was sound, the allowance matches it. For a gate above 1 it is 1.05 to 1.09x the generic bound at the served width, all of it the up sum's error. For a negative gate it is smaller, by orders of magnitude at the served width. 1 correction to the allowance commit, in the stricter direction. Its The 1.04It is the generic bound meeting 1 output. It is not the kernel. The first commit's tree, rerun with only the verb's dispatch added, prints the same line: That output has With the first commit's bound back in force over the whole suite, that is the only output over it: 1 of 2,296,320 across the 20 shapes of the 2 gate/up kernels. Under the derived allowance none is. It showed at
The kernel's bytes are its epilogue. The epilogue evaluated in float64 at float64's own sums gives the kernel's exact bytes on all 245,760 outputs of that shape, and on 499,190 of the 499,200 outputs of the two kernels at The epilogue's scalar model, a different summation with the same roundings, passes gate 3 on every shape with a worst of 0.803 of the allowance. It is inside the first commit's bound on every shape as well: Gate 4's bf16 marginOn the stress rows the exact-sum allowance for this epilogue is A bf16 sum that returns 0 misses by the output itself, which is So 63.38 is the most any mirrored input can prove of a bf16 SwiGLU output, and 100 asks for a miss of 1.57x the output. The device prints 63x under this allowance, and printed 63.812 under the first commit's ControlsAll 4 new entries are the gate/up form as 1 scalar kernel in the controls image,
Both gate 3 controls cross the first commit's bound as well. With that bound in force the cut epilogue is outside it on 156 outputs at The 2 earlier controls are unchanged: Receipt
The whole run's verdict is |
|
Thanks @BadAd84. The negative-gate example explains why the generic bound can reject this epilogue, and the stress arithmetic supports a margin near 63× rather than 100×. I reviewed The earlier BF16 prompt-down byte comparison and dense-FP32 coverage or wrapper narrowing also remain open. The focused entrypoint is absent from the reviewed tree. The kernel preserves the stored codes and scale bits, and no serving caller selects it yet. The disclosed recipe import also needs a provenance decision before landing.
|
|
5060 Ti (sm_120) kernel-contract 1. The suite is unreachable by filter. 2. Every launch record is a placeholder.
rc=1 is the limit-problem exit; no gate spec was exercised by this filter. |
|
Thanks @BadAd84 for the arithmetic explanation, and @joshuaswarren for the focused check. The PR still has the older head, so the corrected formula, new SwiGLU controls and standalone entrypoint remain unreviewable until those commits are pushed. BF16 prompt-down comparison and dense-FP32 coverage or wrapper narrowing remain open too. Please retain the complete summary and every control result with the updated head. The filtered command does skip int4 correctness checks. One distinction on the limits result: this tree has all 21 nvcc 13.3 overrides in The stored GPTQ build is fine as loaded, but error bounds do not replace bit-exact serial arithmetic and byte comparisons. The disclosed recipe import still needs a provenance decision. Integration conflicts are mechanical and remain on our side.
|
… reach the filter Every fn_int4 record now holds the usage nvcc 13.0.88 measured on sm_80, sm_86, sm_89, sm_120 and sm_121: registers and static shared bytes from ptxas -v, the launch bound from each cubin's EIATTR_MAX_THREADS. The 12 launches nvcc 13.3.73 compiles differently carry that compiler's values as the 13.3 set, and the duplicate receipts leave pending_133, so gate 5 has a measurement on every recorded SM instead of five "no compiled usage recorded" findings a launch. The int4 gate registrations join kernel-contract's filtered list, so kernel-contract int4 selects them; the plan's skipped-slot check and the suite verb move to contract_int4_run.zig, which keeps contract_int4.zig under the 600-line rule. Two coverage entries are new: the bf16 prompt down against the paired form's bytes, and the LM head to fp32, the two paths the review named.
The split moved the skipped slot's check into contract_int4_run.zig, which reads grouped, the spec alias and the suite's dims and width; name them there and publish the two shapes from contract_int4.zig, so the runner compiles again.
The file split moved the suite verb to contract_int4_run.zig but left two references on the old names, so the runner did not compile: zig/tests/cuda/main.zig:331: error: root source file struct 'contract_int4' has no member named 'run' zig/tests/cuda/contract_int4_run.zig:62: error: 'launch' is not marked 'pub' main.zig's int4-contract dispatch now imports the run file, and Fixture.launch is pub because the skipped-slot check calls it from that file.
|
Thanks @BadAd84. The corrected allowance, derivation, nonlinear controls, BF16 prompt-down comparison and dense FP32 case are now present. The compiler-specific records and filtered registration are present too. The runner split has two compile blockers: the dispatcher still calls One question on provenance: the notice says
|
|
On provenance:
So the kernel is MiaAI-Lab's file, as the notice says: Apache-2.0, Copyright 2026 MiaAI-Lab, with three of our changes marked in it and recorded. If that separation is not enough for you, we will rewrite it from TensorFold's own specification with the reference closed: a machine that has never held this tree, an agent given the GPTQ group-128 format, the required shapes and the exactness gates and nothing else, and the result arrives as a new commit for review. |
|
Thanks @BadAd84. Both runner references are fixed, and the corrected allowance, nonlinear controls, BF16 prompt-down and dense FP32 cases remain present. Your explanation also answers the origin question; please keep the attribution. Before landing, we still need the complete updated-head gate summary and every control result, including the BF16 prompt-down byte comparison. Error bounds do not replace those exact comparisons. The main integration conflicts remain ours.
|
Terms used below: "the base" is upstream
mainat7d4a77aa5bfa14deffaa18a7ce31bd8a0dffaca8, which carries the GPTQ reader of pull request #3611 (merged as51a108030,fe3622b72,08540d797andda8e4444b), and "the branch" is that base merged with the three commits this pull request adds, whose head is named below.What this changes
Before, TensorFold on CUDA could read AutoGPTQ weights with the base's reader (
zig/src/core/quant/gptq.zig,merged as #3611) and multiplied none of them as stored:
git grep -l fn_int4 7d4a77aa5bfa14deffaa18a7ce31bd8a0dffaca8 -- ziglists no file. After,zig/kernels/cuda/fn_int4.cumultiplies them as stored andzig/src/cuda/int4.zigpacks and launches it. No family loads the module yet, so every checkpoint served today takes the path it took before; the caller is step 5 of the same order, and the kernel's contract suite is the only thing that runs it here.mainat7d4a77aa5bfa14deffaa18a7ce31bd8a0dffaca8(changelog: each line once under Unreleased). The branch is this change's two commits on32c4e3d8fe7b696de738839a0cf1d8cc596c80fe, the twosigned merges of
main:fa7d93d9aford796b267e6f535a4819cf049c1aa034288611209and73a3d618bfor7d4a77aa5bfa14deffaa18a7ce31bd8a0dffaca8, and one commit after them,582994e22(fn_int4.cu: the mma, the non-allocating load and the cp.async copies come from common/). The GPTQ reader this kernel packs is merged(core/quant: a GPTQ reader for AutoGPTQ v1 group 128 symmetric weights #3611,
51a108030,fe3622b72,08540d797,da8e4444b), so the branch is cut frommainitself and needs noparent pull request: the reader owns the layout constants this kernel packs (
zig/src/core/quant/gptq.zig'sgroup = 128andzero_nibble = 7), and nothing else is needed to apply the branch. The second merge conflictedin exactly one file,
zig/kernels/cuda/contract_controls_set.cu, where both sides appended an include to the sameimage list (main's
contract_embed_controls.cuh, this change'scontract_int4_controls.cuh); it was resolved bykeeping both, main's line first. The gates below are at the head named above; the device run is at
73a3d618b,whose compiled kernel is byte-identical to this head's (see below).
tools/zig/cuda_common_check.py, the "SharedCUDA primitive copies" step that opens the
zigjob, rejects local copies of thecp.asyncinstructions,ld.global.ncandmma.syncoutsidezig/kernels/cuda/common: at73a3d618bit readcuda common: 60 local copies, 5 violationsand named five lines offn_int4.cu(cp.async.cgat 281,commit_groupat 283,wait_groupat 285,ld.global.nc.L1at 48 andmma.sync.aligned.m16n8k16.row.col.f32.bf16.bf16.f32at 40).The kernel now calls
tf_common::cp16z,tf_common::cp_commit,tf_common::cp_wait,tf_common::ld_ncandqmm_frag::mma, whose instruction text is the one the file carried, and the check readscuda common: 55 local copies, 0 violations, the count the base tree reads too (the allowlist carries nofn_int4line either way).fn_int4.cuis the commit's only compiled source: the samenvcc13.3-fatbincommand on the old and the newfile produces one file, 4,154,648 bytes with sha256
1e2b5ee6c0bce3b297168e000449b61cb1047d826d3b5375195945c3085901c0, byte-identical to the image the device runmeasured, and the dependency files show the new build read
common/cp_async.cuhandcommon/qmm_frag.cuhwherethe old read no
common/path, so the shared forms are what the compiler consumed and the device results stand.atc overlap --json: run in this branch's worktree at the head named above withup/mainat57c792ae5eb6795451e93e15056325983f6aea04(upstreammainas fetched on 2026-11-20), on 2026-11-20:complete: falsewith its own four limits (otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit), 20 changed files and 22 overlaps, all of them working-tree overlaps against 22open pull requests (atc's own states: 7
clean, 3conflicts, 12unknownbecause it could not fetch theirfiles). No entry is sourced from our own pull requests:
myPullRequestsis empty, our glm cuda: decode windows' EXL3 experts run on the 16-pair item plan #2044 having merged. Eachof the 22 was then merged three ways read-only (
git merge-treewith main alone and with this head): 7 mergecleanly with this head; 8 conflict in exactly the files they conflict with main alone, 7 of them with the same
number of conflict blocks in every file and ricursive: serve Ripple-65B on two GB10s with up to 1M tokens of context #2522 with one block fewer in
zig/tests/cuda/main.zig; 2 conflict infewer files than they do with main alone, MiMo-V2.6-Flash on CUDA (2x GB10) with DFlash as the drafter #728 not in
zig/exl3_prompt_host.zigand qwen3_5: TF_QWEN_KV_HOST - pinned-host KV pages (capacity mode for long windows) #2637 not inzig/src/families/qwen3_5/cuda_native.zig, files main changed after the base and this head does not touch; and5 conflict in at least one file that main alone merges, each of those files with one conflict block: lfm3: serve LFM3-1.7B on CUDA: NVFP4 and FP8 weight-only, MLX 4-bit (stacked on #1513, #1492 and #1503) #1508 and
idol: the octree and Gaussian decoders on CUDA (stacked on #1773, #1767; not yet run on a GPU) #1858 in
zig/tests/cuda/contract_limits.zig, MoE route tap: optional TF_ROUTE_TAP trace of global top-k #1886 and glm cuda: TF_GLM_GRAPHS=1 replays verify windows as CUDA graphs (#1490) #2279 inzig/tests/fixtures/gradient-serving.tsv, andLing-3.1-flash on CUDA, on one or two GB10s #2340 in
zig/src/core/contract/measurements/pending_133.zig. Every one of those is a shared registration tableor a pin row this change also touches: a registration list resolves by keeping both sides' lines, and a pin row
by writing the merged tree's own bytes.
main: this head's CI ran at582994e22against the base this description names,7d4a77aa5, and the branch conflicts with main's newest tip,57c792ae5eb6795451e93e15056325983f6aea04:git merge-tree --write-tree --name-onlyof this head and that tip exits 1 with one conflict block in each oftwo files,
zig/kernels/cuda/contract_controls_set.cu, where main appendscontract_hcn_controls.cuhto theinclude list this change also appends to (
542deb953), andzig/tests/fixtures/gradient-serving.tsv, where bothsides re-pin the
zig/src/cuda/kernels.zigrow. Both are shared registries this change extends, and each takesthe resolution the registries take: the image list keeps both sides' includes, main's first, and the row is
re-pinned from the merged blob. Against
3661a4281, the main of the previous round, and against7d4a77aa5,the same command exits 0.
How the stored form is read, and why its bits are stable:
136(128 + the zero point 8) is subtracted in bf16, which leaves q - 8 exactly: every value 0..15 and 128..143 is a bf16 exactly, and the subtraction of two bf16 values this close is exact. No nibble is widened through an f32 round and no product is formed in a narrower type than its inputs.int4_prompt_kernelstages the same packed words and the item's rows in shared memory withcp.async; the contract compares both prompt launches byte for byte with the plain ones.What the module keeps, and what it drops:
int4_kernel(gate/up with SwiGLU, down to fp32, down to bf16) at 1, 2 and 4 n8 tiles a warp and 1 or 2 row tiles a pass: 18 launches. Twoint4_prompt_kernellaunches for the routed down (fp32 and bf16 out) and one for the routed gate/up. The head and the down share the bf16-down instantiation, because the epilogue is the whole difference.--tp 2is refused by name at admission (step 5), so the instantiations would be dead weight and 12 more records.TF_FLASHNEXT_INT4_TILE,TF_FLASHNEXT_INT4_PROMPT_GATE_UPandTF_FLASHNEXT_HEAD_ROW_TILES, plus a prompt-down switch. Each would be a directgetenvtoday, none is measured, and no caller exists to honour one. The module offers the paths as calls (gateUp,down,downPrompt,gateUpPrompt,dense); the caller that wants a plan tile of 64 pairs says so. The PR that turns one on brings itsplatform/environment.zigrow and its measurement.cuda.experts.Format. The format's kernels belong to the backend, asfp8.zigandnvfp4.zigare host-only incore/quant, and the family's layer view (step 5) is where a format is declared.Why not
affine4, which already serves 4-bit weights on CUDA: its lane reads a bf16 scale and a bf16 bias for every 64 inputs (zig/src/cuda/qlinear.zigAffine4.layoutsizes both tables atk / 64, andzig/src/cuda/affine4_kernels.zigpacks MLX's(n, k/64)scales and biases into the tiles), while these weights carry one fp16 scale for every 128 inputs and no bias. Rounding that fp16 scale to bf16 is lossy, measurably so on this checkpoint's own scales (our reply on #3368), and the format has a zero point (8, fromqzeros) rather than a bias. Serving these weights on the affine lane would trade a stored format for a re-encoded one, which the engine does not do.Provenance and licence:
fn_int4.cuis MiaAI-Lab's file from their two-rank recipe at04f2b53826dca9a52893f2bce9d49bb3d1828e88(patches/0002-kernels.patchcreates it, 489 lines), Apache-2.0,Copyright 2026 MiaAI-Lab. Three changes are TensorFold's, the first two marked
TF:in the file and all threestated in
THIRD_PARTY_NOTICES.mdwith the recipe's NOTICE line: the head's dense items hold 16 MT rows ratherthan 16, one more
int4_prompt_kernelinstantiation builds for the routed gate/up, and the local copies of themma, the non-allocating load and the
cp.asynccopies are replaced by the shared ones inzig/kernels/cuda/common/, whose instruction text is the same. The file's header states the three.zig/src/cuda/int4.zigand its tests are this branch's own.What the branch does not do: it adds no setting (so
docs/environment.mdis unchanged), no lossy conversion (the only widenings are the exact ones above), and no mode that changes output tokens. Nothing calls it, so there is no default path to compare and no token hash to take; the receipt below is the device gates and the limits audit, measured on a GB10.Checks on this head
582994e2291711e861068d3d123be8b8a6979c1e, signed (%G?=Gin this checkout), tree63a931abee646ec50f605a3fcad993f538855e85: the two commits on32c4e3d8fe7b696de738839a0cf1d8cc596c80fe(
7fe47dbe0, the kernel, 18 files, +1,864/-4, and619d5e95b, the contract fix, 7 files, +192/-31), the twosigned merges of
mainnamed above, and one commit after them (582994e22, the shared primitives, 2 files,+23/-30); against the base the branch is 20 changed files, 8 of them new, +2,018/-4. The contract fix is the
skipped-slot check by row, the second control registered at gate 3, the gate/up allowance derived from the
epilogue at
zig/tests/cuda/int4_ref.zig, the stress rows' magnitudes, and the 21 nvcc 13.3 receipts. The lastcommit is the shared-primitive change described above, and its only compiled output is byte-identical to the
image the device run measured. The two rows the pin fixture re-pins are the bytes of the two serving sources this
change edits,
zig/src/cuda/kernels.zigandzig/src/cuda/root.zig. NoCHANGELOG.mdline is in the branch:the maintainer adds a merged pull request's bullet in a follow-up commit, as they did for the reader's own merge.
byte-identical by blob at the GPU-measured head
619d5e95band at this head:zig/src/cuda/int4.zig61625c9eae,zig/src/cuda/int4_test.zig5155a3b5b6,zig/src/cuda/root.zig0e3ac57219,zig/build/cuda_int4_host.zig8275134ba4,zig/kernels/cuda/contract_int4_controls.cuhe8a41d963f,zig/src/core/contract/int4_records.zig0a43335817,zig/tests/cuda/contract_int4.zigb83fcd81bd,zig/tests/cuda/int4_ref.zig4102656d42,zig/src/core/contract/measurements/pending_133.zigdccc116f6c(the 21 added lines, every one a
fn_int4receipt, none lost) andzig/tests/cuda/contract_after.zig80d73fc337.zig/kernels/cuda/fn_int4.cuis the one that moved:6d0b5de16eat619d5e95b,0c5e5ca3a1atthis head, from the shared-primitive change.
zig/kernels/cuda/contract_controls_set.cuis81410ea1bbat thishead: main's
contract_embed_controls.cuhinclude and this change'scontract_int4_controls.cuhinclude areboth there, main's first, and the rest of the file is main's. Three shared files moved only because main added to
them, this change's line unchanged in each:
zig/src/cuda/kernels.zig(thefatbin_fn_int4line, between main'sdrama3_codecanddrama3_staged_gemv),zig/build/cuda_kernels.zig(itsfn_int4entry at the end of theimage list) and
zig/tests/cuda/contract_limits.zig("fn_int4"added to the image names main lists). The restare shared text and pins:
docs/kernel-contract.mdandTHIRD_PARTY_NOTICES.mdcarry this change's added lines,zig/build/cuda.zigandzig/src/core/contract/registry_joins.zigadd one line each, andzig/tests/fixtures/gradient-serving.tsvdiffers from main in exactly its two pinned rows, the bytes of the twoserving sources this change edits; its other rows are main's.
git archiveoutputs verified blob by blob againstgit ls-tree -rof their commit before anystep ran: on the x86_64 machine head 12,557 entries and base 12,549, 0 mismatches, 0 extra files; on the device
box the head, 12,557 entries, 0 mismatches, 0 extra files.
tools/zig/lean_check.pyput in the base worktree as CI puts it and run from each root:this head
6,962 files, 168 problems(rc 1), the base6,954 files, 168 problems(rc 1), the two file countsdiffering by this change's 8 new files, so
lean_new.pyreadslean: 168 problems, 168 on the base, 0 new(rc 0).python3 tools/pr_check.py --base 7d4a77aa5bfa14deffaa18a7ce31bd8a0dffaca8 --pr 4183(upstreammainat thesha the branch merges), rc 0:
merge base 7d4a77aa5bfa14deffaa18a7ce31bd8a0dffaca8; 20 changed files; lean 168 vs 168, 0 newand0 error(s), 1 warning(s); warnings are advisory. The warning isWARN: Zig changed: no Unreleased bullet naming this PR: the branch changes Zig files and the CHANGELOG carries no Unreleased bulletnaming this pull request, which the tool treats as advisory, the maintainer adding a merged pull request's bullet
in a follow-up commit. The check needs a git checkout, so it runs here on the branch's own worktree. The two rows
this change re-pins in
zig/tests/fixtures/gradient-serving.tsvare read bytest-gradient-serving, the stepthat runs against this head's own tree:
11/11 steps succeeded; 6/6 tests passedover the file's 169 rows.and verified as above,
zig fmt --check build.zig zigrc 0 on the head and rc 0 on the base: on the head,zig build -Dfixed-cpu test-int4-hostrc 0 in 32 s,6/6 steps succeeded; 33/33 tests passed;zig build -Dfixed-cpu test-kernel-contractrc 0 in 404 s,36/36 steps succeeded; 260/260 tests passed;zig build test-environment-hostrc 0 in 3 s,3/3 steps succeeded; 26/26 tests passed;zig build -Dfixed-cpu test-gradient-serving test-qwen-serving-host test-glm-pdl-scanrc 0 in 4 s,11/11 steps succeeded; 6/6 tests passed. The run stopped after those four steps because the request budget ended and a queued gate run waswaiting for the machine's build lock, so these are not this head's own local runs:
compile-cuda-testsandcompile-config-servercross-compiled for aarch64-linux-gnu(10/10 and 8/8 steps at
fa7d93d9a),test-cuda-host,test-host-a,test-host-b,test-golden,test-server-security test-pull-security,fuzz-cortheonandcheck-release-paths. CI ran every one of thosesteps on this head (below). The head's contract run is 260 tests against the base's 258, the difference being
int4_records.zig's twotest "int4:blocks, which are in this diff; the base tree's run, on the same machinein the previous round, read
36/36 steps succeeded; 258/258 tests passedin 295 s.zigjob's python steps, run here at this head with the workflow's own commands, all rc 0:python3 tools/zig/cuda_common_check.py,cuda common: 55 local copies, 0 violations;python3 tools/zig/cuda_fragment_check.py,cuda fragments: 2 fragments, 15 includes, 0 misses;python3 -m unittest discover -s tools/zig -p cuda_common_check_test.py -v,Ran 9 tests in 0.012s,OK;python3 tools/test_pdl_early_loads.py -v,Ran 17 tests in 0.010s,OK; the lean check above;python3 -m unittest discover -s tools/zig -p zig_cache_restat_test.py -v,Ran 2 tests in 226.634s,OK, with its own linezig_cache_restat: 12 manifests, 2 rewritten, 2 records updated, 2 changed, 0 unreadable, 4 pruned with 3 output folders;python3 -m unittest discover -s tools/zig -p host_tests_test.py -v,Ran 13 tests in 17.345s,OK;python3 -m unittest discover -s tools/zig -p flashnext_batch_serve_test.py,Ran 8 tests,OK;python3 tools/zig/nfkd_tables.py --check --zigwith Zig 0.17.0 as the argument, no output;cd tools/zig && python3 -m unittest test_nfkd_tables,Ran 5 tests in 0.887s,OK;python3 -m unittest discover -s tools/zig -p build_options_test.py,Ran 5 tests in 144.414s,OK. The first attempt of the first command read rc 127, thehost's
timeoutwrapper failing to execpython3once; the three commands of that step were re-run unchangedseconds later, and those reruns are the record above. The workflow's "Let a restored cache fit this checkout"
step only warns and was not run, and its "Save the build cache" step runs on main pushes only.
pytestjob at this head:python3 -m pytest -q -p no:cacheproviderfrom the root, rc 0,645 passed, 95 skipped, 670 subtests passed in 522.22s (0:08:42), on python 3.14.4.The
benchmark-clientsjob's two steps ran at this head on both legs: the ubuntu legRan 201 tests in 169.558s,OKfor the benchmark clients andRan 32 tests in 0.902s,OKfor the evidence index, and the windows legRan 201 tests in 213.401s,OKandRan 32 tests in 32.702s,OK.zig build -Dfixed-cpu test-int4-hostruns the cuda module's host tests, thischange's
int4:blocks among them (the step'sfiltersfield narrows nothing in this Zig:std.Buildnever emits--test-filter, so a filtered step runs its module's whole test file set and the count is the module's): theword shuffle,
packWordsagainst every stored code of a slice, a whole 640 x 2,560 matrix's scale layout and its own column groups, every slice refusal by name, the stored codes and fp16 scales against hand-computed binary64 weights, the 21 mangled symbols, the two prompt launches' shared-memory sizes and the gate/up launch's alignment guards. They pass 33/33 at this head (6/6 steps succeeded; 33/33 tests passed), 12 of those tests being this change's (11int4:blocks plus the import test that pulls them in). The file had never been compiled before the module's test list named it, so five of its expectations were wrong and are fixed here: the shuffle mapping is not an involution, a k32 block index read(kin % 32) / 32(always 0) instead of(kin % checkpoint_group) / 32, a source whosek_fulldisagrees with its buffers iserror.BadLengthnoterror.BadSlice, the fp16 constant for -2.0 was written0xBC00(-1.0) instead of0xC000, and a 2,560 x 640 matrix carries 12,800 scales, not 5,120.3a33f80ab, whosezig/src/cuda/int4.zigis this head's blob (61625c9eae): eachmutant is the inverse of one check the module makes, applied to its own fresh extraction of the tree and run
through
test-int4-host, and a mutant is killed only when it fails anamed
int4:test that the unmutated control passes. The anchors all resolve (ANCHORS 23 mutants, 0 not exactly once), the control readsrc 0,6/6 steps succeeded; 33/33 tests passed,0 failing int4 test(s), and thescoring reads
SCORED 23 mutants, 23 killed, 0 no kill.scale-widen's replacement keeps only bf16's sevenmantissa bits, so its kill is a test failure and not a build error. The table is in the branch's gate record, not
in this diff.
test-hostin full was not run at this head: the machine's run stopped after the four steps above. At the parenthead
73a3d618bthe same machine'szig build -Dfixed-cpu test-cuda-host(the CUDA side's host unit testsalone, which the
test-host-ashard runs) reads rc 0,440/440 steps succeeded; 7618/7658 tests passed (40 skipped)in 844 s. CI rantest-host-ain thezigjob andtest-host-bin thezig-bjob on this head, andboth passed.
zig fmt --check build.zig zig: rc 0 on the head and rc 0 on the base;git diff --check7d4a77aa5bfa14deffaa18a7ce31bd8a0dffaca8..582994e2291711e861068d3d123be8b8a6979c1eprints no output and exits0, and
git diff --checkover the two commits, over the second merge and over the last commit does the same.582994e22.gh pr checks 4183reads pass forfmt,zig,zig-b,zig-windows,pytest,benchmark-clients (ubuntu-latest),benchmark-clients (windows-latest),release-paths (ubuntu-24.04)andzig-macos-dev-tools, and skip forhost-nightly-linuxandhost-nightly-macos, whose jobs areif: github.event_name == 'schedule'. That puts on this head the steps themachine above did not run:
zigrunstest-host-a,test-kernel-contract,test-golden,test-gradient-serving test-qwen-serving-host test-glm-pdl-scan,test-server-security test-pull-securityandfuzz-cortheon;zig-brunstest-host-b;zig-windowsrunszig build test,test-golden,fuzz-cortheonand
test-pull-security;release-pathsrunscheck-release-paths; andzig-macos-dev-toolsrunsdev-tools.The step that failed at the parent head is the first of
zig, and it passes here withcuda common: 55 local copies, 0 violations.from the compiled cubins in the five-SM audit). Metal and HIP are not reached by a
.cufile. Two ranks are notreached: the groups-of-64 form is not built. The device run was taken at
73a3d618bon 2026-11-20, and thishead's
fn_int4.cucompiles to the samefn_int4.fatbinbyte for byte, so the limits name tablezig/tests/cuda/contract_limits.zig, which main extended beside this change's line, is described by that runrather than by an earlier head's.
Receipt
grep -rln 'fn_int4\|cuda\.int4\|cuda/int4' ziglists fourteen files: the kernel, the host module and its test, the reference the contract derives its allowance from, the two image registrations (zig/build/cuda_kernels.zig,zig/src/cuda/kernels.zig),zig/src/cuda/root.zig's export and its test list, the controls header, the contract suite, the launch records and the 13.3 receipts that carry them, the image name inzig/tests/cuda/contract_limits.zig, the build step that runs the host tests (zig/build/cuda_int4_host.zig) and the pin row inzig/tests/fixtures/gradient-serving.tsv, and no family, server or recipe file.zig/src/platform/environment.zigis untouched and so isdocs/environment.md. The settings the kernel's port read are removed rather than routed (see above).7d4a77aa5bfa14deffaa18a7ce31bd8a0dffaca8, head582994e2291711e861068d3d123be8b8a6979c1e(the device suite and the limits audit below ran at73a3d618b, whose compiled kernel is byte-identical to this head's), Zig 0.17.0,nvcc 13.3.73 for the device suite and the limits audit, an aarch64 Linux machine with an NVIDIA GB10 (Ubuntu 24.04.5
LTS, 20 CPUs, 123 GiB RAM, driver 580.178.04, compute capability 12.1), an x86_64 Linux machine with 16 CPUs and no
GPU (the host gates below, and the aarch64 cross-compiles at
fa7d93d9a), and no checkpoint: the hosttest and the device suite build their own stored matrices. The checkpoint the shapes come from is
azampatti/Qwen3.8-Flash-Next-125B-A5B-INT4-AutoRoundat revision8b145d7f6505f71521a73646c268e51f6af532e4:hidden 2,560, 512 experts of width 640, group 128, 4-bit symmetric GPTQ weights with zero point 8.
fa7d93d9aand not re-run at this head, the device path on sm_121 (a GB10), where the int4 suite passes every gate and both planted controls read red as planted (see the kernel contract section); no SM is claimed qualified. sm_80, sm_86, sm_89 and sm_120 were not run.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: n/a, no served path. The exactness this change does own is the stored weight: the host test checks(code - 8) * scalein binary64 against hand-computed values for a zero point, a negative scale, an infinite scale, fp16's least subnormal and a scale of 0.1 whose fp16 bits are not decimal 0.1.tools/bench_openai.py: n/a, no served path.THIRD_PARTY_NOTICES.md.The device lines are the run at
73a3d618b, the head this one adds its commit to, taken on 2026-11-20 from thathead's
git archive, verified blob by blob againstgit ls-tree -ron the box before the build. This head'sfn_int4.cucompiles to that run's ownfn_int4.fatbinbyte for byte, so every line describes this head's kernel.Two runners did the work: that head's own runner for
kernel-contract fn_int4and the limits audit, and the sametree plus one dispatch line naming the int4 suite's own verb (which main does not carry) for
int4-contract. Thefull
kernel-contractrun was not taken: the same box took 3,930 s over it at an earlier head, over the one-hourcap this window works to, so that run has no full-run aggregate and none is quoted below. The planted head without
the nibble shuffle is a control at gate 3 (
Fixture.kernel()maps.unshuffled_nibblesto.shapes), not aneighth kernel, so its failure is
CONTROL ... red at shapes, as plantedand not a gate failure. The gate/upregistrations compute their allowance from
zig/tests/cuda/int4_ref.zig(both fp32 sums through silu's slope overthe rounding's interval, then bf(g), bf(u), bf(silu) and the store at their own values, and expf's fp32 overflow),
state gate 4's bf16 proof at 60 with its arithmetic in
why, and gate 4's stress rows carry 8 to 2,040 with theeight nudged inputs at 4 to 16. Production was down from
2026-11-20T02:19:01+00:00to2026-11-20T02:21:08+00:00, and the box read/health200 afterwards. Two hashes carry the run:fn_int4.fatbinis 4,154,648 bytes with sha256
1e2b5ee6c0bce3b297168e000449b61cb1047d826d3b5375195945c3085901c0, the same bytes as the earlier head's, andcontract_controls.fatbinreadseff8853391d641d43fa50edb12508610d8e110a4385f3a119c34ace7db245e9fwhere theearlier head read
b15f6bff69ab92bcda1d3adbaab14c5c2273933322b663657bfdec20d8947d54, because the merged tree addsmain's
contract_embed_controls.cuhinclude to the planted-controls image. The int4 suite's log is byte-identicalto the earlier head's, sha256
3673fb00ebaa2179b78409b230dd88b2f39beb5c1d960aa0f6c81a7674a90d93.Each declaration, and what derives it:
accum = .f32,depth = k/16 + k/128 + 36: one mma k16 step an input's 16 products accumulate in (k/16of them, in order), onefmaf(group sum, scale, acc)a group of 128 inputs (k/128), and the 36 roundings one bf16 mma k16 step carries at worst (core/attention_range.mma_step, the count the other CUDA experts state).ops = 5:expf's 2 ulps, the1 + e, the quotient and the product.mids = 3:bf(g),bf(u)andbf(silu), the three bf16 roundingsexperts.cuh's SwiGLU makes before the product (fn_int4.cu'sswiglu,float gv = bf(g), uv = bf(u); ... bf(gv / (1.f + expf(-gv))) * uv).out = .bf16: the store's__floats2bfloat162_rnin both kernels.int4_ref.zig'sgateUp, the sums through|silu'|on the rounding's interval (its turning points are +-2.3993572805, so the interval's largest slope is exact), thenbf(g),bf(u)andbf(silu)at their own values, the store,expf's fp32 overflow above 88.72, and the five fp32 ops;rowsis the same two lines for a down or the head..bf16 = 60: the largest miss a low-precision sum can make on a mirrored row iswantitself (the halves order cancels it exactly), and the roundings already allow4.1368 uof it (computed from the harness'sboundExact:(5 * 2^-24 + 3 u) (1 + u) + u, where the undivided generic form is4.0118 uand its ceiling63.812x, the number the device printed), so1 / (4.1368 u) = 61.9xis the ceiling and 60 is stated below it.Kernel contract, only when a GPU kernel is new or changed
fn_int4.cu'sint4_kernel(three epilogues) andint4_prompt_kernel(the routed down and the routed gate/up) are registered inzig/tests/cuda/contract_int4.zigas seven kernel entries at the checkpoint's shapes, with the two planted controls as the last two rows of the sameentriesarray: gate/up and down at 1, 3, 16 and 64 token rows and at 64 and 200 pair rows for the prompt forms, the head at 1, 16 and 32 rows including its full 248,320 columns at one row, and each entry's edges. The two prompt entries replace the plain form they must equal, byte for byte, and say so. It replaces no kernel on any served path; nothing loads it yet.73a3d618bwith nvcc 13.3.73,CONTROL control: int4 routed down with each group's sum rounded to bf16: red at sums, as planted(FAIL sums control: ... 1103940812.8x over its exact-sum bound at k 640: not fp32 sums (fp16 would miss 96087692x, bf16 640330411x)) andCONTROL control: int4 lm head with each word's nibbles unshuffled: red at shapes, as planted(FAIL shapes control: ... at 1x2560x2560 output 0 is 4.650000e1 where float64 gives 2.521465e0: 1301.67 of its bound). Both are entered as controls, so neither counts as a gate failure:2 controls: 2 red as planted, 0 missed.SUMMARYline and exit status: CUDA on a GB10 (sm_121), runners built from73a3d618b's tree withnvcc 13.3.73. The int4 suite,
tf-cuda-test int4-contract, exits 0 after 28 s with 29PASSlines, the 2 plantedcontrols'
FAIL ... controllines and theirCONTROL ... red atlines,PASS int4 skipped slot: 16 of 96 pair rows left at 0xff, the others byte-equal to the all-live run, andSUMMARY int4: 7 kernels, 7 pass gates 1-4, 0 fail, 0 known findings; 2 controls: 2 red as planted, 0 missed.73a3d618b's own runner,tf-cuda-test kernel-contract fn_int4, exits 0 in 1 s with 23PASSlines, noFAIL, and(filtered) SUMMARY 0 kernels: 0 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems; gates 32 ms, limits 2 ms. The limits audit over the 21 committed records and the five-SM images readsLIMITS head exit 1 51s lines 10024 int4 RECORD lines 21: 850 problems, 850(record stale)lines, and105 PASS;fn_int4verdicts with(record current)on every one, no int4 entry among the stale lines. The full run,tf-cuda-test kernel-contract, was not taken at73a3d618b: it took 3,930 s on the same box at an earlier head,past the one-hour cap this window works to, and this head runs main's new suites after the main body as well.
Checklist
6/6 steps succeeded), the two new blocks beingint4_ref.zig's derivation and its tightness check. That check requires the generic formula to be short on some of 4,000 epilogue draws, so reverting the allowance to the generic formula failstest-int4-host. The contract suite, reached only by the contract runner that requires-Dnvcc, is the run this commit exists to make pass, and it passes every gate on the device (SUMMARY int4: 7 kernels, 7 pass gates 1-4, 0 fail, 0 known findings)."draft": false, a resumed prompt equals a fresh one, and concurrent equals solo: not applicable as above.