Repository navigation
feat(glm): the image tower on vit full attention, behind TF_GLM_VISION_FUSED - #3790
Conversation
|
Reworking this before review, so I am converting it to a draft.
It stays opt-in behind Not run yet: the device gates for the two registrations, and the TP=3 main-against-branch receipt. I will push the new head and rewrite the description only when both are real, so until then the head here is still the old design and its description still describes that. |
a01e2f4 to
68119d4
Compare
|
The rework is pushed: head |
|
Hi @ultradaoto, thanks for the rework. TF_GLM_VISION_FUSED is a strict opt-in that is off by default; with it unset the image path still runs the two cuBLASLt products, and the shared full-attention kernel is one new instance at head dim 64 with the existing kernels left alone. The reply difference on the opt-in path is stated in the description, and the arithmetic is held to the shared float64 reference. The description and serving pins agree with the head, which applies to current main. We do not need the extra side-by-side comparison, and the #3614 question is ours to answer. Nothing is needed from you.
|
|
A heads-up on how this meets #3776, for whichever lands second. #3776 turns The fix is one line,
|
|
Thank you @ultradaoto. The rework is accepted as an opt-in, and nothing further is needed from you on this PR. Noted for landing: if #3776 lands first, glm_vis_qk needs its glm_pdl::enter() line, checked with check-pdl-loads. This PR can land first without that change. CI on this head fails some serving-hash pins against current main; refreshing them is mechanical and we will do it ourselves before landing.
|
68119d4 to
30d9226
Compare
|
Thanks @ultradaoto. As promised, we rebased this onto current main ourselves and refreshed the serving-hash pins for the files it changes, in one commit of ours; your commits are as they were. It is in the landing queue now; nothing is needed from you.
|
30d9226 to
628aa53
Compare
|
Trial-merging On M5 Max with Zig 0.17.0, the resolved tree passed 64 host tests, including the serving pins, plus index emulation and both the GLM native-open and Linux CUDA test-runner compile checks: zig build test-gradient-serving test-environment-host test-glm-index-emulate \
test-glm-logprobs-host test-vision-cli-host compile-glm-native-open \
-Dcpu=apple_m1 -j5 --summary all
zig build compile-cuda-tests -Dtarget=x86_64-linux -j5 --summary allA scratch target selecting On Igor Lessio - AIFLOW LABS |
628aa53 to
4a27414
Compare
|
Thanks @ultradaoto. Nothing more is needed from you on this one. The fused image-tower path stays behind Main has moved since your push: it conflicts in
|
45a4023 to
15394a5
Compare
|
I trial-merged zig build test-gradient-serving test-glm-index-emulate test-glm-logprobs-host \
compile-glm-native-open -Dcpu=apple_m1 -j4 --summary allThose targets passed. I also used a scratch test target to select Igor Lessio - AIFLOW LABS |
c714905 to
2d0b42f
Compare
2d0b42f to
5f88647
Compare
Follow main 7948cc4, which routes the vision launch helper through cuda_pdl.launch. The new glm_vis_qk entry must open with glm_pdl::enter() before reading its predecessor outputs, like every existing GLM vision entry. Keep the incoming arithmetic and both current serving pins unchanged.
…ernelEx Follows main's 7948cc4 (GLM's CUDA kernels as dependent launches), which sends every GLM launch through cuLaunchKernelEx; the test hands those to its recording cuLaunchKernel with cuda_pdl.forwardEx, as main's GLM tests do.
Reference the new vision_attn module from the GLM CUDA test block so the default GLM host test root discovers its launch-geometry coverage.
Combine the PR glm_vision image entry with main’s expanded image list, including idol_decoder and all four Inkling2 images, so every registered CUDA launch resolves its own image.
5f88647 to
7408f4a
Compare
|
Thank you @ultradaoto. 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. |
7b2717aTF_GLM_VISION_FUSED=1What this changes
This head replaces the first design of this pull request (a GLM-only attention kernel,
glm_vis_attn), as my comment of 2026-11-18 said it would. The earlier description and its numbers were for that design and are gone from here.The GLM image tower's attention runs, for each head, as two cuBLASLt products around
glm_vis_softmax: scores [rows, seg] in fp32, the weights in bf16, then the values product. The scores matrix is [patches, patches] for each of 16 heads in each of 24 blocks, so its cost grows with the square of an image's patches, and on a large image the tower is most of the first token's time (#3614).zig/src/cuda/vit.zigalready has full attention over a picture's rows in one kernel:prefill_attention.cu'svision_kernel, which RADIO runs at head dim 80 and MOSS-Image at 128. WithTF_GLM_VISION_FUSED=1, GLM's tower runs that kernel at head dim 64:prefill_attention.cu: one new instance,vision_kernel<64, 8>, and its entry invit.zig's table. Nothing else in either file changes. The 70 existing kernels ofprefill_attention.fatbin(its 14 instances at sm_80, 86, 89, 120 and 121) disassemble the same in main's build and in this head's (cuobjdump -sass, a function at a time; main built at8cbef97, and the kernel sources are unchanged from there to7b2717a), and so do the 50 ofglm_vision.fatbin. Both files are ingradient-serving.tsv, which carries their new hashes.glm_vis_qk(glm_vis_qk.cuh): that kernel reads q, k and v from rows [N, 3 × 1024], which is how the tower's qkv linear leaves them, so GLM's q and k head norm and 2D rotation now happen in place in those rows. It isglm_vis_qkv's arithmetic, and the contract holds it toglm_vis_qkv's bytes.cuda_vision_attn.zigholds both paths: a block is oneglm_vis_qklaunch and one attention launch a frame group, or the old loop, which moved there unchanged.The switch is off by default, and with it unset the branch gives main's bytes for every image reply below.
What differs in the arithmetic, and why it stays a switch:
vision_kerneltakes its maximum a 64-key tile at a time and rescales its running sums, where the cuBLASLt path takes one maximum over a whole row before any weight is rounded to bf16. Both sum in fp32 and round the weights to bf16 before the values product. So the tower's features differ in their last bits and a reply to a prompt with images can differ from the unset path's. It is the arithmetic RADIO and MOSS-Image already serve with, and here it is held to the same float64 reference (below). What I have not done is measure the cuBLASLt path against that reference on the same inputs, so I cannot show "no worse than the current path" side by side; tell me if you want that and in what form.--visionat three ranks: an image pass longer than the net plugin's operation timeout stops every rank (30 s on nccl-mesh-plugin) #3614, where I wrote up the tower's cost on large images and asked whether this would be wanted. That question has no answer yet. I am fine with this waiting or being closed.atc overlap --json: not run, I do not have the tool installed. glm cuda: decode kernels as dependent launches (carries #3673), +3.7% decode at TP=3, same tokens #3776 (the dependent launches carried from glm cuda: decode kernels as dependent launches, +6.8% decode at TP=2, same tokens #3673) also editsglm_vision.cuandcuda_vision.zig; whichever lands later rebases, andglm_vis_qkwould then need that pull request's entry wait.vision_kernelis launched plain here.Checks on this head
68119d4315on main7b2717a20d. Every number here was taken on that commit.python3 tools/zig/lean_check.py, on the base and on this head: 221 on main and 221 on this head, 0 new findings.zig build test-cuda-host: 7,165 of 7,199 passed, 33 skipped, 1 failed:cli_config_test("serve --config: expand reads the file …"). On main7b2717a20don the same box the same test fails: 7,174 of 7,208 passed, 33 skipped, 1 failed. The totals differ because the summary counts only the steps that did not come from the build cache.zig build test-kernel-contract: exit 0.zig build -Dfixed-cpu test-gradient-serving test-glm-index-emulate test-glm-logprobs-host: exit 0.zig fmt --check build.zig zig: clean.git diff --check: clean.python3 tools/zig/cuda_common_check.py: 51 local copies, 0 violations.python3 tools/pr_check.py --base origin/main --pr 3790: 0 errors, 0 warnings.cuda_vision_attn.zigchecks that a block is one q and k launch and one attention launch a frame group (a block of 128 rows a head, for segments of 4 to 6,528 patches) against a recordingcuLaunchKernel;cuda_env_test.zigcovers the switch's reader (unset, 0, 1, a typo refused).tf-cuda-test glm-vision(the comparison withvision_ref.py's torch runs): these boxes have no torch and no reference dumps.TF_GLM_VISION_FUSED=1 tf-cuda-test glm-vision MODEL F32 BF16 IMGruns this path through that test unchanged; I would be glad of a run from someone who has the dumps. Also not run:atc overlap; nvcc 13.2 and later (13.0 only here, so the records are 13.0's); chips other than GB10 on a device (the limits check covers sm_80, 86, 89, 120 and 121 from their compiled images); TP=1 and TP=2; video input (more than one frame group);TF_GLM_VISION_HOST=1together with this switch; the whole device contract (only the two sets named below).Receipt
7b2717a20dand this head built on these boxes the same way. Six starts in one session in this order: main, branch unset, branch with the switch, branch with the switch, branch unset, main. A start: 13 greedy text replies hashed, 16 greedy text requests one at a time, then for each of three sizes two different synthetic screenshots (a 4-token question timed to its reply, then a 96-token description of the same image, hashed), then four screenshots in one message, then a 6-question image check with known answers. In the table, the two numbers before the slash are the two images of the first start of that kind and the two after it are the second start's. The 1.33 and 1.30 at 640 × 480 are a start's first image; the other starts' first images took 1.02 to 1.07 s.--vision, rank 0's image tower, only with the switch set.TF_GLM_VISION_FUSED, default off, exactly0or1(platform/environment.zig,docs/environment.md);core/profile.zigrow forglm5_next, classarithmetic, syntaxone;docs/profiles.mdand the GLM recipe say what it changes.cuda_13.0.r13.0/compiler.36424714_0), driver 580.159.03, Ubuntu 24.04.4, kernel 6.17.0-1018-nvidia, 3 × DGX Spark (GB10). GLM-5.3-Flash-Uncensored EXL3 at revision07135ec082f8,--vision --parallel 4 --kv-cache fp8 --reasoning-effort high --decode-share 0.5,--drafterincoai/GLM-5.3-Flash-DFlash2 at6cc6c481,TF_GLM_CLEAR_THINKING=1 TF_GLM_REQUEST_STARTS=1 TF_GLM_DENSE_BITS=8 TF_GLM_HEAD_BITS=8 TF_GLM_KDA_PAD=1 TF_ROCE=1, greedy.Kernel contract, only when a GPU kernel is new or changed
zig/tests/cuda/contract_glm_vision.zig, family setglm_vision):vision_kernel<64, 8>, throughvit.Attention.fullas the tower calls it. It replaces no kernel: the unset path stays. Reference:contract_attn.zig's float64 attention over each head's keys and values, the reference MOSS-Image's instance is held to. Its test is MOSS-Image's test type made generic over the head dim (contract_vit_full.zig);contract_moss_image_attn.zigis now that type at 128 with its name and shapes unchanged. Served shapes here: 2 heads at 6,528 and 1,024 keys, 16 heads at 196, 36 and 4 keys.glm_vis_qk, throughcuda_vision_attn.headsas the tower calls it. Registered as replacingglm_vis_qkvat segments of one row, where that kernel's head-major q and k are these rows: the shapes gate and the non-finite gate compare bytes withglm_vis_qkvrun on the same inputs. Served shapes: 6,528, 1,024, 196 and 4 patches of 16 heads.tf_ctl_glm_vis_qk_unrounded(the rotation of a head before its bf16 rounding) fails the shapes gate at 6,528 patches, its bytes differing fromglm_vis_qkv's from byte 0.vision_kernel<64, 8>has none of its own: it is the same template as MOSS-Image's 128 instance, whose set has none either. Say if you want one.SUMMARYline and exit status, CUDA on GB10 (sm_121) with nvcc 13.0:tf-cuda-test kernel-contract glm_vis, exit 0:(filtered) SUMMARY 2 kernels: 2 pass gates 1-4, 0 fail, 0 known findings; 1 controls: 1 red as planted, 0 missed; 0 limit problems. Gate lines forglm_vis_qk: byte-identical toglm_vis_qkv's rows including non-finite inputs; five runs byte-identical, inputs and guards untouched; 4 shapes bit-equal to the kernel it replaces. Forvision_kernel<64, 8>: outputs equal the float64 reference's classes with NaN and both infinities planted; five runs byte-identical; 9 shapes exact by its own check; exact sums at k 6,528, where bf16 sums would miss by 256x.tf-cuda-test kernel-contract "moss image vit", exit 0:(filtered) SUMMARY 1 kernels: 1 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems, for the moved test type.kernel-contract-limitson fatbins of sm_80, 86, 89, 120 and 121 reports the three new records current on all five (132, 132, 132, 120, 120 registers at 256 threads and 36,864 dynamic shared bytes forvision_kernel<64, 8>; 27, 27, 27, 25, 25 forglm_vis_qk), and the live check on sm_121 passes them. That command exits 1 on this head with 21 stale records, none of them these:nemo_audio(3),flashnext_mtp fn_row_topk(5),exl3_experts tf_exl3_prompt_guand_down(10) andqwen35 tf_q35_gdn_slots_*(3). I did not run it on main, so I do not know if main reports the same 21.Checklist
glm_vis_qk's test; the host test needs no GPU.)"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Not measured for image prompts on this head; the text hashes include 4 at once against alone.)