From 78d862216c3f9388a6d38dd54677ce46e20e6f3d Mon Sep 17 00:00:00 2001 From: ultradaoto Date: Wed, 18 Nov 2026 11:48:35 -0800 Subject: [PATCH 1/8] feat(glm): the image tower on vit full attention, behind TF_GLM_VISION_FUSED --- docs/environment.md | 1 + docs/kernel-contract.md | 5 + docs/profiles.md | 1 + docs/recipes/glm-5.3-flash-cuda.md | 5 + zig/kernels/cuda/contract_controls_set.cu | 1 + .../cuda/contract_glm_vision_controls.cuh | 10 + zig/kernels/cuda/glm_vis_qk.cuh | 36 +++ zig/kernels/cuda/glm_vision.cu | 9 + zig/kernels/cuda/prefill_attention.cu | 5 +- zig/src/core/contract/glm_cuda_records.zig | 3 + zig/src/core/profile.zig | 2 + zig/src/cuda/vit.zig | 2 +- zig/src/families/glm/cuda.zig | 1 + zig/src/families/glm/cuda_env_test.zig | 2 + zig/src/families/glm/cuda_vision.zig | 71 ++---- zig/src/families/glm/cuda_vision_attn.zig | 104 +++++++++ zig/src/platform/environment.zig | 1 + zig/tests/cuda/contract_family_sets.zig | 5 + zig/tests/cuda/contract_glm_vision.zig | 208 ++++++++++++++++++ zig/tests/cuda/contract_moss_image_attn.zig | 158 +------------ zig/tests/cuda/contract_vit_full.zig | 163 ++++++++++++++ zig/tests/fixtures/gradient-serving.tsv | 4 +- 22 files changed, 581 insertions(+), 216 deletions(-) create mode 100644 zig/kernels/cuda/contract_glm_vision_controls.cuh create mode 100644 zig/kernels/cuda/glm_vis_qk.cuh create mode 100644 zig/src/families/glm/cuda_vision_attn.zig create mode 100644 zig/tests/cuda/contract_glm_vision.zig create mode 100644 zig/tests/cuda/contract_vit_full.zig diff --git a/docs/environment.md b/docs/environment.md index f3028337f0a..e6f85622a56 100644 --- a/docs/environment.md +++ b/docs/environment.md @@ -69,6 +69,7 @@ Diagnostics quote and escape the supplied text so it cannot create another termi | `TF_DRAMA_REFERENCE_CACHE` | Drama 3 on CUDA: kept reference states, 0 (off) through 16; default 0. Checked when the checkpoint opens, with its own message | | `TF_GLM_HOST_CACHE` | Exactly `0` or `1`; default off (kept GLM states on the device) | | `TF_GLM_VISION_HOST` | Exactly `0` or `1`; default off (GLM vision weights on the device) | +| `TF_GLM_VISION_FUSED` | Exactly `0` or `1`; default off (the GLM vision tower's attention as cuBLASLt products around a softmax kernel) | | `TF_GLM_PAIR_EXPERTS` | Exactly `0` or `1`; default off. On, GLM paired CUDA prompt chunks share 128-pair routed NVFP4 expert items, with separate per-chunk outputs and unchanged slot combines | | `TF_GLM_PROF` | Exactly `0` or `1`; default off (no GLM section timing). On, all four prompt traces are created before readiness; startup, gate, final-draw, cache-admission and memory-counter records go to the log. A prompt step is one chunk, with no pair or solo steps, so its prompt timings are of that shape | | `TF_GLM_LINK_WAIT` | Exactly `0` or `1`; default off (short GLM steps go to the other ranks unwaited) | diff --git a/docs/kernel-contract.md b/docs/kernel-contract.md index 4841b24f5be..16602f4fe46 100644 --- a/docs/kernel-contract.md +++ b/docs/kernel-contract.md @@ -635,6 +635,11 @@ of the two branches), each output within float64's range at its bf16 points, and `contract_attn.zig`'s float64 reference (`audio-contract`; eight controls built from `nemo_audio.cuh` with one thing dropped each). +CUDA also checks GLM-5.3-Flash's image tower on that attention: `vision_kernel` at head dim 64 against the same +float64 reference (`contract_vit_full.zig`, the MOSS-Image test's type at any head dim), and `glm_vis_qk`, which +norms and rotates q and k in place in the rows it reads, bit-equal to `glm_vis_qkv` at segments of one row (one +control: the rotation before a head's bf16 rounding). + CPU: Qwen3.5-2B's affine projection (4 bits, groups of 64, `cpu_kernels.zig`) at the widths the 2B calls it, one row to a 128-row prompt chunk, registered once for each chain count of its projection classes (16; 32 for the delta rule's a and b; 8 for the head), and its RMS norm over 2048-wide rows; each registration's runs take 1 to 8 threads in turn, diff --git a/docs/profiles.md b/docs/profiles.md index 2b54701868e..a4ad1fceafe 100644 --- a/docs/profiles.md +++ b/docs/profiles.md @@ -99,6 +99,7 @@ still carries each resolved value, so ranks that disagree still stop before weig | --- | --- | --- | --- | | `TENSORFOLD_KOLIBRI_KV_PAGES` | CUDA, Kolibri-1 | arithmetic | Exact `0`, which disables otherwise requested pages | | `TENSORFOLD_DORY_KV_PAGES` | CUDA, Dory | arithmetic | Every present value except exact `0`, including empty text | +| `TF_GLM_VISION_FUSED` | CUDA, GLM | arithmetic | Exact `1`, which runs the vision tower's attention as the towers' shared full-attention kernel | | `GEMMA_DRAFT_BF16` | Metal, Gemma 4 | debug | `all`, `fc`, `self_attn.q_proj`, `self_attn.k_proj`, `self_attn.o_proj`, `mlp.gate_proj`, `mlp.down_proj` | | `TF_ANE_COLUMNS` | Metal, Qwen3.5 dense adapter | experimental | Nonzero columns; admission still decides whether the share is supported | | `TF_PROMPT_ROWS` | Metal, Qwen3.5 dense/MoE adapter | arithmetic | Every explicit native prompt width | diff --git a/docs/recipes/glm-5.3-flash-cuda.md b/docs/recipes/glm-5.3-flash-cuda.md index bc2627e8696..cde8f587b69 100644 --- a/docs/recipes/glm-5.3-flash-cuda.md +++ b/docs/recipes/glm-5.3-flash-cuda.md @@ -54,6 +54,11 @@ drafted at one stream, and about 1,430 prompt tokens a second from 2,048 to 65,5 `TF_GLM_VISION_HOST=1` keeps the tower's bf16 weights in pinned host memory and copies each part of a pass into one device slot as it runs (240 MiB for GLM-5.3-Flash's tower instead of its 1.05 GiB), leaving rank 0 that much more room for KV pages. Checked on two RTX PRO 6000 Blackwell cards. + `TF_GLM_VISION_FUSED=1` (opt-in) runs the tower's attention as the full-attention kernel the other towers use + (`vision_kernel` at head dim 64, the same code as RADIO's and MOSS-Image's) instead of two cuBLASLt products + around a softmax kernel: no scores or weights are written, so a large image's first token comes much sooner. + That kernel takes its maximum a 64-key tile at a time and sums in another order than cuBLASLt, so a reply to a + prompt with images can differ from the unset path's; text-only prompts are untouched. - Nonstreaming `/v1/completions` requests return `prompt_logprobs`, structured output follows its schema with drafts on, and required and named tool calls use the model's tool markup ([1.1.1](../../CHANGELOG.md#111): #1016 to #1018). - `--kv-cache fp8` is an opt-in FP8 latent cache ([1.1.2](../../CHANGELOG.md#112)); BF16 remains the default and the diff --git a/zig/kernels/cuda/contract_controls_set.cu b/zig/kernels/cuda/contract_controls_set.cu index 29d0a35f8cd..38717e38f80 100644 --- a/zig/kernels/cuda/contract_controls_set.cu +++ b/zig/kernels/cuda/contract_controls_set.cu @@ -12,3 +12,4 @@ #include "contract_controls_idol_decoder.cuh" #include "contract_qwen3_asr_controls.cuh" #include "contract_ricursive_controls.cuh" +#include "contract_glm_vision_controls.cuh" diff --git a/zig/kernels/cuda/contract_glm_vision_controls.cuh b/zig/kernels/cuda/contract_glm_vision_controls.cuh new file mode 100644 index 00000000000..f5de93a08b1 --- /dev/null +++ b/zig/kernels/cuda/contract_glm_vision_controls.cuh @@ -0,0 +1,10 @@ +// Planted control for glm_vision's in-place q and k: the rotation of a head before its bf16 rounding. + +#include "glm_vis_qk.cuh" + +extern "C" __global__ void tf_ctl_glm_vis_qk_unrounded(__nv_bfloat16* qkv, const __nv_bfloat16* __restrict__ qn, + const __nv_bfloat16* __restrict__ kn, + const int* __restrict__ pos, const float* __restrict__ inv_freq, + int N, int H, float eps) { + glm_vis_rows::qk(qkv, qn, kn, pos, inv_freq, N, H, eps); +} diff --git a/zig/kernels/cuda/glm_vis_qk.cuh b/zig/kernels/cuda/glm_vis_qk.cuh new file mode 100644 index 00000000000..76356950fe0 --- /dev/null +++ b/zig/kernels/cuda/glm_vis_qk.cuh @@ -0,0 +1,36 @@ +// GLM image tower: glm_vis_qkv's q and k, in place in the rows vit's full attention reads. +#pragma once + +#include + +namespace glm_vis_rows { + +// A warp a (row, head) of qkv [N, 3 H 64]: q and k head-RMSNormed, then rotated by the row's 2D angles; MID as served. +template +__device__ __forceinline__ void qk(__nv_bfloat16* qkv, const __nv_bfloat16* __restrict__ qn, + const __nv_bfloat16* __restrict__ kn, const int* __restrict__ pos, + const float* __restrict__ inv_freq, int N, int H, float eps) { + const long long item = blockIdx.x * (long long)(blockDim.x >> 5) + (threadIdx.x >> 5); + if (item >= (long long)N * H) return; + const int lane = threadIdx.x & 31; + const int n = (int)(item / H), h = (int)(item % H); + const int p = lane < 16 ? pos[2 * n] : pos[2 * n + 1]; + const float ang = (float)p * inv_freq[lane & 15]; + const float c = cosf(ang), s = sinf(ang); + for (int which = 0; which < 2; ++which) { + __nv_bfloat16* x = qkv + ((long long)n * 3 + which) * H * 64 + h * 64; + const __nv_bfloat16* wn = which ? kn : qn; + float a = __bfloat162float(x[lane]), b = __bfloat162float(x[lane + 32]); + float ss = a * a + b * b; + for (int o = 16; o > 0; o >>= 1) ss += __shfl_xor_sync(0xffffffffu, ss, o); + const float inv = rsqrtf(ss / 64.f + eps); + a = a * inv * __bfloat162float(wn[lane]); + b = b * inv * __bfloat162float(wn[lane + 32]); + if (MID) a = __bfloat162float(__float2bfloat16_rn(a)), b = __bfloat162float(__float2bfloat16_rn(b)); + // rotate_half: dims l < 32 take -x[l + 32], dims l + 32 take x[l] + x[lane] = __float2bfloat16_rn(a * c - b * s); + x[lane + 32] = __float2bfloat16_rn(b * c + a * s); + } +} + +} // namespace glm_vis_rows diff --git a/zig/kernels/cuda/glm_vision.cu b/zig/kernels/cuda/glm_vision.cu index 9887b23f457..ff69c83244c 100644 --- a/zig/kernels/cuda/glm_vision.cu +++ b/zig/kernels/cuda/glm_vision.cu @@ -4,6 +4,8 @@ #include #include "glm_pdl.cuh" +#include "glm_vis_qk.cuh" + namespace { __device__ __forceinline__ float bf(__nv_bfloat16 x) { return __bfloat162float(x); } __device__ __forceinline__ __nv_bfloat16 tobf(float x) { return __float2bfloat16_rn(x); } @@ -108,6 +110,13 @@ extern "C" __global__ void glm_vis_qkv(const __nv_bfloat16* __restrict__ qkv, co vt[(blk * 64 + lane + 32) * seg + j] = v[lane + 32]; } +// vit's full attention inputs: glm_vis_qkv's q and k, in place in qkv's rows [N, 3 H 64]; a warp a (row, head). +extern "C" __global__ void glm_vis_qk(__nv_bfloat16* qkv, const __nv_bfloat16* __restrict__ qn, + const __nv_bfloat16* __restrict__ kn, const int* __restrict__ pos, + const float* __restrict__ inv_freq, int N, int H, float eps) { + glm_vis_rows::qk(qkv, qn, kn, pos, inv_freq, N, H, eps); +} + // A scores row's softmax: pr = bf16(exp(scale (s - max))) and its sum (of the bf16 values), a block a row extern "C" __global__ void glm_vis_softmax(const float* __restrict__ sc, __nv_bfloat16* __restrict__ pr, float* __restrict__ sums, int n, float scale) { diff --git a/zig/kernels/cuda/prefill_attention.cu b/zig/kernels/cuda/prefill_attention.cu index d0be0a7b089..502f1bf400a 100644 --- a/zig/kernels/cuda/prefill_attention.cu +++ b/zig/kernels/cuda/prefill_attention.cu @@ -332,10 +332,7 @@ template __global__ void tf_prefill_attention::tree_kernel<64, 8, 4, 8>(const __ // Head dim 72, eight warps of one head, eight staging slots (SigLIP2's tower, 72 dims padded to 80 inside). template __global__ void tf_prefill_attention::full_kernel<72, 8, 8>(const __nv_bfloat16* __restrict__, __nv_bfloat16* __restrict__, int, int, float); -// Head dim 80, eight warps, two blocks an SM (RADIO's tower, 16 heads of 80): full_kernel<80>'s bits, 1.35x faster. -template __global__ void tf_prefill_attention::vision_kernel<80, 8>(const __nv_bfloat16* __restrict__, __nv_bfloat16* __restrict__, int, int, - float); -// Head dim 64, eight warps (Qwen3-ASR's audio tower, 14 or 16 heads of 64 over a window of its rows). +// Head dim 64, eight warps (Qwen3-ASR's audio tower and GLM-5.3-Flash's image tower over their respective windows or frame groups). template __global__ void tf_prefill_attention::vision_kernel<64, 8>(const __nv_bfloat16* __restrict__, __nv_bfloat16* __restrict__, int, int, float); // Head dim 128, eight warps (MOSS-Image's denoiser, 24 heads of 128 over its image and prompt rows). diff --git a/zig/src/core/contract/glm_cuda_records.zig b/zig/src/core/contract/glm_cuda_records.zig index 1e027f2dd7d..5bc70c05ad7 100644 --- a/zig/src/core/contract/glm_cuda_records.zig +++ b/zig/src/core/contract/glm_cuda_records.zig @@ -62,6 +62,9 @@ pub const cuda = [_]registry.CudaRecord{ .{ .launch = .{ .name = "glm_ops tf_glm_kvh_copy_cached", .symbol = "tf_glm_kvh_copy_cached", .image = "glm_ops", .threads = 256, .min_sm = 80 }, .usage = .{ .{ .regs = 42, .static = 0, .bound = 0 }, .{ .regs = 46, .static = 0, .bound = 0 }, .{ .regs = 46, .static = 0, .bound = 0 }, .{ .regs = 34, .static = 0, .bound = 0 }, .{ .regs = 34, .static = 0, .bound = 0 } } }, .{ .launch = .{ .name = "glm_ops tf_glm_kvh_keep", .symbol = "tf_glm_kvh_keep", .image = "glm_ops", .threads = 256, .min_sm = 80 }, .usage = .{ .{ .regs = 30, .static = 0, .bound = 0 }, .{ .regs = 34, .static = 0, .bound = 0 }, .{ .regs = 34, .static = 0, .bound = 0 }, .{ .regs = 38, .static = 0, .bound = 0 }, .{ .regs = 38, .static = 0, .bound = 0 } } }, .{ .launch = .{ .name = "glm_ops tf_glm_kvh_unmark", .symbol = "tf_glm_kvh_unmark", .image = "glm_ops", .threads = 256, .min_sm = 80 }, .usage = .{ .{ .regs = 16, .static = 0, .bound = 0 }, .{ .regs = 16, .static = 0, .bound = 0 }, .{ .regs = 16, .static = 0, .bound = 0 }, .{ .regs = 16, .static = 0, .bound = 0 }, .{ .regs = 16, .static = 0, .bound = 0 } } }, + .{ .launch = .{ .name = "glm_vision glm_vis_qk", .symbol = "glm_vis_qk", .image = "glm_vision", .threads = 256, .min_sm = 80 }, .usage = .{ .{ .regs = 27, .static = 0, .bound = 0 }, .{ .regs = 27, .static = 0, .bound = 0 }, .{ .regs = 27, .static = 0, .bound = 0 }, .{ .regs = 25, .static = 0, .bound = 0 }, .{ .regs = 25, .static = 0, .bound = 0 } } }, + .{ .launch = .{ .name = "glm_vision tf_ctl_glm_vis_qk_unrounded", .symbol = "tf_ctl_glm_vis_qk_unrounded", .image = "contract_controls", .threads = 256, .min_sm = 80 }, .usage = .{ .{ .regs = 29, .static = 0, .bound = 0 }, .{ .regs = 28, .static = 0, .bound = 0 }, .{ .regs = 28, .static = 0, .bound = 0 }, .{ .regs = 24, .static = 0, .bound = 0 }, .{ .regs = 24, .static = 0, .bound = 0 } } }, + .{ .launch = .{ .name = "glm_vision vit vision_kernel<64, 8>", .symbol = "_ZN20tf_prefill_attention13vision_kernelILi64ELi8EEEvPK13__nv_bfloat16PS1_iif", .image = "prefill_attention", .threads = 256, .dynamic = 36864 }, .usage = .{ .{ .regs = 132, .static = 0, .bound = 256 }, .{ .regs = 132, .static = 0, .bound = 256 }, .{ .regs = 132, .static = 0, .bound = 256 }, .{ .regs = 120, .static = 0, .bound = 256 }, .{ .regs = 120, .static = 0, .bound = 256 } } }, }; /// nvcc 13.2's usage where it differs from 13.0's. diff --git a/zig/src/core/profile.zig b/zig/src/core/profile.zig index 9131634a82d..12b4c9eb7fc 100644 --- a/zig/src/core/profile.zig +++ b/zig/src/core/profile.zig @@ -24,6 +24,7 @@ pub const Switch = enum { TF_GLM_HOST_CACHE, TF_GLM_PAIR_EXPERTS, TF_GLM_VISION_HOST, + TF_GLM_VISION_FUSED, TF_GLM_PDL, TF_GLM_PROMPT_STEPS, TF_GLM_SHARED, @@ -167,6 +168,7 @@ pub const entries = [_]Entry{ .{ .id = .TF_GLM_HOST_CACHE, .families = &.{"glm5_next"}, .class = .identical, .syntax = .one, .effect = "Keep kept prompt states in pinned host memory instead of on the device", .evidence = "#2370" }, .{ .id = .TF_GLM_VISION_HOST, .families = &.{"glm5_next"}, .class = .identical, .syntax = .one, .effect = "Keep the vision tower's weights in pinned host memory, staged a unit at a time", .evidence = "#2370" }, .{ .id = .TF_GLM_PAIR_EXPERTS, .families = &.{"glm5_next"}, .class = .identical, .syntax = .one, .effect = "Route two paired CUDA prompt chunks through 128-pair NVFP4 expert items", .evidence = "REV25 E1; default-off; host gates; device A/B required" }, + .{ .id = .TF_GLM_VISION_FUSED, .families = &.{"glm5_next"}, .class = .arithmetic, .syntax = .one, .effect = "Run the vision tower's attention as vit's full-attention kernel; its sums run in another order than cuBLASLt's", .evidence = "#3614" }, .{ .id = .TF_GLM_PDL, .families = &.{"glm5_next"}, .class = .identical, .report_values = &.{"0"}, .effect = "Exact 0 turns off the forward's dependent launches", .evidence = "#2370" }, .{ .id = .TF_GLM_PROMPT_STEPS, .families = &.{"glm5_next"}, .class = .identical, .report_values = &.{"0"}, .effect = "Exact 0 runs rank 0's prompt passes whole, not in chunks", .evidence = "#2370" }, .{ .id = .TF_GLM_SHARED, .families = &.{"glm5_next"}, .class = .identical, .report_values = &.{"0"}, .effect = "Exact 0 runs each of rank 0's windows in its own forward", .evidence = "#2370" }, diff --git a/zig/src/cuda/vit.zig b/zig/src/cuda/vit.zig index 0e9068dab46..6d56690b677 100644 --- a/zig/src/cuda/vit.zig +++ b/zig/src/cuda/vit.zig @@ -297,7 +297,7 @@ const Full = struct { /// Full attention by head dim: Qwen3-ASR's 64, SigLIP2's 72, RADIO's 80 (full_kernel's bits), MOSS-Image's 128. const fulls = [_]Full{ - .{ .dim = 64, .warps = 8 }, + .{ .dim = 64, .warps = 8 }, // Qwen3-ASR's audio tower and GLM-5.3-Flash's image tower .{ .dim = 72, .warps = 8, .slots = 8 }, .{ .dim = 80, .warps = 8 }, .{ .dim = 128, .warps = 8 }, diff --git a/zig/src/families/glm/cuda.zig b/zig/src/families/glm/cuda.zig index 394e488e33e..01f1a145d45 100644 --- a/zig/src/families/glm/cuda.zig +++ b/zig/src/families/glm/cuda.zig @@ -3,6 +3,7 @@ pub const experts = @import("cuda_experts.zig"); pub const exl3 = @import("cuda_exl3.zig"); pub const vision = @import("cuda_vision.zig"); +pub const vision_attn = @import("cuda_vision_attn.zig"); pub const mm = @import("cuda_mm.zig"); pub const vision_config = @import("vision_config.zig"); pub const image_core = @import("image_core.zig"); diff --git a/zig/src/families/glm/cuda_env_test.zig b/zig/src/families/glm/cuda_env_test.zig index cf54528635f..41ca0dfbe4b 100644 --- a/zig/src/families/glm/cuda_env_test.zig +++ b/zig/src/families/glm/cuda_env_test.zig @@ -10,6 +10,7 @@ const Name = struct { name: [:0]const u8, default: bool = false }; const switches = [_]Name{ .{ .name = "TF_GLM_HOST_CACHE" }, .{ .name = "TF_GLM_VISION_HOST" }, + .{ .name = "TF_GLM_VISION_FUSED" }, .{ .name = "TF_GLM_PROF" }, .{ .name = "TF_GLM_LINK_WAIT" }, .{ .name = "TF_GLM_PDL", .default = true }, @@ -129,6 +130,7 @@ test "GLM strict env: the actual readers and the open's check keep defaults, 0 a const cases = [_]Case{ .{ .name = "TF_GLM_HOST_CACHE", .read = @import("cuda_snapshot_pages.zig").onHost }, .{ .name = "TF_GLM_VISION_HOST", .read = @import("cuda_vision_weights.zig").onHost }, + .{ .name = "TF_GLM_VISION_FUSED", .read = @import("cuda_vision_attn.zig").wanted }, .{ .name = "TF_GLM_PROF", .read = @import("cuda_prof.zig").Prof.wanted }, .{ .name = "TF_GLM_WIDE_EXPERT_TILE", .read = @import("cuda_experts.zig").wideExpertTile }, }; diff --git a/zig/src/families/glm/cuda_vision.zig b/zig/src/families/glm/cuda_vision.zig index 75bc5129782..d121194544f 100644 --- a/zig/src/families/glm/cuda_vision.zig +++ b/zig/src/families/glm/cuda_vision.zig @@ -7,19 +7,20 @@ const core = @import("core"); const formats = @import("cuda_formats.zig"); const projection = @import("cuda_proj.zig"); const tower_names = @import("vision_names.zig"); +const attn = @import("cuda_vision_attn.zig"); const H: i64 = 1024; // hidden -const HEADS: i64 = 16; -const HD: i64 = 64; // a head's width +const HEADS = attn.HEADS; +const HD = attn.HD; const MLP: i64 = 4096; const PATCH: i64 = 1176; // 3 channels x 2 frames x 14 x 14 const MERGE: i64 = 2; const OUT: i64 = 4096; // the merged rows' width (the language model's) const PROJ: i64 = 10240; // the merger's SwiGLU width pub const DEPTH = 24; -const CHUNK: i64 = 2048; // query rows a scores product covers +const CHUNK = attn.CHUNK; const ROWS: i64 = 4096; // rows a linear's fp32 product covers (the scratch's bound) -const EPS: f32 = 1e-5; +pub const EPS: f32 = 1e-5; const LIMIT: f32 = 10.0; const weights = @import("cuda_vision_weights.zig"); @@ -107,6 +108,7 @@ pub const Funcs = struct { embed32: cuda.Function, rmsnorm: cuda.Function, qkv: cuda.Function, + qk: cuda.Function, softmax: cuda.Function, head_out: cuda.Function, swiglu: cuda.Function, @@ -120,7 +122,7 @@ pub const Funcs = struct { } }; -fn launch(r: *const Run, f: cuda.Function, grid: cuda.Dim3, threads: u32, a: *cuda.Args) !void { +pub fn launch(r: *const Run, f: cuda.Function, grid: cuda.Dim3, threads: u32, a: *cuda.Args) !void { try cuda_pdl.launch(f, .{ .grid = grid, .block = .{ .x = threads } }, r.stream, a); } @@ -149,6 +151,7 @@ pub const Tower = struct { bytes: u64 = 0, staged: ?staging.Stage = null, // TF_GLM_VISION_HOST: the units' copies from host memory into one device slot stages: ?[]f32 = null, // checks: the fp32 stream after the patch embedding and after every block, read back + full: ?cuda.vit.Attention = null, // TF_GLM_VISION_FUSED=1: vit's full attention, no scores or weights written /// The tower's tensors (either prefix) in one allocation: bf16 as stored, MXFP8 and NVFP4 packed for ``ql``. pub fn load(gpa: std.mem.Allocator, io: std.Io, d: *const cuda.Driver, dir: []const u8, ql: cuda.qlinear.Linear) !Tower { @@ -173,6 +176,10 @@ pub const Tower = struct { }; var t: Tower = .{ .gpa = gpa, .d = d, .lt = try cuda.cublaslt.Library.open(), .mem = try weights.Weights.alloc(d, total, try weights.onHost()), .ql = ql, .inv_freq = try cuda.DeviceBuffer.alloc(d, 16 * 4), .linears = .init(gpa), .ws = undefined }; errdefer t.deinit(); + if (try attn.wanted()) { + t.full = try cuda.vit.Attention.load(d); + std.log.info("glm: the image tower's attention as vit's full attention (TF_GLM_VISION_FUSED)", .{}); + } t.bytes = t.mem.deviceBytes(); t.ws = try cuda.DeviceBuffer.alloc(d, t.ws_len); var at: u64 = 0; @@ -249,6 +256,7 @@ pub const Tower = struct { while (it.next()) |l| l.deinit(); t.linears.deinit(); if (t.staged) |*s| s.deinit(); + if (t.full) |*f| f.unload(); t.mem.free(); t.inv_freq.free(); t.ws.free(); @@ -269,7 +277,7 @@ pub const Tower = struct { } /// D[m, n] = X[m, k] . W[n, k]^T (fp32 or bf16 out), a plan per shape kept for the next image. - fn linear(t: *Tower, ru: *const Run, x: u64, w: u64, d: u64, m: i64, n: i64, kk: i64, f32_out: bool) !void { + pub fn linear(t: *Tower, ru: *const Run, x: u64, w: u64, d: u64, m: i64, n: i64, kk: i64, f32_out: bool) !void { const key: LinKey = .{ .m = @intCast(m), .n = @intCast(n), .k = @intCast(kk), .f32_out = f32_out }; const gop = try t.linears.getOrPut(key); if (!gop.found_existing) { @@ -330,7 +338,7 @@ pub const Tower = struct { return ptr; } - fn grid1(n: i64) cuda.Dim3 { + pub fn grid1(n: i64) cuda.Dim3 { return .{ .x = @intCast(@min(std.math.divCeil(i64, n, 256) catch unreachable, 65535)) }; } @@ -461,58 +469,15 @@ pub const Tower = struct { try launch(ru, ru.f.embed32, grid1(rows * H), 256, &b); } } - const scale: f32 = 1.0 / @sqrt(@as(f32, HD)); if (t.stages) |dst| try t.stage(ru, dst, 0, x32, N); + const ab: attn.Buffers = .{ .qkv = big, .qh = qh, .kh = kh, .vt = vt, .att = att, .sc = sc, .pr = pr, .oh = oh, .sums = sums }; for (t.blocks, 1..) |bl, bi| { defer if (t.stages) |dst| t.stage(ru, dst, bi, x32, N) catch {}; try t.bring(ru, bi); try rmsnorm(ru, x32, bl.n1, xn, N, H); try t.dense(ru, xn, bl.qkv_w, bl.qkv_b, big, 0, acc, N, 3 * H, H); - { - var a: cuda.Args = .{}; - a.add(big); - a.add(bl.qn); - a.add(bl.kn); - a.add(dpos); - a.add(t.inv_freq.ptr); - a.add(qh); - a.add(kh); - a.add(vt); - a.add(@as(i32, @intCast(N))); - a.add(@as(i32, @intCast(seg))); - a.add(@as(i32, @intCast(HEADS))); - a.add(EPS); - try launch(ru, ru.f.qkv, .{ .x = @intCast(std.math.divCeil(i64, N * HEADS, 8) catch unreachable) }, 256, &a); - } - // each frame group attends within itself, per head, in query chunks (q, k [t, H, seg, 64]; v transposed) - var g: i64 = 0; - while (g < gt) : (g += 1) { - var h: i64 = 0; - while (h < HEADS) : (h += 1) { - const blk: u64 = @intCast((g * HEADS + h) * seg * HD * 2); - var c: i64 = 0; - while (c < seg) : (c += CHUNK) { - const rows = @min(CHUNK, seg - c); - try t.linear(ru, qh + blk + @as(u64, @intCast(c * HD * 2)), kh + blk, sc, rows, seg, HD, true); - var a: cuda.Args = .{}; - a.add(sc); - a.add(pr); - a.add(sums); - a.add(@as(i32, @intCast(seg))); - a.add(scale); - try launch(ru, ru.f.softmax, .{ .x = @intCast(rows) }, 256, &a); - try t.linear(ru, pr, vt + blk, oh, rows, HD, seg, true); - var b: cuda.Args = .{}; - b.add(oh); - b.add(sums); - b.add(att + @as(u64, @intCast((g * seg + c) * H * 2))); - b.add(@as(i32, @intCast(rows))); - b.add(@as(i32, @intCast(HEADS))); - b.add(@as(i32, @intCast(h))); - try launch(ru, ru.f.head_out, grid1(rows * HD), 256, &b); - } - } - } + try attn.heads(t, ru, ab, bl.qn, bl.kn, dpos, N, seg); + try attn.run(t, ru, ab, gt, seg); try t.dense(ru, att, bl.proj_w, bl.proj_b, 0, x32, acc, N, H, H); try rmsnorm(ru, x32, bl.n2, xn, N, H); try t.swiglu(ru, xn, bl.g_w, bl.g_b, bl.u_w, bl.u_b, big, acc, acc2, N, MLP, H); diff --git a/zig/src/families/glm/cuda_vision_attn.zig b/zig/src/families/glm/cuda_vision_attn.zig new file mode 100644 index 00000000000..eb1885b80a2 --- /dev/null +++ b/zig/src/families/glm/cuda_vision_attn.zig @@ -0,0 +1,104 @@ +//! The image tower's attention on CUDA: each frame group attends within itself. + +const std = @import("std"); +const cuda = @import("cuda"); +const vision = @import("cuda_vision.zig"); + +pub const HEADS: i64 = 16; +pub const HD: i64 = 64; // a head's width +pub const CHUNK: i64 = 2048; // query rows a scores product covers + +/// TF_GLM_VISION_FUSED=1: rank 0's tower runs vit's full attention; unset or 0, a head in chunks around cuBLASLt. +pub fn wanted() !bool { + return @import("sys").environment.value(bool, "TF_GLM_VISION_FUSED", @import("profile").lookup("TF_GLM_VISION_FUSED"), false); +} + +/// A pass's rows: qkv [N, 3 x 1024], att [N, 1024]; the chunked path's q and k [t, 16, seg, 64], v transposed, scratch. +pub const Buffers = struct { qkv: u64, qh: u64, kh: u64, vt: u64, att: u64, sc: u64, pr: u64, oh: u64, sums: u64 }; + +/// A block's q and k head-normed and rotated: in place in `b.qkv` for `t.full`, else into `b.qh`, `b.kh` and `b.vt`. +pub fn heads(t: *const vision.Tower, ru: *const vision.Run, b: Buffers, qn: u64, kn: u64, pos: u64, n: i64, seg: i64) !void { + const rows = t.full != null; + var a: cuda.Args = .{}; + for ([_]u64{ b.qkv, qn, kn, pos, t.inv_freq.ptr }) |p| a.add(p); + if (!rows) for ([_]u64{ b.qh, b.kh, b.vt }) |p| a.add(p); + a.add(@as(i32, @intCast(n))); + if (!rows) a.add(@as(i32, @intCast(seg))); + a.add(@as(i32, @intCast(HEADS))); + a.add(vision.EPS); + const grid: cuda.Dim3 = .{ .x = @intCast(std.math.divCeil(i64, n * HEADS, 8) catch unreachable) }; + try vision.launch(ru, if (rows) ru.f.qk else ru.f.qkv, grid, 256, &a); +} + +/// Every frame group's heads into `b.att`: `t.full` over the group's rows, else two products around a softmax a head. +pub fn run(t: *vision.Tower, ru: *const vision.Run, b: Buffers, gt: i64, seg: i64) !void { + const scale: f32 = 1.0 / @sqrt(@as(f32, HD)); + var g: i64 = 0; + while (g < gt) : (g += 1) { + const at: u64 = @intCast(g * seg * HEADS * HD * 2); + if (t.full) |*f| { + try f.full(ru.stream, b.qkv + 3 * at, b.att + at, @intCast(seg), HEADS, HD, scale); + continue; + } + var h: i64 = 0; + while (h < HEADS) : (h += 1) try chunked(t, ru, b, @intCast((g * HEADS + h) * seg * HD * 2), b.att + at, seg, h, scale); + } +} + +/// The head in query chunks: the scores product, glm_vis_softmax, the values product, glm_vis_head_out. +fn chunked(t: *vision.Tower, ru: *const vision.Run, b: Buffers, blk: u64, att: u64, seg: i64, h: i64, scale: f32) !void { + var c: i64 = 0; + while (c < seg) : (c += CHUNK) { + const rows = @min(CHUNK, seg - c); + try t.linear(ru, b.qh + blk + @as(u64, @intCast(c * HD * 2)), b.kh + blk, b.sc, rows, seg, HD, true); + var a: cuda.Args = .{}; + a.add(b.sc); + a.add(b.pr); + a.add(b.sums); + a.add(@as(i32, @intCast(seg))); + a.add(scale); + try vision.launch(ru, ru.f.softmax, .{ .x = @intCast(rows) }, 256, &a); + try t.linear(ru, b.pr, b.vt + blk, b.oh, rows, HD, seg, true); + var o: cuda.Args = .{}; + o.add(b.oh); + o.add(b.sums); + o.add(att + @as(u64, @intCast(c * HEADS * HD * 2))); + o.add(@as(i32, @intCast(rows))); + o.add(@as(i32, @intCast(HEADS))); + o.add(@as(i32, @intCast(h))); + try vision.launch(ru, ru.f.head_out, vision.Tower.grid1(rows * HD), 256, &o); + } +} + +const Seen = struct { + var n: usize = 0; + var grid: [8][2]u32 = undefined; + var block: [8]u32 = undefined; + fn launch(_: cuda.abi.Function, gx: c_uint, gy: c_uint, _: c_uint, bx: c_uint, _: c_uint, _: c_uint, _: c_uint, _: cuda.abi.Stream, _: ?[*]?*anyopaque, _: ?[*]?*anyopaque) callconv(.c) cuda.abi.Result { + grid[n] = .{ gx, gy }; + block[n] = bx; + n += 1; + return cuda.abi.success; + } +}; + +test "with vit's attention a block is one q and k launch and one attention launch a frame group, for any segment" { + var d: cuda.Driver = undefined; + d.api.cuLaunchKernel = Seen.launch; + const f: cuda.Function = .{ .d = &d, .handle = null }; + var ru: vision.Run = .{ .stream = .{ .d = &d, .handle = null }, .f = undefined }; + ru.f.qk = f; + var tower: vision.Tower = undefined; + tower.inv_freq.ptr = 0; + tower.full = .{ .mod = undefined, .fns = @splat(f) }; + const b: Buffers = .{ .qkv = 0, .qh = 0, .kh = 0, .vt = 0, .att = 0, .sc = 0, .pr = 0, .oh = 0, .sums = 0 }; + inline for (.{ .{ 4, 16, 1 }, .{ 128, 512, 1 }, .{ 129, 516, 2 }, .{ 6528, 26112, 51 } }) |case| { + Seen.n = 0; + try heads(&tower, &ru, b, 0, 0, 0, 2 * case[0], case[0]); + try run(&tower, &ru, b, 2, case[0]); + try std.testing.expectEqual(@as(usize, 3), Seen.n); + try std.testing.expectEqual([2]u32{ case[1], 1 }, Seen.grid[0]); + for (1..3) |i| try std.testing.expectEqual([2]u32{ case[2], HEADS }, Seen.grid[i]); + try std.testing.expectEqualSlices(u32, &.{ 256, 256, 256 }, Seen.block[0..3]); + } +} diff --git a/zig/src/platform/environment.zig b/zig/src/platform/environment.zig index a155b145995..8fc9de6a829 100644 --- a/zig/src/platform/environment.zig +++ b/zig/src/platform/environment.zig @@ -170,6 +170,7 @@ pub const rules = [_]Rule{ .{ .name = "TF_NEMOTRON_WIDE_ROUNDS", .scope = .nemotron, .kind = .flag, .forms = "0 or 1 (default 0)" }, .{ .name = "TF_GLM_HOST_CACHE", .scope = .glm, .kind = .flag, .forms = "0 or 1" }, .{ .name = "TF_GLM_VISION_HOST", .scope = .glm, .kind = .flag, .forms = "0 or 1" }, + .{ .name = "TF_GLM_VISION_FUSED", .scope = .glm, .kind = .flag, .forms = "0 or 1" }, .{ .name = "TF_GLM_PROF", .scope = .glm, .kind = .flag, .forms = "0 or 1" }, .{ .name = "TF_GLM_LINK_WAIT", .scope = .glm, .kind = .flag, .forms = "0 or 1" }, .{ .name = "TF_GLM_PDL", .scope = .glm, .kind = .flag, .forms = "0 or 1" }, diff --git a/zig/tests/cuda/contract_family_sets.zig b/zig/tests/cuda/contract_family_sets.zig index 387e93eb9ae..23c0f21bba0 100644 --- a/zig/tests/cuda/contract_family_sets.zig +++ b/zig/tests/cuda/contract_family_sets.zig @@ -17,6 +17,7 @@ pub const Sets = struct { moss: *@import("contract_moss_image.zig").Set, nemo_audio: *@import("contract_nemo_audio.zig").Set, qwen3_asr: *@import("contract_qwen3_asr.zig").Set, + glm_vision: *@import("contract_glm_vision.zig").Set, modelopt: *@import("contract_flashnext_modelopt.zig").Set, grouped: *Grouped, flashnext: *@import("contract_flashnext_more.zig").Set, @@ -46,6 +47,8 @@ pub const Sets = struct { errdefer nemo_audio.deinit(); const qwen3_asr = try @import("contract_qwen3_asr.zig").Set.init(gpu, s, a, list); errdefer qwen3_asr.deinit(); + const glm_vision = try @import("contract_glm_vision.zig").Set.init(gpu, s, a, list); + errdefer glm_vision.deinit(); const modelopt = try @import("contract_flashnext_modelopt.zig").Set.init(gpu, s, a, list); errdefer modelopt.deinit(); const grouped = try gpu.gpa.create(Grouped); @@ -88,6 +91,7 @@ pub const Sets = struct { .moss = moss, .nemo_audio = nemo_audio, .qwen3_asr = qwen3_asr, + .glm_vision = glm_vision, .modelopt = modelopt, .grouped = grouped, .flashnext = flashnext, @@ -120,6 +124,7 @@ pub const Sets = struct { sets.modelopt.deinit(); sets.qwen3_asr.deinit(); sets.nemo_audio.deinit(); + sets.glm_vision.deinit(); sets.moss.deinit(); sets.inkling2.deinit(); sets.minimax.deinit(); diff --git a/zig/tests/cuda/contract_glm_vision.zig b/zig/tests/cuda/contract_glm_vision.zig new file mode 100644 index 00000000000..e693ebfc7d3 --- /dev/null +++ b/zig/tests/cuda/contract_glm_vision.zig @@ -0,0 +1,208 @@ +//! GLM's image tower on vit's full attention under the contract: glm_vis_qk's rows, then vision_kernel<64, 8>. +const std = @import("std"); +const cuda = @import("cuda"); +const core = @import("core"); +const glm = @import("glm_cuda"); +const check_ = @import("check.zig"); +const rig_ = @import("contract_rig.zig"); + +const c = core.contract.spec; +const g = core.contract.gates; + +const D = 64; +const H = 16; // heads +const W = H * D; + +const controls = struct { + pub const bytes align(16) = @embedFile("fatbin_contract_controls").*; +}; + +/// Shape: heads (rows), head width (n), a frame group's patches (k): two heads at an image's sizes, 16 at small ones. +pub const Full = @import("contract_vit_full.zig").Full(D, "cuda glm_vision vit vision_kernel<64, 8> (full attention)", &.{ .{ .rows = 2, .n = D, .k = 6528 }, .{ .rows = 2, .n = D, .k = 1024 }, .{ .rows = H, .n = D, .k = 196 }, .{ .rows = H, .n = D, .k = 36 }, .{ .rows = H, .n = D, .k = 4 } }); + +/// A lane's two squares, then the warp's 5 shuffles. +fn qkDepth(_: c.Shape) usize { + return 2 + 5; +} + +/// Shape: patches (rows), heads (n), head width (k). +fn qkSpec(control: bool) c.Spec { + return .{ + .name = if (control) "control: glm_vis_qk rotates a head before its bf16 rounding" else "cuda glm_vision glm_vis_qk (q and k head norm and 2D rotation, in place)", + .accum = .f32, + .depth = qkDepth, + .out = .bf16, + .in_place = true, + .replaces = "glm_vis_qkv at segments of one row", + .nan = .{ .stated = "byte-identical to glm_vis_qkv's rows, including non-finite inputs" }, + .served = &.{ .{ .rows = 6528, .n = H, .k = D }, .{ .rows = 1024, .n = H, .k = D }, .{ .rows = 196, .n = H, .k = D }, .{ .rows = 4, .n = H, .k = D } }, + .sums = .{ .f16 = 0, .bf16 = 0, .why = "a head's sum of squares is checked against the replaced kernel's bytes" }, + }; +} + +/// glm_vis_qk through cuda_vision_attn.heads, on a copy of the rows [rows, 3 x 1024], against glm_vis_qkv. +pub const Qk = struct { + rig: rig_.Rig, + run_: glm.vision.Run, + att: *cuda.vit.Attention, + control: bool = false, + shape: c.Shape = undefined, + qkv: u64 = 0, + norms: u64 = 0, + pos: u64 = 0, + freq: u64 = 0, + out: u64 = 0, + /// glm_vis_qkv's q, k and v at segments of one row: [rows, 1024] each + old: [3]u64 = @splat(0), + base: []u8 = &.{}, + msg: [200]u8 = undefined, + + pub fn deinit(self: *Qk) void { + self.rig.gpu.gpa.free(self.base); + self.rig.deinit(); + } + + const vt = g.hooks(Qk); + + pub fn kernel(self: *Qk) g.Kernel { + return .{ .spec = qkSpec(self.control), .ctx = self, .vt = &vt, .control = if (self.control) .shapes else null }; + } + + pub fn prepare(self: *Qk, sh: c.Shape, fill: g.Fill, seed: u64) !bool { + if (sh.rows == 0 or sh.n != H or sh.k != D) return false; + self.rig.reset(); + self.shape = sh; + const a = self.rig.gpu.gpa; + const x = try a.alloc(u16, self.count()); + defer a.free(x); + const pos = try a.alloc(i32, 2 * sh.rows); + defer a.free(pos); + var norms: [2 * D]u16 = undefined; + var freq: [16]f32 = undefined; + var prng = std.Random.DefaultPrng.init(seed); + const rng = prng.random(); + for (x) |*v| v.* = c.toBf16(rng.float(f32) * 8 - 4); + for (&norms) |*v| v.* = c.toBf16(0.25 + rng.float(f32) * 1.75); + for (pos) |*p| p.* = rng.intRangeLessThan(i32, 0, 275); + for (&freq, 0..) |*v, i| v.* = 1.0 / std.math.pow(f32, 10000.0, @as(f32, @floatFromInt(2 * i)) / 32.0); + if (fill == .nonfinite) for (x, 0..) |*v, i| switch (i % (3 * W + 7)) { + 0 => v.* = c.toBf16(std.math.nan(f32)), + 1 => v.* = c.toBf16(std.math.inf(f32)), + 2 => v.* = c.toBf16(-std.math.inf(f32)), + else => {}, + }; + if (fill == .stress) { // every q and k element 8 under unit weights at the origin: each head norms to ones + for (0..sh.rows) |r| @memset(x[r * 3 * W ..][0 .. 2 * W], c.toBf16(8)); + @memset(&norms, c.toBf16(1)); + @memset(pos, 0); + } + self.qkv = try self.rig.input(std.mem.sliceAsBytes(x)); + self.norms = try self.rig.input(std.mem.sliceAsBytes(&norms)); + self.pos = try self.rig.input(std.mem.sliceAsBytes(pos)); + self.freq = try self.rig.input(std.mem.sliceAsBytes(&freq)); + self.out = try self.rig.output(self.count() * 2); + for (&self.old) |*o| o.* = try self.rig.scratch(sh.rows * W * 2); + a.free(self.base); + self.base = &.{}; + self.base = try a.alloc(u8, self.count() * 2); + return true; + } + + pub fn count(self: *Qk) usize { + return self.shape.rows * 3 * W; + } + + fn heads(self: *Qk, rows: bool, qkv: u64) !void { + var tower: glm.vision.Tower = undefined; + tower.full = if (rows) self.att.* else null; + tower.inv_freq.ptr = self.freq; + const b: glm.vision_attn.Buffers = .{ .qkv = qkv, .qh = self.old[0], .kh = self.old[1], .vt = self.old[2], .att = 0, .sc = 0, .pr = 0, .oh = 0, .sums = 0 }; + try glm.vision_attn.heads(&tower, &self.run_, b, self.norms, self.norms + D * 2, self.pos, @intCast(self.shape.rows), 1); + } + + pub fn run(self: *Qk) !void { + try (cuda.DeviceBuffer{ .d = self.rig.gpu.d, .ptr = self.out, .len = self.count() * 2 }).copyFrom(0, self.qkv, self.count() * 2, self.rig.s.handle); + try self.heads(true, self.out); + try self.rig.s.synchronize(); + } + + /// glm_vis_qkv's bytes as rows of q, k, v: at segments of one row its head-major q and k are row-major. + pub fn replaced(self: *Qk) ![]const u8 { + try self.heads(false, self.qkv); + const row = W * 2; + for (self.old, 0..) |ptr, which| { + const part = try self.rig.bytes(ptr, self.shape.rows * row); + for (0..self.shape.rows) |r| @memcpy(self.base[(r * 3 + which) * row ..][0..row], part[r * row ..][0..row]); + } + return self.base; + } + + pub fn reference(self: *Qk, want: []f64, mag: []f64) !void { + const bytes = try self.replaced(); + for (want, mag, 0..) |*w, *m, i| { + w.* = c.read(.bf16, bytes, i); + m.* = @abs(w.*); + } + } + + /// The stress rows: 64 squares of 8 a head, then 8 / sqrt(their mean) as bf16; v's 8s as they are. + pub fn simulate(self: *Qk, acc: c.Accum, order: g.Order, out: []f64) !void { + const squares: [D]f64 = @splat(64); + const ss = core.contract.rows.sumIn(acc, order, &squares); + const one = c.fromBf16(c.toBf16(@floatCast(8 / @sqrt(ss / D + 1e-5)))); + for (0..self.shape.rows) |r| { + @memset(out[r * 3 * W ..][0 .. 2 * W], one); + for (out[(r * 3 + 2) * W ..][0..W], 0..) |*v, i| v.* = c.read(.bf16, self.base, (r * 3 + 2) * W + i); + } + } + + pub fn check(self: *Qk, _: g.Gate) !?[]const u8 { + const a = self.rig.gpu.gpa; + const got = try a.dupe(u8, try self.rig.outputBytes()); + defer a.free(got); + const want = try self.replaced(); + if (std.mem.indexOfDiff(u8, got, want)) |at| return try std.fmt.bufPrint(&self.msg, "byte {d} of {d} differs from glm_vis_qkv's rows", .{ at, got.len }); + for (0..self.count()) |i| if (c.classOf(c.read(.bf16, got, i)) != .finite) return null; + return "no output is non-finite: the planted values prove nothing"; + } +}; + +/// The tower's q and k rows with their control, and its attention, on the heap: the gates hold pointers to them. +pub const Set = struct { + gpa: std.mem.Allocator, + mod: cuda.Module, + ctl: cuda.Module, + att: cuda.vit.Attention, + qk: [2]Qk = undefined, + full: Full = undefined, + + /// The set, its kernels appended to `list` (the control after the kernel it breaks). + pub fn init(gpu: check_.Gpu, s: cuda.Stream, a: std.mem.Allocator, list: *std.ArrayList(g.Kernel)) !*Set { + const set = try gpu.gpa.create(Set); + errdefer gpu.gpa.destroy(set); + var mod = try cuda.Module.load(gpu.d, cuda.kernels.glm_vision); + errdefer mod.unload(); + var ctl = try cuda.Module.load(gpu.d, &controls.bytes); + errdefer ctl.unload(); + set.* = .{ .gpa = gpu.gpa, .mod = mod, .ctl = ctl, .att = try cuda.vit.Attention.load(gpu.d) }; + const rig: rig_.Rig = .{ .gpu = gpu, .s = s }; + const f = try glm.vision.Funcs.load(mod); + var broken = f; + broken.qk = try ctl.function("tf_ctl_glm_vis_qk_unrounded"); + set.qk[0] = .{ .rig = rig, .run_ = .{ .stream = s, .f = f }, .att = &set.att }; + set.qk[1] = .{ .rig = rig, .run_ = .{ .stream = s, .f = broken }, .att = &set.att, .control = true }; + set.full = .{ .rig = rig, .att = &set.att }; + for (&set.qk) |*x| try list.append(a, x.kernel()); + try list.append(a, set.full.kernel()); + return set; + } + + pub fn deinit(set: *Set) void { + for (&set.qk) |*x| x.deinit(); + set.full.deinit(); + set.att.unload(); + set.ctl.unload(); + set.mod.unload(); + set.gpa.destroy(set); + } +}; diff --git a/zig/tests/cuda/contract_moss_image_attn.zig b/zig/tests/cuda/contract_moss_image_attn.zig index 176c9cf4e02..e8a01067b51 100644 --- a/zig/tests/cuda/contract_moss_image_attn.zig +++ b/zig/tests/cuda/contract_moss_image_attn.zig @@ -1,161 +1,7 @@ //! prefill_attention.cu's vision_kernel<128, 8> under the contract: MOSS-Image's full attention, head by head. -const std = @import("std"); -const cuda = @import("cuda"); -const core = @import("core"); -const rig_ = @import("contract_rig.zig"); -const attn = @import("contract_attn.zig"); - -const c = core.contract.spec; -const g = core.contract.gates; +const full = @import("contract_vit_full.zig"); const D = 128; -/// The P x V chain of a row: every key, a 64-key tile at a time. -fn keyChain(s: c.Shape) usize { - return s.k + 64; -} - -fn scale() f32 { - return 1.0 / @sqrt(@as(f32, D)); -} - /// Shape: heads (rows), head width (n), rows L (k); 24 heads at prompt lengths, two stand for them at joint ones. -pub fn spec() c.Spec { - return .{ - .name = "cuda moss image vit vision_kernel<128, 8> (full attention)", - .accum = .f32, - .depth = keyChain, - .ops = 1, - .out = .bf16, - .tiles = .{ .{}, .{}, .{ .size = 128 } }, - .served = &.{ .{ .rows = 2, .n = D, .k = 4188 }, .{ .rows = 2, .n = D, .k = 4135 }, .{ .rows = 2, .n = D, .k = 4130 }, .{ .rows = 2, .n = D, .k = 4106 }, .{ .rows = 24, .n = D, .k = 63 }, .{ .rows = 24, .n = D, .k = 34 }, .{ .rows = 24, .n = D, .k = 10 } }, - .sums = .{ .why = attn.why }, - }; -} - -pub const Full = struct { - rig: rig_.Rig, - att: *const cuda.vit.Attention, - r: ?attn.Ref = null, - shape: c.Shape = undefined, - /// [L, 3 heads 128]: q heads, then k, then v (tf_moss_qk's packed rows) - qkv: []u16 = &.{}, - dev: u64 = 0, - out: u64 = 0, - - pub fn deinit(self: *Full) void { - self.rig.gpu.gpa.free(self.qkv); - if (self.r) |*r| r.deinit(); - self.rig.deinit(); - } - - pub fn kernel(self: *Full) g.Kernel { - return .{ .spec = spec(), .ctx = self, .vt = &vt }; - } - - const vt = g.hooks(Full); - - fn stride(self: *const Full) usize { - return 3 * self.shape.rows * D; - } - - fn at(self: *const Full, row: usize, which: usize, head: usize) []u16 { - return self.qkv[row * self.stride() + (which * self.shape.rows + head) * D ..][0..D]; - } - - pub fn prepare(self: *Full, shape: c.Shape, fill: g.Fill, seed: u64) !bool { - self.rig.reset(); - if (shape.n != D or shape.rows == 0 or shape.k == 0) return false; - const a = self.rig.gpu.gpa; - self.shape = shape; - const L = shape.k; - var prng = std.Random.DefaultPrng.init(seed); - const rng = prng.random(); - if (self.r) |*r| r.deinit(); - self.r = null; - self.r = try attn.Ref.init(a, D, L); - a.free(self.qkv); - self.qkv = &.{}; - self.qkv = try a.alloc(u16, L * self.stride()); - for (self.qkv) |*e| e.* = attn.normal(rng); - switch (fill) { - .random => {}, - .nonfinite => self.plant(), - .stress => try self.stress(rng), - } - self.dev = try self.rig.input(std.mem.sliceAsBytes(self.qkv)); - self.out = try self.rig.output(L * shape.rows * D * 2); - return true; - } - - /// Head 0: NaN in row 0's query, +inf and -inf in values, both in one column; head 1: NaN in one key. - fn plant(self: *Full) void { - const L = self.shape.k; - const nan = c.toBf16(std.math.nan(f32)); - const inf = c.toBf16(std.math.inf(f32)); - const ninf = c.toBf16(-std.math.inf(f32)); - self.at(0, 0, 0)[3] = nan; - self.at(L - 1, 2, 0)[7] = inf; - self.at(L / 2, 2, 0)[9] = ninf; - if (L >= 3) { - self.at(1, 2, 0)[11] = inf; - self.at(2, 2, 0)[11] = ninf; - } - if (self.shape.rows > 1) self.at(L / 3, 1, 1)[5] = nan; - } - - /// Gate 4: every key one vector (each p is 1); each value column mirrored over the keys. - fn stress(self: *Full, rng: std.Random) !void { - const a = self.rig.gpu.gpa; - const L = self.shape.k; - const key = try a.alloc(u16, D); - defer a.free(key); - for (key) |*e| e.* = attn.normal(rng); - const col = try a.alloc(f32, L); - defer a.free(col); - for (0..self.shape.rows) |h| { - for (0..L) |j| @memcpy(self.at(j, 1, h), key); - for (0..D) |e| { - attn.mirrored(rng, col); - for (col, 0..) |y, j| self.at(j, 2, h)[e] = c.toBf16(y); - } - } - } - - pub fn run(self: *Full) !void { - try self.att.full(self.rig.s, self.dev, self.out, self.shape.k, self.shape.rows, D, scale()); - try self.rig.s.synchronize(); - } - - pub fn count(self: *Full) usize { - return self.shape.k * self.shape.rows * D; - } - - /// Output head i (row i / heads, head i % heads) over every row's key and value. - pub fn load(self: *Full, i: usize, hd: *attn.Head) !void { - const row = i / self.shape.rows; - const head = i % self.shape.rows; - for (hd.q, self.at(row, 0, head)) |*y, x| y.* = c.fromBf16(x); - for (0..self.shape.k) |j| for (0..D) |e| { - hd.k[j * D + e] = c.fromBf16(self.at(j, 1, head)[e]); - hd.v[j * D + e] = c.fromBf16(self.at(j, 2, head)[e]); - }; - hd.n = self.shape.k; - } - - fn heads(self: *Full) usize { - return self.shape.k * self.shape.rows; - } - - pub fn check(self: *Full, gate: g.Gate) !?[]const u8 { - return self.r.?.check(self, self.heads(), scale(), try self.rig.outputBytes(), gate); - } - - pub fn reference(self: *Full, want: []f64, mag: []f64) !void { - return self.r.?.reference(self, self.heads(), scale(), want, mag); - } - - pub fn simulate(self: *Full, acc: c.Accum, order: g.Order, out: []f64) !void { - return self.r.?.simulate(self, self.heads(), scale(), acc, order, out); - } -}; +pub const Full = full.Full(D, "cuda moss image vit vision_kernel<128, 8> (full attention)", &.{ .{ .rows = 2, .n = D, .k = 4188 }, .{ .rows = 2, .n = D, .k = 4135 }, .{ .rows = 2, .n = D, .k = 4130 }, .{ .rows = 2, .n = D, .k = 4106 }, .{ .rows = 24, .n = D, .k = 63 }, .{ .rows = 24, .n = D, .k = 34 }, .{ .rows = 24, .n = D, .k = 10 } }); diff --git a/zig/tests/cuda/contract_vit_full.zig b/zig/tests/cuda/contract_vit_full.zig new file mode 100644 index 00000000000..1d69c09c582 --- /dev/null +++ b/zig/tests/cuda/contract_vit_full.zig @@ -0,0 +1,163 @@ +//! prefill_attention.cu's vision_kernel under the contract: a tower's full attention, head by head. +const std = @import("std"); +const cuda = @import("cuda"); +const core = @import("core"); +const rig_ = @import("contract_rig.zig"); +const attn = @import("contract_attn.zig"); + +const c = core.contract.spec; +const g = core.contract.gates; + +/// The P x V chain of a row: every key, a 64-key tile at a time. +fn keyChain(s: c.Shape) usize { + return s.k + 64; +} + +/// The test type at head dim `D`, registered as `name` at the shapes `served`: heads (rows), D (n), rows L (k). +pub fn Full(comptime D: usize, comptime name: []const u8, comptime served: []const c.Shape) type { + return struct { + const Self = @This(); + + fn scale() f32 { + return 1.0 / @sqrt(@as(f32, D)); + } + + pub fn spec() c.Spec { + return .{ + .name = name, + .accum = .f32, + .depth = keyChain, + .ops = 1, + .out = .bf16, + .tiles = .{ .{}, .{}, .{ .size = 128 } }, + .served = served, + .sums = .{ .why = attn.why }, + }; + } + + rig: rig_.Rig, + att: *const cuda.vit.Attention, + r: ?attn.Ref = null, + shape: c.Shape = undefined, + /// [L, 3 heads D]: q heads, then k, then v + qkv: []u16 = &.{}, + dev: u64 = 0, + out: u64 = 0, + + pub fn deinit(self: *Self) void { + self.rig.gpu.gpa.free(self.qkv); + if (self.r) |*r| r.deinit(); + self.rig.deinit(); + } + + pub fn kernel(self: *Self) g.Kernel { + return .{ .spec = spec(), .ctx = self, .vt = &vt }; + } + + const vt = g.hooks(Self); + + fn stride(self: *const Self) usize { + return 3 * self.shape.rows * D; + } + + fn at(self: *const Self, row: usize, which: usize, head: usize) []u16 { + return self.qkv[row * self.stride() + (which * self.shape.rows + head) * D ..][0..D]; + } + + pub fn prepare(self: *Self, shape: c.Shape, fill: g.Fill, seed: u64) !bool { + self.rig.reset(); + if (shape.n != D or shape.rows == 0 or shape.k == 0) return false; + const a = self.rig.gpu.gpa; + self.shape = shape; + const L = shape.k; + var prng = std.Random.DefaultPrng.init(seed); + const rng = prng.random(); + if (self.r) |*r| r.deinit(); + self.r = null; + self.r = try attn.Ref.init(a, D, L); + a.free(self.qkv); + self.qkv = &.{}; + self.qkv = try a.alloc(u16, L * self.stride()); + for (self.qkv) |*e| e.* = attn.normal(rng); + switch (fill) { + .random => {}, + .nonfinite => self.plant(), + .stress => try self.stress(rng), + } + self.dev = try self.rig.input(std.mem.sliceAsBytes(self.qkv)); + self.out = try self.rig.output(L * shape.rows * D * 2); + return true; + } + + /// Head 0: NaN in row 0's query, +inf and -inf in values, both in one column; head 1: NaN in one key. + fn plant(self: *Self) void { + const L = self.shape.k; + const nan = c.toBf16(std.math.nan(f32)); + const inf = c.toBf16(std.math.inf(f32)); + const ninf = c.toBf16(-std.math.inf(f32)); + self.at(0, 0, 0)[3] = nan; + self.at(L - 1, 2, 0)[7] = inf; + self.at(L / 2, 2, 0)[9] = ninf; + if (L >= 3) { + self.at(1, 2, 0)[11] = inf; + self.at(2, 2, 0)[11] = ninf; + } + if (self.shape.rows > 1) self.at(L / 3, 1, 1)[5] = nan; + } + + /// Gate 4: every key one vector (each p is 1); each value column mirrored over the keys. + fn stress(self: *Self, rng: std.Random) !void { + const a = self.rig.gpu.gpa; + const L = self.shape.k; + const key = try a.alloc(u16, D); + defer a.free(key); + for (key) |*e| e.* = attn.normal(rng); + const col = try a.alloc(f32, L); + defer a.free(col); + for (0..self.shape.rows) |h| { + for (0..L) |j| @memcpy(self.at(j, 1, h), key); + for (0..D) |e| { + attn.mirrored(rng, col); + for (col, 0..) |y, j| self.at(j, 2, h)[e] = c.toBf16(y); + } + } + } + + pub fn run(self: *Self) !void { + try self.att.full(self.rig.s, self.dev, self.out, self.shape.k, self.shape.rows, D, scale()); + try self.rig.s.synchronize(); + } + + pub fn count(self: *Self) usize { + return self.shape.k * self.shape.rows * D; + } + + /// Output head i (row i / heads, head i % heads) over every row's key and value. + pub fn load(self: *Self, i: usize, hd: *attn.Head) !void { + const row = i / self.shape.rows; + const head = i % self.shape.rows; + for (hd.q, self.at(row, 0, head)) |*y, x| y.* = c.fromBf16(x); + for (0..self.shape.k) |j| for (0..D) |e| { + hd.k[j * D + e] = c.fromBf16(self.at(j, 1, head)[e]); + hd.v[j * D + e] = c.fromBf16(self.at(j, 2, head)[e]); + }; + hd.n = self.shape.k; + } + + fn heads(self: *Self) usize { + return self.shape.k * self.shape.rows; + } + + pub fn check(self: *Self, gate: g.Gate) !?[]const u8 { + return self.r.?.check(self, self.heads(), scale(), try self.rig.outputBytes(), gate); + } + + pub fn reference(self: *Self, want: []f64, mag: []f64) !void { + return self.r.?.reference(self, self.heads(), scale(), want, mag); + } + + pub fn simulate(self: *Self, acc: c.Accum, order: g.Order, out: []f64) !void { + return self.r.?.simulate(self, self.heads(), scale(), acc, order, out); + } + }; +} diff --git a/zig/tests/fixtures/gradient-serving.tsv b/zig/tests/fixtures/gradient-serving.tsv index 19f4ac14410..ed05b408bf1 100644 --- a/zig/tests/fixtures/gradient-serving.tsv +++ b/zig/tests/fixtures/gradient-serving.tsv @@ -46,7 +46,7 @@ zig/kernels/cuda/nemotron_route.cu 65da41432442f9fd99f73abefe87f34cf3c46b4971afe zig/kernels/cuda/norms.cu 89d3c6cea39fe3e1bf8d5a2fe60465f7ae272548f14711abb59ddac709d2d1db raw main d4541b00e0 (rms_scale shared; same SASS) zig/kernels/cuda/nvfp4_experts.cu dc78d37c1eb1d9a9fff6c1ba9c5f0a9b0eb485a47a56e7b0b2fdbb8bbf1b223b raw #2266 (decode cp.async rings, GB10 SASS unchanged); #4493 (opt-in paired prompt experts, 128-row items) zig/kernels/cuda/nvfp4q.cuh 5fe4fa58568f2293bb72ccfa58b362ba2783b21a781e56946a5a2c328303d111 raw -zig/kernels/cuda/prefill_attention.cu 4227f0a9b7a89ac296388a7dcd9e49cd0dd487ed09ee46cc1d4eda94ab8e3741 raw main 82f3dde92 (pattn_kernel<64, 8, 4, 8> over paged caches), 94a9a48d6 (helpers to prefill_attention.cuh, SASS unchanged), 191061381 (#2609: two new pattn_kernel instances at two query heads a block, head dims 128 and 64; existing instances unchanged), #2239 (a vision_kernel<64, 8> instance for Qwen3-ASR's audio tower; existing instances unchanged) +zig/kernels/cuda/prefill_attention.cu 4227f0a9b7a89ac296388a7dcd9e49cd0dd487ed09ee46cc1d4eda94ab8e3741 raw main 82f3dde92 (pattn_kernel<64, 8, 4, 8> over paged caches), 94a9a48d6 (helpers to prefill_attention.cuh, SASS unchanged), 191061381 (#2609: two new pattn_kernel instances at two query heads a block, head dims 128 and 64; existing instances unchanged), #2239 (a vision_kernel<64, 8> instance for Qwen3-ASR's audio tower; existing instances unchanged); #3790 (one new vision_kernel instance at head dim 64; existing instances unchanged) zig/kernels/cuda/prefill_attention_rows.cuh 21975248a7ec9efd199a28324bba837e7b78f066a63b426ab26587cba38fda5e raw main 94a9a48d6 (helpers shared with the contract controls, SASS unchanged) zig/kernels/cuda/probe.cu 94a3118894b3066e0f0f6fc1cfc3c03828d291077cb26c437b62fcc9b177a210 raw glm-pdl-order's slow writer, planted early reader and glm_pdl::enter() reader zig/kernels/cuda/prompt16.cu 2da3c4ea23de0fa9b2536db0fa66f07bb2d5b45db36c2f9cb321e039ebeac7c2 raw #3252: the lean gate/up SwiGLU pair launch for a dense MLP prompt @@ -113,7 +113,7 @@ zig/src/cuda/stream.zig 02c1879e72a35927466ab462d6b2a461691d1f5196da770decd1125d zig/src/cuda/tp_group.zig 1a2acbdf2de6b827218deb45df5b5845beecde4eb718a4e4b3966582db51d7a7 raw commits b8d45ded3, 80afaf959; series patches 14-runtime-foundation.patch; HELD: must be re-qualified by the LW device gates on the 1.1.1 candidate; main c8ad9872da (#2205: RoCE small gathers at any world up to roce.max_world when every rank asks; TF_ROCE's default unchanged, two ranks on, three or more on NCCL), 61a2651577 (#2789: a call failing after the group's abort ends as Aborted, not fatally); #2918 (communicator abort through its owner) zig/src/cuda/tp_watch.zig 19ed1d12bc56f804b5d207d04226e9f6131a517aaf7aec4c4b2d0bd5f468ace3 raw main 13d7450fd (#2354), 7ead07c92 (bounded peer warm-up, #2512) zig/src/cuda/triton.zig 256323865c6a4676b8b75aae9e32d2d9732cf2623efedb9462cf6f95302c3e83 raw -zig/src/cuda/vit.zig 0a9200b161e331cf3f5937ff5dcc5c65bcb15e3de8127c277f6a31595d2e5296 raw #2239 (convCols, convFlatten and the head-64 full attention for Qwen3-ASR's audio tower; existing paths unchanged) +zig/src/cuda/vit.zig 0a9200b161e331cf3f5937ff5dcc5c65bcb15e3de8127c277f6a31595d2e5296 raw #2239 (convCols, convFlatten and the head-64 full attention for Qwen3-ASR's audio tower; existing paths unchanged); #3790 (GLM-5.3-Flash's image tower uses the shared head-64 full attention) zig/src/families/flashnext/cuda_attn.zig 99dfe79f919a8599490f1cdba0bec20d6e73ccbeafe26d5848419a465fdfa0d0 raw zig/src/families/flashnext/cuda_batch.zig b368dc5784c9d7e82d9e29ce26f37b3471d31a21e12a144127d365bdcc4ead96 raw main 42ff6c510f (disk states keyed by the resolved prompt passes; serving unchanged); #XXXX: the scratch test's ceiling restated at the 3,072-row default, #3413 (TF_FLASHNEXT_READOUT_FUSED's prompt read-out; unchanged when unset); TF_FLASHNEXT_GDN_CHAIN_TPR's opt-in row dispatch; unset leaves the key unchanged zig/src/families/flashnext/cuda_batch_state.zig 493ee0dc5bc832b9344d16de92ab33f5de15574b4d9a81f283558c4d729c6db6 raw y and moe_f32 take one spare row for a --tp 2 prompt pass's padded rank block; replies unchanged; #XXXX: the default prompt chunk is 3,072 rows; the shared pass takes the pooled n-gram gather first (TF_FLASHNEXT_GATHER_EARLY); replies unchanged From 907d70f6286c63d10d6cfc774d2d37a5e7cd94fc Mon Sep 17 00:00:00 2001 From: ashhart <71890694+ashhart@users.noreply.github.com> Date: Fri, 20 Nov 2026 07:55:54 +0000 Subject: [PATCH 2/8] glm vision: wait before the new dependent image-tower launch reads Follow main 7948cc42d3f74b3b5e6d4ef8776c3777172c20d0, 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. --- zig/kernels/cuda/glm_vision.cu | 1 + 1 file changed, 1 insertion(+) diff --git a/zig/kernels/cuda/glm_vision.cu b/zig/kernels/cuda/glm_vision.cu index ff69c83244c..7ab52c84cc1 100644 --- a/zig/kernels/cuda/glm_vision.cu +++ b/zig/kernels/cuda/glm_vision.cu @@ -114,6 +114,7 @@ extern "C" __global__ void glm_vis_qkv(const __nv_bfloat16* __restrict__ qkv, co extern "C" __global__ void glm_vis_qk(__nv_bfloat16* qkv, const __nv_bfloat16* __restrict__ qn, const __nv_bfloat16* __restrict__ kn, const int* __restrict__ pos, const float* __restrict__ inv_freq, int N, int H, float eps) { + glm_pdl::enter(); glm_vis_rows::qk(qkv, qn, kn, pos, inv_freq, N, H, eps); } From 9f8869e8d9b57295d54c9c1a9466acb7cbc13539 Mon Sep 17 00:00:00 2001 From: ashhart <71890694+ashhart@users.noreply.github.com> Date: Sat, 21 Nov 2026 02:01:00 +0000 Subject: [PATCH 3/8] glm vision: the fused-attention launch test records through cuLaunchKernelEx Follows main's 7948cc42d (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. --- zig/src/families/glm/cuda_vision_attn.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/zig/src/families/glm/cuda_vision_attn.zig b/zig/src/families/glm/cuda_vision_attn.zig index eb1885b80a2..00869fe9818 100644 --- a/zig/src/families/glm/cuda_vision_attn.zig +++ b/zig/src/families/glm/cuda_vision_attn.zig @@ -85,6 +85,7 @@ const Seen = struct { test "with vit's attention a block is one q and k launch and one attention launch a frame group, for any segment" { var d: cuda.Driver = undefined; d.api.cuLaunchKernel = Seen.launch; + d.api.cuLaunchKernelEx = @import("cuda_pdl.zig").forwardEx(Seen.launch); const f: cuda.Function = .{ .d = &d, .handle = null }; var ru: vision.Run = .{ .stream = .{ .d = &d, .handle = null }, .f = undefined }; ru.f.qk = f; From b1b4a7f2fa4a1eb201afef9e7ea0250d4c680adf Mon Sep 17 00:00:00 2001 From: ashhart <71890694+ashhart@users.noreply.github.com> Date: Sat, 21 Nov 2026 12:44:00 +0000 Subject: [PATCH 4/8] glm vision: register the fused-attention launch tests Reference the new vision_attn module from the GLM CUDA test block so the default GLM host test root discovers its launch-geometry coverage. --- zig/src/families/glm/cuda.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/zig/src/families/glm/cuda.zig b/zig/src/families/glm/cuda.zig index 01f1a145d45..8129f4c9407 100644 --- a/zig/src/families/glm/cuda.zig +++ b/zig/src/families/glm/cuda.zig @@ -82,6 +82,7 @@ test { _ = experts; _ = exl3; _ = vision; + _ = vision_attn; _ = @import("vision_names.zig"); _ = mm; _ = image_core; From edf2fca6b937663a173a460bb377fd7df76816d7 Mon Sep 17 00:00:00 2001 From: ashhart <71890694+ashhart@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:04:24 +0000 Subject: [PATCH 5/8] glm vision: restore the contract image resolution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- zig/tests/cuda/contract_limits.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zig/tests/cuda/contract_limits.zig b/zig/tests/cuda/contract_limits.zig index 98e4ba9cce5..0ed91467353 100644 --- a/zig/tests/cuda/contract_limits.zig +++ b/zig/tests/cuda/contract_limits.zig @@ -31,7 +31,7 @@ pub fn image(name: []const u8) error{UnknownContractImage}![]const u8 { if (std.mem.eql(u8, name, "flashnext_hcn")) return kk.flashnext_hcn; inline for (.{ "qwen4_projection", "qwen4_hc", "qwen4_gdn", "qwen4_ple", "gemma4_ple" }) |n| if (std.mem.eql(u8, name, n)) return @field(kk, n); - inline for (.{ "tree_round", "act_rows", "gdn_prep", "qk_rows", "norms", "moe", "experts", "qwen36_mtp", "nemotron_attention", "nemotron_route", "nemotron_latent", "qmm_group", "qmm_prefill", "lane_gemv", "prompt16", "qmmf", "ck_experts", "nvfp4_experts", "nvfp4_experts_tile", "nvfp4_experts32", "rank_sum", "prefill_attention", "vit", "embed_rows", "route_rows", "flashnext_gdn", "flashnext_batch", "flashnext_hc", "flashnext_attn", "flashnext_mtp", "qwen_vision", "exl3_linear", "exl3_experts", "exl3_candidate", "experts3", "experts3_prefill", "drama3", "drama3_fp8", "drama3_codec", "glm_mm", "glm_dflash", "glm_glue", "glm_ops", "glm_index", "nemotron_mamba", "sample", "qwen35", "qwen35_bf16_rows", "qwen35_keep", "qwen35_kv8", "w4a8_prefill", "qwen35_draft", "ck_lane", "gdn_train", "train_q4", "train_attn", "flashnext_train", "train", "attn_train", "qwen27_train", "tree_attention", "block_attention", "window_attention", "window_pages", "moe_glue", "dense_rows", "qmm", "flashnext_fact", "flashnext_hcf", "flashnext_fexp", "experts_rows", "nemotron_ops", "minimax_m3", "minimax_m3_attn", "experts_bf16", "nemo_audio", "moss_image", "idol", "idol_decoder", "lfm2_moe", "lfm2", "dots_mocr", "muse_glue", "muse_attention", "muse_linear", "muse_experts2", "muse_dflash", "muse_dflash2", "ricursive", "ricursive_prep" }) |n| if (std.mem.eql(u8, name, n)) return @field(kk, n); + inline for (.{ "tree_round", "act_rows", "gdn_prep", "qk_rows", "norms", "moe", "experts", "qwen36_mtp", "nemotron_attention", "nemotron_route", "nemotron_latent", "qmm_group", "qmm_prefill", "lane_gemv", "prompt16", "qmmf", "ck_experts", "nvfp4_experts", "nvfp4_experts_tile", "nvfp4_experts32", "rank_sum", "prefill_attention", "vit", "embed_rows", "route_rows", "flashnext_gdn", "flashnext_batch", "flashnext_hc", "flashnext_attn", "flashnext_mtp", "qwen_vision", "exl3_linear", "exl3_experts", "exl3_candidate", "experts3", "experts3_prefill", "drama3", "drama3_fp8", "drama3_codec", "glm_mm", "glm_dflash", "glm_glue", "glm_ops", "glm_index", "nemotron_mamba", "sample", "qwen35", "qwen35_bf16_rows", "qwen35_keep", "qwen35_kv8", "w4a8_prefill", "qwen35_draft", "ck_lane", "gdn_train", "train_q4", "train_attn", "flashnext_train", "train", "attn_train", "qwen27_train", "tree_attention", "block_attention", "window_attention", "window_pages", "moe_glue", "dense_rows", "qmm", "flashnext_fact", "flashnext_hcf", "flashnext_fexp", "experts_rows", "nemotron_ops", "minimax_m3", "minimax_m3_attn", "experts_bf16", "nemo_audio", "moss_image", "glm_vision", "idol", "idol_decoder", "lfm2_moe", "lfm2", "dots_mocr", "muse_glue", "muse_attention", "muse_linear", "muse_experts2", "muse_dflash", "muse_dflash2", "ricursive", "ricursive_prep" }) |n| if (std.mem.eql(u8, name, n)) return @field(kk, n); inline for (.{ "inkling2_attn", "inkling2_pattn", "inkling2_ops", "inkling2_rows", "inkling2_experts", "inkling2_modelopt", "inkling2_loop_math", "inkling2_vision" }) |n| if (std.mem.eql(u8, name, n)) return @field(kk, n); inline for (.{ "moss_image_decoder", "moss_image_encoder" }) |n| if (std.mem.eql(u8, name, n)) return @field(kk, n); if (std.mem.eql(u8, name, "contract_controls")) return if (options.controls) &controls.bytes else &.{}; From 87b0672623160f44aa738472010749c61c333caa Mon Sep 17 00:00:00 2001 From: ashhart <71890694+ashhart@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:23:13 +0000 Subject: [PATCH 6/8] glm vision: retain RADIO and re-pin shared attention --- zig/kernels/cuda/prefill_attention.cu | 5 ++++- zig/tests/fixtures/gradient-serving.tsv | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/zig/kernels/cuda/prefill_attention.cu b/zig/kernels/cuda/prefill_attention.cu index 502f1bf400a..23afe7f9cbb 100644 --- a/zig/kernels/cuda/prefill_attention.cu +++ b/zig/kernels/cuda/prefill_attention.cu @@ -332,7 +332,10 @@ template __global__ void tf_prefill_attention::tree_kernel<64, 8, 4, 8>(const __ // Head dim 72, eight warps of one head, eight staging slots (SigLIP2's tower, 72 dims padded to 80 inside). template __global__ void tf_prefill_attention::full_kernel<72, 8, 8>(const __nv_bfloat16* __restrict__, __nv_bfloat16* __restrict__, int, int, float); -// Head dim 64, eight warps (Qwen3-ASR's audio tower and GLM-5.3-Flash's image tower over their respective windows or frame groups). +// Head dim 80, eight warps, two blocks an SM (RADIO's tower, 16 heads of 80): full_kernel<80>'s bits, 1.35x faster. +template __global__ void tf_prefill_attention::vision_kernel<80, 8>(const __nv_bfloat16* __restrict__, __nv_bfloat16* __restrict__, int, int, + float); +// Head dim 64, eight warps (Qwen3-ASR audio and GLM-5.3-Flash image towers; existing instances unchanged). template __global__ void tf_prefill_attention::vision_kernel<64, 8>(const __nv_bfloat16* __restrict__, __nv_bfloat16* __restrict__, int, int, float); // Head dim 128, eight warps (MOSS-Image's denoiser, 24 heads of 128 over its image and prompt rows). diff --git a/zig/tests/fixtures/gradient-serving.tsv b/zig/tests/fixtures/gradient-serving.tsv index ed05b408bf1..c41b959ba2f 100644 --- a/zig/tests/fixtures/gradient-serving.tsv +++ b/zig/tests/fixtures/gradient-serving.tsv @@ -46,7 +46,7 @@ zig/kernels/cuda/nemotron_route.cu 65da41432442f9fd99f73abefe87f34cf3c46b4971afe zig/kernels/cuda/norms.cu 89d3c6cea39fe3e1bf8d5a2fe60465f7ae272548f14711abb59ddac709d2d1db raw main d4541b00e0 (rms_scale shared; same SASS) zig/kernels/cuda/nvfp4_experts.cu dc78d37c1eb1d9a9fff6c1ba9c5f0a9b0eb485a47a56e7b0b2fdbb8bbf1b223b raw #2266 (decode cp.async rings, GB10 SASS unchanged); #4493 (opt-in paired prompt experts, 128-row items) zig/kernels/cuda/nvfp4q.cuh 5fe4fa58568f2293bb72ccfa58b362ba2783b21a781e56946a5a2c328303d111 raw -zig/kernels/cuda/prefill_attention.cu 4227f0a9b7a89ac296388a7dcd9e49cd0dd487ed09ee46cc1d4eda94ab8e3741 raw main 82f3dde92 (pattn_kernel<64, 8, 4, 8> over paged caches), 94a9a48d6 (helpers to prefill_attention.cuh, SASS unchanged), 191061381 (#2609: two new pattn_kernel instances at two query heads a block, head dims 128 and 64; existing instances unchanged), #2239 (a vision_kernel<64, 8> instance for Qwen3-ASR's audio tower; existing instances unchanged); #3790 (one new vision_kernel instance at head dim 64; existing instances unchanged) +zig/kernels/cuda/prefill_attention.cu e4cb5bd5e4e9bf8157e5612b45f3dcf78ea31f4ab0822573da495c7aa63728d5.raw main 82f3dde92 (pattn_kernel<64, 8, 4, 8> over paged caches), 94a9a48d6 (helpers to prefill_attention.cuh, SASS unchanged), 191061381 (#2609: two new pattn_kernel instances at two query heads a block, head dims 128 and 64; existing instances unchanged), #2239 (a vision_kernel<64, 8> instance for Qwen3-ASR's audio tower; existing instances unchanged); #3790 (GLM-5.3-Flash's image tower reuses the head-64 vision_kernel instance; existing instances unchanged) zig/kernels/cuda/prefill_attention_rows.cuh 21975248a7ec9efd199a28324bba837e7b78f066a63b426ab26587cba38fda5e raw main 94a9a48d6 (helpers shared with the contract controls, SASS unchanged) zig/kernels/cuda/probe.cu 94a3118894b3066e0f0f6fc1cfc3c03828d291077cb26c437b62fcc9b177a210 raw glm-pdl-order's slow writer, planted early reader and glm_pdl::enter() reader zig/kernels/cuda/prompt16.cu 2da3c4ea23de0fa9b2536db0fa66f07bb2d5b45db36c2f9cb321e039ebeac7c2 raw #3252: the lean gate/up SwiGLU pair launch for a dense MLP prompt @@ -113,7 +113,7 @@ zig/src/cuda/stream.zig 02c1879e72a35927466ab462d6b2a461691d1f5196da770decd1125d zig/src/cuda/tp_group.zig 1a2acbdf2de6b827218deb45df5b5845beecde4eb718a4e4b3966582db51d7a7 raw commits b8d45ded3, 80afaf959; series patches 14-runtime-foundation.patch; HELD: must be re-qualified by the LW device gates on the 1.1.1 candidate; main c8ad9872da (#2205: RoCE small gathers at any world up to roce.max_world when every rank asks; TF_ROCE's default unchanged, two ranks on, three or more on NCCL), 61a2651577 (#2789: a call failing after the group's abort ends as Aborted, not fatally); #2918 (communicator abort through its owner) zig/src/cuda/tp_watch.zig 19ed1d12bc56f804b5d207d04226e9f6131a517aaf7aec4c4b2d0bd5f468ace3 raw main 13d7450fd (#2354), 7ead07c92 (bounded peer warm-up, #2512) zig/src/cuda/triton.zig 256323865c6a4676b8b75aae9e32d2d9732cf2623efedb9462cf6f95302c3e83 raw -zig/src/cuda/vit.zig 0a9200b161e331cf3f5937ff5dcc5c65bcb15e3de8127c277f6a31595d2e5296 raw #2239 (convCols, convFlatten and the head-64 full attention for Qwen3-ASR's audio tower; existing paths unchanged); #3790 (GLM-5.3-Flash's image tower uses the shared head-64 full attention) +zig/src/cuda/vit.zig 3a22b6aaf70bcf83a1d3c7624c8c554e262e69d12be07b6e6b389702f77b5877 raw #2239 (convCols, convFlatten and the head-64 full attention for Qwen3-ASR's audio tower; existing paths unchanged); #3790 (GLM-5.3-Flash's image tower uses the shared head-64 full attention) zig/src/families/flashnext/cuda_attn.zig 99dfe79f919a8599490f1cdba0bec20d6e73ccbeafe26d5848419a465fdfa0d0 raw zig/src/families/flashnext/cuda_batch.zig b368dc5784c9d7e82d9e29ce26f37b3471d31a21e12a144127d365bdcc4ead96 raw main 42ff6c510f (disk states keyed by the resolved prompt passes; serving unchanged); #XXXX: the scratch test's ceiling restated at the 3,072-row default, #3413 (TF_FLASHNEXT_READOUT_FUSED's prompt read-out; unchanged when unset); TF_FLASHNEXT_GDN_CHAIN_TPR's opt-in row dispatch; unset leaves the key unchanged zig/src/families/flashnext/cuda_batch_state.zig 493ee0dc5bc832b9344d16de92ab33f5de15574b4d9a81f283558c4d729c6db6 raw y and moe_f32 take one spare row for a --tp 2 prompt pass's padded rank block; replies unchanged; #XXXX: the default prompt chunk is 3,072 rows; the shared pass takes the pooled n-gram gather first (TF_FLASHNEXT_GATHER_EARLY); replies unchanged From 5278286be0419594e7a1876d96517d05a5c2cf79 Mon Sep 17 00:00:00 2001 From: ashhart <71890694+ashhart@users.noreply.github.com> Date: Mon, 23 Nov 2026 10:32:21 +0000 Subject: [PATCH 7/8] glm vision: finish fused attention cleanup and pin coverage --- zig/dense_serving_test.zig | 4 ++-- zig/src/core/contract/glm_cuda_records.zig | 1 + zig/src/families/glm/cuda_vision.zig | 4 ++-- zig/tests/cuda/contract_glm_vision.zig | 1 + zig/tests/fixtures/gradient-serving.tsv | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/zig/dense_serving_test.zig b/zig/dense_serving_test.zig index 6bfdfd2b9cf..980556f25f3 100644 --- a/zig/dense_serving_test.zig +++ b/zig/dense_serving_test.zig @@ -11,8 +11,8 @@ test "dense serving: owned CUDA images retain their reviewed lane and decode byt try std.testing.expectEqualStrings("5f325dc6d8134624b30b5e99c5764f75beb3c344b5f949d38bfaa41bc8dfe5dc", &hash(@embedFile("kernels/cuda/experts_prefill.cu"))); try std.testing.expectEqualStrings("e5ef9dcce75c478e59e476d2fa8747baee2317bd283b0756f125ea050dad9228", &hash(@embedFile("kernels/cuda/gdn.cu"))); try std.testing.expectEqualStrings("dba5aae94115571ed48933d80f646fff31b2a7da226569867c74a1dc061d2ca2", &hash(@embedFile("kernels/cuda/lane_gemv.cu"))); - // #2239 adds vision_kernel<64, 8> for Qwen3-ASR's tower; every function main had keeps its SASS (sm_80 to sm_121) - try std.testing.expectEqualStrings("4227f0a9b7a89ac296388a7dcd9e49cd0dd487ed09ee46cc1d4eda94ab8e3741", &hash(@embedFile("kernels/cuda/prefill_attention.cu"))); + // #2239 adds head-64 attention for Qwen3-ASR; #3790 reuses it for GLM; existing instances keep their SASS + try std.testing.expectEqualStrings("e4cb5bd5e4e9bf8157e5612b45f3dcf78ea31f4ab0822573da495c7aa63728d5", &hash(@embedFile("kernels/cuda/prefill_attention.cu"))); const group = @embedFile("kernels/cuda/qmm_group.cu"); try std.testing.expectEqualStrings("ceff4ee13e97b5aa93cbe7a1edc9a524c78aaa145dd1e5c82dcb05a3011aae23", &hash(group[0..16095])); try std.testing.expectEqualStrings("8780fd710be3ce2f04e53fa1e69eb062809d3bec6391d9bd49983d0588e374d0", &hash(group)); diff --git a/zig/src/core/contract/glm_cuda_records.zig b/zig/src/core/contract/glm_cuda_records.zig index 5bc70c05ad7..4c725cd07b0 100644 --- a/zig/src/core/contract/glm_cuda_records.zig +++ b/zig/src/core/contract/glm_cuda_records.zig @@ -72,6 +72,7 @@ pub const cuda_132 = [_]registry.Override{ .{ .name = "glm_mm16_16", .usage = .{ .{ .regs = 95, .static = 0, .bound = 128 }, .{ .regs = 95, .static = 0, .bound = 128 }, .{ .regs = 95, .static = 0, .bound = 128 }, .{ .regs = 56, .static = 0, .bound = 128 }, .{ .regs = 56, .static = 0, .bound = 128 } } }, .{ .name = "glm_mm8_16", .usage = .{ .{ .regs = 93, .static = 0, .bound = 128 }, .{ .regs = 94, .static = 0, .bound = 128 }, .{ .regs = 94, .static = 0, .bound = 128 }, .{ .regs = 58, .static = 0, .bound = 128 }, .{ .regs = 58, .static = 0, .bound = 128 } } }, .{ .name = "glm_mm8_32", .usage = .{ .{ .regs = 128, .static = 0, .bound = 128 }, .{ .regs = 126, .static = 0, .bound = 128 }, .{ .regs = 126, .static = 0, .bound = 128 }, .{ .regs = 74, .static = 0, .bound = 128 }, .{ .regs = 74, .static = 0, .bound = 128 } } }, + .{ .name = "glm_vision vit vision_kernel<64, 8>", .usage = .{ .{ .regs = 132, .static = 0, .bound = 256 }, .{ .regs = 132, .static = 0, .bound = 256 }, .{ .regs = 132, .static = 0, .bound = 256 }, .{ .regs = 128, .static = 0, .bound = 256 }, .{ .regs = 128, .static = 0, .bound = 256 } } }, .{ .name = "df_block_qkv", .usage = .{ .{ .regs = 32, .static = 8, .bound = 0 }, .{ .regs = 30, .static = 8, .bound = 0 }, .{ .regs = 30, .static = 8, .bound = 0 }, .{ .regs = 32, .static = 8, .bound = 0 }, .{ .regs = 32, .static = 8, .bound = 0 } } }, .{ .name = "df_ctx_kv", .usage = .{ .{ .regs = 30, .static = 8, .bound = 0 }, .{ .regs = 30, .static = 8, .bound = 0 }, .{ .regs = 30, .static = 8, .bound = 0 }, .{ .regs = 28, .static = 8, .bound = 0 }, .{ .regs = 28, .static = 8, .bound = 0 } } }, .{ .name = "df_top16_merge", .usage = .{ .{ .regs = 23, .static = 8416, .bound = 256 }, .{ .regs = 23, .static = 8416, .bound = 256 }, .{ .regs = 23, .static = 8416, .bound = 256 }, .{ .regs = 28, .static = 8416, .bound = 256 }, .{ .regs = 28, .static = 8416, .bound = 256 } } }, diff --git a/zig/src/families/glm/cuda_vision.zig b/zig/src/families/glm/cuda_vision.zig index d121194544f..c034213320c 100644 --- a/zig/src/families/glm/cuda_vision.zig +++ b/zig/src/families/glm/cuda_vision.zig @@ -176,12 +176,12 @@ pub const Tower = struct { }; var t: Tower = .{ .gpa = gpa, .d = d, .lt = try cuda.cublaslt.Library.open(), .mem = try weights.Weights.alloc(d, total, try weights.onHost()), .ql = ql, .inv_freq = try cuda.DeviceBuffer.alloc(d, 16 * 4), .linears = .init(gpa), .ws = undefined }; errdefer t.deinit(); + t.bytes = t.mem.deviceBytes(); + t.ws = try cuda.DeviceBuffer.alloc(d, t.ws_len); if (try attn.wanted()) { t.full = try cuda.vit.Attention.load(d); std.log.info("glm: the image tower's attention as vit's full attention (TF_GLM_VISION_FUSED)", .{}); } - t.bytes = t.mem.deviceBytes(); - t.ws = try cuda.DeviceBuffer.alloc(d, t.ws_len); var at: u64 = 0; var names = std.StringHashMap(u64).init(gpa); defer names.deinit(); diff --git a/zig/tests/cuda/contract_glm_vision.zig b/zig/tests/cuda/contract_glm_vision.zig index e693ebfc7d3..94aead30afe 100644 --- a/zig/tests/cuda/contract_glm_vision.zig +++ b/zig/tests/cuda/contract_glm_vision.zig @@ -185,6 +185,7 @@ pub const Set = struct { var ctl = try cuda.Module.load(gpu.d, &controls.bytes); errdefer ctl.unload(); set.* = .{ .gpa = gpu.gpa, .mod = mod, .ctl = ctl, .att = try cuda.vit.Attention.load(gpu.d) }; + errdefer set.att.unload(); const rig: rig_.Rig = .{ .gpu = gpu, .s = s }; const f = try glm.vision.Funcs.load(mod); var broken = f; diff --git a/zig/tests/fixtures/gradient-serving.tsv b/zig/tests/fixtures/gradient-serving.tsv index c41b959ba2f..7dc9f2cafa6 100644 --- a/zig/tests/fixtures/gradient-serving.tsv +++ b/zig/tests/fixtures/gradient-serving.tsv @@ -46,7 +46,7 @@ zig/kernels/cuda/nemotron_route.cu 65da41432442f9fd99f73abefe87f34cf3c46b4971afe zig/kernels/cuda/norms.cu 89d3c6cea39fe3e1bf8d5a2fe60465f7ae272548f14711abb59ddac709d2d1db raw main d4541b00e0 (rms_scale shared; same SASS) zig/kernels/cuda/nvfp4_experts.cu dc78d37c1eb1d9a9fff6c1ba9c5f0a9b0eb485a47a56e7b0b2fdbb8bbf1b223b raw #2266 (decode cp.async rings, GB10 SASS unchanged); #4493 (opt-in paired prompt experts, 128-row items) zig/kernels/cuda/nvfp4q.cuh 5fe4fa58568f2293bb72ccfa58b362ba2783b21a781e56946a5a2c328303d111 raw -zig/kernels/cuda/prefill_attention.cu e4cb5bd5e4e9bf8157e5612b45f3dcf78ea31f4ab0822573da495c7aa63728d5.raw main 82f3dde92 (pattn_kernel<64, 8, 4, 8> over paged caches), 94a9a48d6 (helpers to prefill_attention.cuh, SASS unchanged), 191061381 (#2609: two new pattn_kernel instances at two query heads a block, head dims 128 and 64; existing instances unchanged), #2239 (a vision_kernel<64, 8> instance for Qwen3-ASR's audio tower; existing instances unchanged); #3790 (GLM-5.3-Flash's image tower reuses the head-64 vision_kernel instance; existing instances unchanged) +zig/kernels/cuda/prefill_attention.cu e4cb5bd5e4e9bf8157e5612b45f3dcf78ea31f4ab0822573da495c7aa63728d5 raw main 82f3dde92 (pattn_kernel<64, 8, 4, 8> over paged caches), 94a9a48d6 (helpers to prefill_attention.cuh, SASS unchanged), 191061381 (#2609: two new pattn_kernel instances at two query heads a block, head dims 128 and 64; existing instances unchanged), #2239 (a vision_kernel<64, 8> instance for Qwen3-ASR's audio tower; existing instances unchanged); #3790 (GLM-5.3-Flash's image tower reuses the head-64 vision_kernel instance; existing instances unchanged) zig/kernels/cuda/prefill_attention_rows.cuh 21975248a7ec9efd199a28324bba837e7b78f066a63b426ab26587cba38fda5e raw main 94a9a48d6 (helpers shared with the contract controls, SASS unchanged) zig/kernels/cuda/probe.cu 94a3118894b3066e0f0f6fc1cfc3c03828d291077cb26c437b62fcc9b177a210 raw glm-pdl-order's slow writer, planted early reader and glm_pdl::enter() reader zig/kernels/cuda/prompt16.cu 2da3c4ea23de0fa9b2536db0fa66f07bb2d5b45db36c2f9cb321e039ebeac7c2 raw #3252: the lean gate/up SwiGLU pair launch for a dense MLP prompt From 7c40d61507856d0cf3a29972f866a3a89b57a7c5 Mon Sep 17 00:00:00 2001 From: ashhart <71890694+ashhart@users.noreply.github.com> Date: Tue, 24 Nov 2026 12:02:28 +0000 Subject: [PATCH 8/8] changelog: #3790 under Unreleased --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf41b694707..8ab675e6953 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ Each release's page on GitHub has its notes and measurements. See [the 1.0.0 rel ## Unreleased +- GLM-5.3-Flash on CUDA: `TF_GLM_VISION_FUSED=1` (off by default) runs the image tower's attention on the shared full-attention vision kernel instead of two cuBLASLt products around a softmax; its sums run in another order, so replies to prompts with images can differ from the default path, which is unchanged (#3790, refs #3614). Thanks to @ultradaoto. + - Lanes: window-cost tables are measured in interleaved sweeps and saved tables are repaired at startup inside a fixed time budget; a table with no valid timing is refused. Tokens unchanged (#4755). - Drama 3 on CUDA: semantic guidance (`--cfg-gamma` and the other guidance flags) now works, as it does on Metal (#4153). Thanks @plotarmordev.