Repository navigation
Qwen3.5/3.8 and Flash Next on CUDA: --vision reads a quantized ModelOpt tower - #3727
Conversation
86e139a to
c6cf7a9
Compare
|
Thanks @BadAd84. The decoder and byte-level fixtures look sound. Please correct README.md:12 and :50: they claim floating-point serving/equality, while exactness.md says both configurations were refused before loading. Also map the current head to the measured ac20700 revision and update the check status. Unchanged runtime sources can be documented without assuming another GPU run.
|
|
Thank you @BadAd84. The two README lines now match exactness.md. Nothing is left for you here.
|
d860857 to
d86ea98
Compare
|
On M5 Max with Zig 0.17.0, I also checked the MXFP8 multiply and rounding independently in scratch: all 254 non-NaN E4M3 codes crossed with all 255 finite E8M0 scales. A Python oracle used binary64 powers of two and ties-to-even BF16 rounding, including signed zero, subnormal outputs and overflow. All 64,770 BF16 bit patterns matched. The updated trial merge with the extra fixture also passed Igor Lessio - AIFLOW LABS |
A checkpoint whose vision tower ModelOpt quantizes, as nvidia/Qwen3.8-Flash-Next-FP4-Local stores attention as MXFP8 and the MLP and merger as NVFP4, was refused by the CUDA tower's reader, which expects bf16 for every tensor. The tower's linears now decode on the host as they load: an e4m3 code times the e8m0 power of two of its 32 inputs for MXFP8, and an e2m1 code times the e4m3 scale of its 16 inputs times the tensor's global scale for NVFP4, each a product of exactly representable factors in fp32 and rounded to bf16 once, nearest even, so a row is the stored value read as the format defines it rather than an approximation of it. The tower still runs in bf16: its kernels, launches, scratch and rows are the ones a floating-point tower gets, and its device bytes are the same, because the arena is sized for bf16 weights either way. The decode holds one linear in host memory at a time and frees it once the upload holds its own copy, so a failed load leaves nothing behind. A floating-point tower is read as stored, byte for byte, so a checkpoint that loads today loads to the same bytes; only a tower whose linear's dtype is e4m3 or u8 takes the new path, and a stored plane, scale or global scale of another shape, a width that is not a whole number of scale groups, and an extra tensor the reader does not take all stop the load naming the tensor. Nothing of the tower loads without --vision, so text serving is untouched. docs/vision.md says which towers CUDA reads now, and CHANGELOG names the change under Unreleased.
…longer claims a floating-point tower leg The floating-point tower leg was refused before any weight was read on both images, so the receipt says it has no result. The current head is mapped to the measured revision by its source files, which are byte equal.
d86ea98 to
9441f3b
Compare
|
Thank you @BadAd84. 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. |
Terms used below: "main" is upstream TensorFold at
077998f7d9b14adebec3a2acc2caa47ff7ae6ec7(its tip of 2026-11-16T15:26:10Z), and "the measured head" is391c6bf1f9592703c19c18878ad251532ad7cf24, that main plus the change and the receipt, the commit the checks and the receipt below name as measured. The pull request's head isd8608573a7366dc88cc79f21ca73e0363e5dea6f("the head"): the maintainer rebased the change and the receipt onto upstreammainat8cbef9777b9a05dfaff99d5aa9c2ce52fe2b00f8(asd46832d6631650b2c969fa6f03e7e9bed9a398adandc6cf7a965a55cbe206e50166602fe74b788891c7), and two commits of ours follow:8826ad672793c0fb6f8ab5d115cbd46822c0dc20, which answers the review (the receipt README no longer claims a floating-point tower leg, since both images refused that checkpoint before loading, and it maps the head to the measured revision), andd8608573a7366dc88cc79f21ca73e0363e5dea6f, the Unreleased bullet naming this pull request. Where a check below says "this head", it means the measured head unless the bullet names the head.What this changes
The CUDA vision tower's reader takes every linear's weight as stored bf16, so
--visionon a checkpoint whose tower ModelOpt quantizes stops at the first quantised linear and names it. With this change a linear stored as MXFP8 (e4m3 codes, an e8m0 power of two every 32 inputs) or NVFP4 (e2m1 codes two to a byte, an e4m3 scale every 16 inputs, one fp32 scale a row) is decoded on the host to bf16 while the tower loads, and the tower runs in bf16 exactly as it did: same kernels, same launches, same scratch, and the same bytes on the device, because the tower's arena is sized for bf16 weights either way.--visionflag, and adds no arithmetic to the served path (the tower runs in bf16 as before); the gate it proposes is the one below: every decoded tensor compared byte for byte with a binary64 reference on the host, and the device load, replies and contracts on the checkpoint itself.mainat8cbef9777b9a05dfaff99d5aa9c2ce52fe2b00f8. The branch is the maintainer's rebase of the change (d46832d66, which wasac2070000) and of the receipt (c6cf7a965, which was391c6bf1f, three files, no code), then8826ad672andd8608573aas named above. The change's five source files are the same blobs atd46832d66as atac2070000, andzig/src/visionis the same on both mains, so every device cell below was measured on the code this head carries; only the documentation around the change moved (docs/vision.md).atc overlap --json: run last, on the headd8608573a7366dc88cc79f21ca73e0363e5dea6fwithup/mainate63f26f0e6ae75f76fc2617c1f841af7adbde6e2, 00:12 to 00:13 UTC: incomplete (complete: false, with its own four limits,otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimitandtimeLimit), 10 changed files and 30 overlap rows, of which 20 are working-tree rows (6clean, 3conflicts, 11unknown) and 10 are the fork's trunk (PR 2044) listed against other pull requests, allunknown. The threeconflictsentries are dsv41 metal: image prompts #1722, DeepSeek-V4.1: read the pack's weight spans past the page cache (core/direct_io) #1924 and Nemotron 3.5 Transcribe: audio input, the 65,536-token window, an hour of audio, MTP drafts #1632, and the only file each shares with this change isCHANGELOG.md(checked against the files of each): the ordinary case of pull requests inserting their Unreleased bullets in the same place.How the reader decides, and why it lives in the tower's reader:
zig/src/vision/qwen_cuda_weights.zig'sReader.linearreads the weight once to see its stored dtype.bf16(and any other dtype) takes the unchangedReader.getpath, byte for byte;e4m3is MXFP8 andu8is NVFP4. So a checkpoint that loads today loads to the same bytes, and the seven pre-existing tests inqwen_cuda_weights_test.zig(byte identity, refusals, ownership, allocation balance) still pass against the new routing..weight, its width is a whole number of the format's scale groups, its stored plane is the shape the tower's config says, its scale tensor is e4m3[n, k / 16]for NVFP4 or u8/e8m0[n, k / 32]for MXFP8, and itsweight_scale_2is one fp32. Anything else stops the load naming the tensor ({name}: not a ModelOpt {kind} vision linear of the tower's shape), and an extra tensor the reader does not take still fails the existing unused-tensor check. The test runner's diagnostics check counts every error line and fails on one it does not recognise, so the refusal's own log line is covered by the refusal tests rather than only added. A W4A4 staticinput_scalebeside a linear is read and marked used, because the tower runs bf16 and never applies it.core/modelopt.zig's recipe comments define the two (NVFP4: FP4 weights, an e4m3 scale every 16 inputs, a global scale;MXFP8: e4m3 weights, a UE8M0 scale every 32 inputs), andcore/quant/nvfp4.zigdocuments the stored layout (weightu8[..., N, K / 2]even columns low,scalee4m3[..., N, K / 16],global).zig/src/vision/qwen_cuda_dequant.zigcomputes each element as the product of exactly representable factors in fp32 and rounds to bf16 once, nearest even, which is the same bits as casting the format's exact value to fp32 and then to bf16, and the tests prove it against binary64 references rather than asserting it.core/modelopt_part.zig) is not reused: it covers NVFP4, per-tensor FP8 and bf16, its scale is one fp32 and itsKindhas no MXFP8 arm, and it returns views for a family's own device upload while the tower needs bf16 rows into its arena. The tower's reader handles both recipes with one code path and one refusal.2 * n * kbytes, the merger's first projection atn = k = 4 x hiddenbeing the largest) and frees it once the upload holds its own copy, so a failed load leaves nothing behind; the allocation-failure test walks every allocation index and requires the balance to return to zero. On the device nothing changes:Tower.weightBytescounts two bytes an element for every weight, which is what the sink is handed.--visionis the only trigger.Options.vision(zig/src/families/flashnext/cuda_lanes.zig) defaults to null and is set only from the serve flag (zig/src/native/cuda_options.zig:if (o.vision) |vo| opts.vision = ...),zig/src/families/flashnext/cuda_lanes_load.zigloads the tower only insideif (o.vision) |limits|, andweights.loadis called from nowhere else. A text-only serve reaches none of this code.zig/src/platform/environment.zigand none indocs/environment.md, and the change reads nogetenv. No.cuor.cuhis edited, so the kernel contract does not apply. No serving source is re-pinned: the onlyzig/src/vision-side entry inzig/tests/fixtures/gradient-serving.tsvis the kernelzig/kernels/cuda/qwen_vision.cu, which this change does not edit, andtest-gradient-servingpasses on this head.Checks on this head
391c6bf1f9592703c19c18878ad251532ad7cf24, the receipt commit on the change commitac207000030b969a259143ac32bf2eac6b5e29e7(which, against main077998f7d9b14adebec3a2acc2caa47ff7ae6ec7, changes 7 files, 448 insertions and 6 deletions; the head's whole diff is 10 files, 553 insertions and 6 deletions), both author and committerBadAd84 <BadAd84@users.noreply.github.com>, signed. Every check below ran onac2070000, whose code the head carries unchanged;git diff --check 077998f7d..391c6bf1fis clean.python3 tools/zig/lean_check.py, one tree at a time from its own root, with the head's checker in both (byte-identical,cmprc 0): base077998f7d9b16,575 files, 221 problems; this head 6,577 files, 221 problems;lean_new.py:lean: 221 problems, 221 on the base, 0 new. The 221 are inherited (for examplezig/src/server/tool_grammar.zig:79).python3 tools/pr_check.py --base 077998f7d9b1on this head:merge base 077998f7d9b14adebec3a2acc2caa47ff7ae6ec7; 7 changed files; lean 221 vs 221, 0 new, and on the head with the receipt commit10 changed files; lean 221 vs 221, 0 new; 0 errors, 1 warning, the advisory--prone (this branch has no pull request number yet; the Unreleased bullet carries none and the number is added with the pull request).zig fmt --check build.zig zig: clean, rc 0 with no output, locally and on the head tree on the test machine.git diff --check 077998f7d9b1..HEAD: clean.-j8 --maxrss 6000000000except-j4where noted, umask 022, no GPU visible to the tests), on a freshgit archivetree of this head and, separately, of main, each checked blob by blob against its commit (11,834 and 11,832 entries: 0 missing, 0 extra, 0 different):zig build -Dfixed-cpu test-gradient-serving test-qwen-serving-hostrc 0 (7 of 7 steps, 3 of 3 tests);zig build compile-config-server -Dtarget=aarch64-linux-gnurc 0 (7 of 7 steps);zig build compile-cuda-tests -Dtarget=aarch64-linux-gnurc 0 (10 of 10 steps);zig build -Dfixed-cpu test-qwen-vision-weights-host test-environment-hostrc 0 (6 of 6 steps, 25 of 25 tests, of which the vision step's own runner reports17 passed; 0 skipped; 0 failed.), and the same vision step in the base tree rc 0 with7 passed; 0 skipped; 0 failed., so the module this change touches passes on both sides and the ten new tests are all on the head's side of that count.zig build -Dfixed-cpu test-host --test-timeout 20mat-j4: this head rc 1,2125/2132 steps succeeded (1 failed); 22118/22261 tests passed (142 skipped, 1 failed), the failure beinglistener.test.accepted IPv4 and IPv6 TCP streams disable Nagle for incremental responsesintest-cuda-host(1489 pass, 8 skip, 1 fail of 1498 there), which is the test machine's own limit, not this change's: the test opens and connects an IPv6 loopback listener, and that machine boots withipv6.disable=1. The same command on main at077998f7d9b1returned rc 1 as well:2125/2132 steps succeeded (1 failed); 11844/11933 tests passed (88 skipped, 1 failed), the same single failing test (1489 pass, 8 skip, 1 fail of 1498 there; that run's executed totals are lower because it reused test steps an earlier attempt on the same tree had already passed). The failing sets compared name for name are equal:1in both,0only on either side.qwen_cuda_dequant.zigand six in the newqwen_cuda_weights_quant_test.zig, whichqwen_cuda_weights_test.zigreaches by acomptimeimport block, so the stepzig/build/qwen_vision_weights_host.zigcompiles and the filterQwen tower weights:runs them. Each one is shown failing on the inverse of its behaviour: each mutant is applied to its own fresh copy of this head's tree, its anchors checked to occur exactly once on this head first, and the same command run (zig build -Dfixed-cpu test-qwen-vision-weights-host -j4), against a control that is the same tree unmutated (17 passed, 0 failed). All 12 mutants fail:Reader.get)a tower of floating-point linears reaches the sink as stored,a linear stored as bf16 beside quantized ones is read as stored, and six pre-existing dense tests (9 passed, 8 failed)NVFP4 NaN scales stay NaN and a zero scale zeroes its group(15 passed, 2 failed)e8m0 scale dtype and the activation scales are accepted(16 passed, 1 failed)e8m0 scale dtype and the activation scales are accepted(16 passed, 1 failed)a quantized linear missing or mismatching its planes fails closed(15 passed, 2 failed)Measured on this head: each mutant runs in its own
cp -aof the verified tree, the lane's global Zig cache shared across the runs, and the control is the same tree unmutated (17 passed, 0 skipped, 0 failed). Two rows need their numbers read with care: where a test unexpectedly succeeds,expectErrordrops the fixture'sSink, so its copies leak and the leak reports are counted by the next test's diagnostics check (the 22-block line under the unchecked-scale mutant, and the "expected 0, found N" texts under the not-freed one). Both are the mutant's own failure and test-side accounting, not a defect of the reader.python3 tools/pr_check.py --base 8cbef9777b9a05dfaff99d5aa9c2ce52fe2b00f8 --pr 3727:merge base 8cbef9777b9a05dfaff99d5aa9c2ce52fe2b00f8; 10 changed files; lean 221 vs 221, 0 new,0 error(s), 0 warning(s). On a clean x86_64 Linux machine (16 threads, Zig 0.17.0, umask 022, no GPU), on a freshgit archivetree of the head before its changelog commit:zig fmt --check build.zig zigrc 0;-Dfixed-cpu test-environment-hostrc 0, 3/3 steps, 26/26 tests;-Dfixed-cpu test-gradient-serving test-qwen-serving-hostrc 0, 7/7 steps, 3/3 tests;compile-config-server -Dtarget=aarch64-linux-gnurc 0, 7/7 steps;compile-cuda-tests -Dtarget=aarch64-linux-gnurc 0, 10/10 steps;-Dfixed-cpu test-qwen-vision-weights-hostrc 0, 3/3 steps.d8608573a7366dc88cc79f21ca73e0363e5dea6f(the head), run on this pull request:fmt,zig,zig-b,zig-windows,pytest,benchmark-clients(ubuntu and windows),release-pathsandzig-macos-dev-toolsall completed successfully;host-nightly-linuxandhost-nightly-macosare skipped by their own conditions.Receipt
docs/receipts/flashnext-vision-modelopt/README.md, withcells.csvandexactness.md): 7 boots on one NVIDIA GB10 (sm_121) machine, one fresh server each, through the serving recipe withCHECKPOINT=nvfp4,KV_DTYPE=bf16,--parallel 8 --context 32768,--visiononly where the leg is vision. Four text boots, main and this head ABBA, measure the default path; one boot of main with--visionrecords the load's refusal; two boots of this head with--visionrecord the load, the image replies and the three exactness contracts, the second without a prompt cache; the floating-point leg was not run in this window.bench_concurrent.py --prompts(request i sends item i):End-to-end tokens a second; the per-request decode rate and every alone check are in the receipt's
cells.csv. The greedy hashes: 8 of 8 prompts carry the same token ids on all four boots. The cells cannot move for the code reason below, and their verdicts are the noise rule's.--visionon the FP4 checkpoint: main's boot stops at the first quantised tower linear and names it,model.visual.blocks.0.attn.qkv.weight: f8_e4m3 { 3456, 1152 }, expected bf16 { 3456, 1152 }; this head's boot serves it and answers one image request withA close-up portrait captures a tabby cat with striking green eyes, gazing intently at the viewer against a softly blurred background.(147 prompt tokens, 28 completion tokens, 1.141 s). The reply is the same on a second request in the same boot, with"draft": false, on two streamed requests, and on a second boot with--prompt-cache-gib 0: twice in one boot (equal by token_sha256), with"draft": false(equal by token_sha256), twice streamed (equal by token_sha256), streamed again (equal by token_sha256) and on the second boot (equal by token_sha256).CUDA sm_121 device 0 (NVIDIA GB10, memory shared with the host): model 72.71 GiB; 8 streams at once, 1.29 GiB each at a 32768-token window, of 27.9 GiB left after a 9.0 GiB reserve; prompts in passes of up to 1536 rows, a 16.0 GiB prompt cache; own glue kernelsandCUDA sm_121 device 0 (NVIDIA GB10, memory shared with the host): model 74.23 GiB; 8 streams at once, 1.31 GiB each at a 32768-token window, of 26.2 GiB left after a 9.0 GiB reserve; prompts in passes of up to 1536 rows, a 15.7 GiB prompt cache; own glue kernels.--visionon, fromtools/bench_concurrent.py --alone --serialandtoken_shaagainst"draft": false: drafted equals"draft": falseon 8 of 8 text prompts; concurrent equals solo in 52 comparisons (0 unequal, 0 failed) at levels 1, 2 and 4 and temperatures 0 and 1.0; resumed equals fresh on 7 turns, every resumed reply equal to its fresh twin by token_ids with 0 problems and the resumed requests' cached counts [13, 16, 16, 13, 24, 18, 3406]. The same two contracts hold on the default path too (32 of 32 prompts drafted against"draft": false, every concurrent reply equal to its solo run).CHECKPOINT=int4,--vision: both images were refused before any weight was read,error: flashnext: config.json's quantization_config.quant_method differs from the supported Flash Next CUDA layout, so this leg has no result on this engine and is not claimed. That checkpoint is not the same language model as the FP4 one, so an equality there would have shown the unchanged reader path serving beside the quantised one rather than being compared with the FP4 reply.--vision(rank 0 holds the tower), and the shared Qwen-VL CUDA tower Qwen3.5/3.8 uses. Metal and the Python engine are untouched; MLX already reads per-module quantized tower weights.ac2070000and077998f7d9b1. The device checks ran on one NVIDIA GB10 (sm_121), driver 580.178.04, kernel 7.0.0-1019-nvidia-64k, aarch64, on images built fromgit archivetrees of both commits (blob by blob against their owngit ls-treemanifests),nvcr.io/nvidia/pytorch:26.07-py3, nvcc 13.3 (V13.3.73), Zig 0.17.0,zig build -Dnvcc=/usr/local/cuda/bin/nvcc -Doptimize=fast fatbins install native. Checkpointnvidia/Qwen3.8-Flash-Next-FP4-Localatb9ce18a6887e18c089fdea8509a33e63429a3300, and for the floating-point legazampatti/Qwen3.8-Flash-Next-125B-A5B-INT4-AutoRoundat1464274120d36a4d8fcaa934552334a7d83ce0fd.test-qwen-vision-weights-hostandtest-environment-hostpass, andtest-hostruns the vision tests inside its aggregate too); on the device, the load, the image replies and the three exactness contracts above, on the FP4 checkpoint; the floating-point checkpoint was refused by this engine before any weight was read, as recorded above. Not run: Metal, HIP, Windows, and the two-rank path (rank 0 alone runs the tower reader, and no second GPU was used).tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: the device pairs above are a load, sanity and determinism check, and the reason is the checkpoint's own: its snapshot stores the tower quantised, so there is no floating-point twin of this checkpoint's tower to compare replies with. Exactness itself is proven on the host, and this is the strongest evidence in the change: every tensor the reader hands the sink is compared byte for byte against a binary64 reference (core.quant.nvfp4.reference, and e4m3 times 2^(e8m0 - 127) in f64 for MXFP8), for the real reader driven through a written safetensors fixture, and a floating-point tower's bytes are compared against the stored bytes. The decode is exact by construction as well: an e2m1 code times an e4m3 scale is exact in fp32, the multiply by the row's fp32 global rounds once to fp32, and the bf16 rounding follows, which is the same bits as casting the format's exact value to fp32 and then to bf16; an MXFP8 code times a power of two is exact in fp32 with no rounding at all.tools/bench_openai.py: the two cells above, and neither moves beyond the noise rule. The code is unreachable without--vision(Options.visiondefaults to null and only the serve flag sets it), and with it the decode runs once at load on the host, before the first request: the default path executes the same code on the same bytes.Tower.weightBytescounts two bytes an element). The end-to-end cells at one and four streams above carry the default path's figures.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo: run on the device with--visionon against the FP4 checkpoint's tower, with the counts in the Receipt section above (and on the default path too).