Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel

## Unreleased

- Qwen3.5/3.8 and Flash Next on CUDA: `--vision` loads a tower whose linears ModelOpt stores as MXFP8 or NVFP4, as `nvidia/Qwen3.8-Flash-Next-FP4-Local` does, where it stopped at the first quantized linear; they are decoded to bf16 on the host at load, one linear at a time, so the tower runs in bf16 as before, and a floating-point tower is still read as stored (#3727). Thanks to @BadAd84.

- Build: the three bounded top-k selection tests run in the fast `test-lanes-topk-host` step, with a planted failure confirming they can fail by name (#4095, refs #2460). Thanks to @jschmied.

- Lanes: an optional normalized-row view of the prompt features, whose `null` default keeps every existing drafter path as it is (#4132, refs #2485). Thanks to @tacosta.
Expand Down
59 changes: 59 additions & 0 deletions docs/receipts/flashnext-vision-modelopt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# flashnext-vision-modelopt: the ModelOpt tower decode, served

The CUDA vision tower's reader takes every linear's weight as stored bf16, so `--vision` on a checkpoint whose tower ModelOpt quantizes stops at the first quantised linear and names it. This receipt covers that pair on the device: main refuses the checkpoint's tower, and the branch (main plus the commit below) loads it and serves an image, deterministically, with the three exactness contracts holding. The decode itself is proved exact on the host against binary64 references; this window is a load, sanity and determinism check.

## Source and environment

- Branch `ac207000030b969a259143ac32bf2eac6b5e29e7` (head), cut from main `077998f7d9b14adebec3a2acc2caa47ff7ae6ec7` (its tip of 2026-11-16T15:26:10Z). The pull request's current head carries the same change on main `8cbef9777b9a05dfaff99d5aa9c2ce52fe2b00f8`: its code commit `d46832d66` has the five source files of `ac2070000` byte for byte (`zig/src/vision/qwen_cuda_dequant.zig`, `qwen_cuda_weights.zig`, `qwen_cuda_weights_logs.zig`, `qwen_cuda_weights_quant_test.zig`, `qwen_cuda_weights_test.zig`), `zig/src/vision` is unchanged between the two mains, and only the documentation around the change moved. No GPU run is claimed on the current head: every figure below was measured on `ac2070000`.
- Images: `tensorfold-qwen38:vis-m-077998f7` (main) and `tensorfold-qwen38:vis-b-ac207000` (this branch), each built from a `git archive` of its own commit, blob by blob against its own `git ls-tree` manifest, with `zig build -Dnvcc=/usr/local/cuda/bin/nvcc -Doptimize=fast fatbins install native`, the kernels embedded (`tf.kernels=embedded`).
- One NVIDIA GB10 (sm_121) machine, one fresh server an arm through the serving recipe: `CHECKPOINT=nvfp4`, `KV_DTYPE=bf16`, `--parallel 8 --context 32768`, `--vision` only where the leg says so.
- Checkpoint nvidia/Qwen3.8-Flash-Next-FP4-Local at b9ce18a6887e18c089fdea8509a33e63429a3300: 499 vision tensors in 1 shard. Of its two-dimensional weights 1 (the position embedding) take the unchanged stored-bf16 path, 54 are MXFP8 and 56 are NVFP4; the snapshot's dtype census is BF16/bias=166; BF16/weight=57; F32/weight_scale_2=56; F8_E4M3/weight=54; F8_E4M3/weight_scale=56; U8/weight=56; U8/weight_scale=54.
- The checkpoint's own `config.json` gives the tower depth 27, hidden 1152, intermediate 4304, out_hidden 2560, patch 16 and spatial merge 2: two attention linears a block and two MLP linears a block plus the merger's two make the census's 54 MXFP8 and 56 NVFP4 weights.
- The floating-point tower leg uses azampatti/Qwen3.8-Flash-Next-125B-A5B-INT4-AutoRound at 1464274120d36a4d8fcaa934552334a7d83ce0fd: 333 vision tensors, every one floating point (BF16/bias=166; BF16/weight=167). Neither image served it: both refused the checkpoint's `config.json` before reading any weight (`exactness.md`), so this leg has no result on this engine.

## The load pair

Main, `--vision` on the FP4 checkpoint, fails its boot:

2026-11-17T00:30:32.520841803Z error: model.visual.blocks.0.attn.qkv.weight: f8_e4m3 { 3456, 1152 }, expected bf16 { 3456, 1152 }

The branch, same image settings, serves it: the startup line is `[tensorfold] CUDA 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`, and the first image request returns `A close-up portrait captures a tabby cat with striking green eyes, gazing intently at the viewer against a softly blurred background.` (28 tokens, 1.141 s).

## Memory, as the server reports it

| boot | startup line |
|---|---|
| branch, `--vision` off | `[tensorfold] 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 kernels` |
| branch, `--vision` on | `[tensorfold] CUDA 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` |

- The tower's resident bytes, read as the startup line's own model figure on the same image and settings, `--vision` off against on: 72.71 GiB against 74.23 GiB, so the tower holds 1.52 GiB; the per-stream figure moves from 1.29 to 1.31 GiB.
## Speed, the default path (vision off)

The change is unreachable without `--vision`: `Options.vision` is null unless the serve flag sets it, the tower loads only inside that branch, and no kernel, launch, scheduler, KV or prompt arithmetic is edited. The cells therefore measure the same code on the same bytes, and their verdict is the noise rule's.

| streams | main (two runs) | branch (two runs) | branch vs main | verdict |
|---|---|---|---|---|
| 1 | 155.7, 152.9 | 152.1, 153.1 | -1.11% | level |
| 4 | 65.5, 64.3 | 64.4, 64.3 | -0.82% | level |

End-to-end tokens a second, temperature 0, the eight golden prompts; `cells.csv` has every run with its per-request decode rate and its alone checks. The greedy hashes: 8 of 8 prompts carry the same token ids on all four boots, and every concurrent reply equals its solo run.

Each request's own wall time, from the client's first byte to its last: M1 1 streams: requests [1.64]; B1 1 streams: requests [1.68]; B2 1 streams: requests [1.69]; M2 1 streams: requests [1.67] | M1 4 streams: requests [3.5, 5.24, 15.68, 3.15]; B1 4 streams: requests [3.56, 5.28, 15.91, 3.2]; B2 4 streams: requests [3.57, 5.3, 15.95, 3.21]; M2 4 streams: requests [3.56, 5.3, 15.97, 3.2]. At one stream the cell is one request in flight; at four they all start together, and the aggregate is over the window to the last byte, so a straggler trades aggregate for per-stream rate the same way on both arms.

## Exactness

The three contracts with vision on: drafted equals `"draft": false` on 8 prompts; concurrent equals solo in 52 comparisons (0 unequal, 0 failed); resumed equals fresh on 7 turns, every resumed request served [13, 16, 16, 13, 24, 18, 3406] cached tokens and every fresh one 0. The image request's own pairs: same boot twice, `"draft": false`, streamed twice, and the second boot - all equal. `exactness.md` has the pairs and their basis.

## What this window does not establish

- It does not prove the decode is the format's exact decode: that is the host tests' job, which compare every tensor the reader hands the sink against binary64 references byte for byte.
- It does not compare the FP4 tower's replies with a floating-point twin of the same checkpoint: the snapshot stores the tower quantised, so no such twin exists. The int4 checkpoint's tower is floating point, but both configurations were refused before loading, so no reply from a floating-point tower was compared between main and this branch; that equality is not claimed.
- It is one machine, one boot an arm, one image; it says nothing about Metal, HIP, the Python engine, or two ranks.

## Restore

- prod /health 200 (start rc 0) 2026-11-16T22:58:29+00:00

## Method

Two images from verified trees, the recipe's own argument check on both (vision off and on), then one GPU window holding the box's GPU lock: the four text boots ABBA, main's refusing vision boot, the branch's vision boot and its no-cache-prompt reboot, and the two int4 boots. The raw run records (every command and its output) are kept with the measurement and are available on request.
9 changes: 9 additions & 0 deletions docs/receipts/flashnext-vision-modelopt/cells.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
run,build,leg,prompt_set,checkpoint,vision,temperature,streams,end_to_end_tps,per_stream_tps,per_request_decode_tps,makespan_s,alone_equal,alone_unequal,timing_valid,gap_percent,verdict
M1,main,text,golden.json,nvfp4,0,0.0,1,155.7,160.8,160.8,1.64,3,0,True,-1.11,level
B1,branch,text,golden.json,nvfp4,0,0.0,1,152.1,157.0,157.0,1.68,3,0,True,-1.11,level
B2,branch,text,golden.json,nvfp4,0,0.0,1,153.1,158.2,158.2,1.67,3,0,True,-1.11,level
M2,main,text,golden.json,nvfp4,0,0.0,1,152.9,157.9,157.9,1.67,3,0,True,-1.11,level
M1,main,text,golden.json,nvfp4,0,0.0,4,65.5,63.2,63.2,15.64,12,0,True,-0.82,level
B1,branch,text,golden.json,nvfp4,0,0.0,4,64.4,63.0,62.9,15.90,12,0,True,-0.82,level
B2,branch,text,golden.json,nvfp4,0,0.0,4,64.3,62.4,62.5,15.93,12,0,True,-0.82,level
M2,main,text,golden.json,nvfp4,0,0.0,4,64.3,62.2,62.2,15.93,12,0,True,-0.82,level
37 changes: 37 additions & 0 deletions docs/receipts/flashnext-vision-modelopt/exactness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# flashnext-vision-modelopt: exactness

The branch `ac20700003` on main `077998f7d9`, one image (a photograph, sha256 `596aa1e7cb875eb79f437e310381d26b338a81c2da23439704a73c4651e8c4bb`, 240512 bytes), greedy requests (temperature 0, seed 1234, thinking off), fresh server an arm, `--parallel 8 --context 32768 --kv-cache bf16`, `--vision` where the leg is vision.

## The three contracts, with vision on

| contract | result |
|---|---|
| drafted output equals `"draft": false` (eight prompts, `served_exactness.py drafts`) | 8 of 8 equal, 0 unequal, replies of 256 tokens |
| concurrent equals solo (`bench_concurrent.py --alone --serial`, levels 1, 2, 4, temperatures 0 and 1.0) | 52 equal, 0 unequal, 0 failed requests |
| resumed equals fresh (`served_exactness.py turns`, then `fresh` on a `--prompt-cache-gib 0` boot) | 7 of 7 equal on both a plain and a drafted fresh request, 0 problems |

The turns recorded cached prompt tokens [13, 16, 16, 13, 24, 18, 3406] and every fresh request reported 0 cached tokens; the equality basis is token_ids. Problems: {}.

## The image reply, and the pairs it must equal

- the reply, once: `A close-up portrait captures a tabby cat with striking green eyes, gazing intently at the viewer against a softly blurred background.`
- prompt tokens 147, completion tokens 28, drafted 38, accepted 20, wall 1.141 s, text sha256 `f4f12377f25c105d841b7f23a84cb516504b928edd1fe14aac5268ccdbd280f0`
- the same request twice in one boot: equal=True by token_sha256
- the same request with `"draft": false`: equal=True by token_sha256
- the same request streamed, twice: equal=True by token_sha256
- the same request streamed again: equal=True by token_sha256
- the same request on the second boot (no prompt cache): equal=True by token_sha256

## The default path, text only (vision off)

- drafted equals `"draft": false` on the eight prompts: 32 of 32 equal across the four boots (main two, branch two), 0 unequal
- the greedy hashes: 8 of 8 prompts carry the same token ids on all four boots

## The checkpoint's tower: main refuses, the branch serves

- main, `--vision` on the FP4 checkpoint: [2026-11-17T00:30:32.520841803Z error: model.visual.blocks.0.attn.qkv.weight: f8_e4m3 { 3456, 1152 }, expected bf16 { 3456, 1152 }](the log line, quoted)
- the branch: the same request served, reply above; the tower's line in the boot is in the README's memory table.

## The floating-point tower (CHECKPOINT=int4)

- 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.
6 changes: 4 additions & 2 deletions docs/vision.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ tensorfold serve TensorFold/Qwen3.8-27B-MLX-4bit --vision
tensorfold serve TensorFold/GLM-5.3-Flash-MLX-4bit-MTP --vision
```

GLM-5.3-Flash image input is currently MLX-only. CUDA uses the same flag with `--backend cuda` for supported Qwen checkpoints; their vision tower must use floating-point weights.
GLM-5.3-Flash image input is currently MLX-only. CUDA uses the same flag with `--backend cuda` for supported Qwen checkpoints; their vision tower must use floating-point weights. The native server decodes ModelOpt's MXFP8 and NVFP4 tower linears, as `nvidia/Qwen3.8-Flash-Next-FP4-Local` stores its tower, to bf16 on the host while the tower loads, so the tower runs in bf16 as before; a floating-point tower is read as stored, byte for byte, so its rows do not change. The decoded tower uploads as bf16, so its device bytes are a floating-point tower's, and the decode holds one linear on the host at a time.

On a small CUDA card the resident tower and its 4 GiB workspace reserve take a large part of the startup budget. `--vision-offload` (with `--vision`, CUDA only) keeps the tower in host RAM, copies it to the GPU only while an image is encoded, and reserves 2.25 GiB instead. On one RTX 4090 with the Qwen3.8-27B EXL3 3.50bpw pack and DFlash2, the largest window with `--vision` went from 11,922 to 38,686 tokens; a 4,096-token image peaked about 1.3 GB above idle. Each image request pays the copy of the roughly 0.9 GiB tower to the GPU and back.
MLX also reads per-module quantized tower weights when the checkpoint declares their format.
Expand Down Expand Up @@ -390,5 +390,7 @@ budget never has to make room for an image. A request's images go through the to
replace the `<|image_pad|>` placeholders in the prompt chunks, which rotate at M-RoPE's t, h and w positions
(interleaved sections 11, 11 and 10), and the reply's rows rotate at their position plus the layout's shift, as
transformers' `get_rope_index` lays them out. Text-only requests keep their bits. One image holds at most 4,096
tokens (one tower call); `--vision-image-tokens` bounds a request's images together. JPEG needs libturbojpeg on the
tokens (one tower call); `--vision-image-tokens` bounds a request's images together. A tower whose linears ModelOpt
stores as MXFP8 or NVFP4, as the Flash Next FP4 checkpoints store theirs, is decoded to bf16 at load
(`zig/src/vision/qwen_cuda_weights.zig`; a floating-point tower is read as stored). JPEG needs libturbojpeg on the
machine (PNG decodes everywhere); video parts are refused.
Loading
Loading