Repository navigation
Conversation
This was referenced Oct 25, 2026
7 of 8 tasks
9 tasks done
drowzeys
force-pushed
the
upstream/cosmos3-cuda
branch
from
October 26, 2026 01:10
47b88ff to
7897c00
Compare
A native Metal family for NVIDIA Cosmos3-Edge's understanding tower: dense GQA with interleaved M-RoPE [24, 20, 20] and relu^2, the SigLIP2 tower with its learned 16 x 16 position grid resized as torch's antialiased bilinear, and the 2 x 2 patch merger. MLX affine 4/6/8-bit checkpoints from tools/cosmos3_edge_to_mlx.py (reasoner only). Against the transformers model on the same 8-bit weights in fp32: text logits cosine 0.99980, image prompt (758 tokens) 0.99976, both 48-token greedy exact.
… row The image tower and the text model's prompt rows attend in 32-row tiles on 8 x 8 bf16 MMAs with each 32-key block staged once (P rounded to bf16 as the eager weights are): a 640 x 480 frame's tower 145 -> 30 ms on an M5 Ultra. Calls under 33 rows take the decode twin. Image prompt parity after: cosine 0.99974, 48-token greedy exact. THIRD_PARTY_NOTICES names the transformers code the family ports (Apache-2.0) and NVIDIA's weights (OpenMDW 1.1); README lists the converted reasoner.
The kernel contract's non-finite gate caught cos3_relu2 turning a NaN into 0 (Metal's max drops a NaN, as fmax does); it now keeps it, and every finite output is unchanged bit for bit. cos3_attn_72 and the cos3_attn_tile forms had no caller and leave the source and the pipeline list.
Every cos3 kernel the engine launches goes through gates 1 to 4 (tests/contract/metal_cosmos3*.zig): each output within float64's range at its bf16 rounding points over the spread its fp32 steps and Metal's fast exp allow (cosmos3_ref.zig), the norms' and attention's sums shown fp32 at gate 4, and eight planted controls, each red at its gate. Gate 5 records the eleven launches with their M1/M2 compiled limits (registry_cosmos3.zig). On an M5 Ultra: SUMMARY 13 kernels: 13 pass gates 1-4, 0 fail, 0 known findings; 8 controls: 8 red as planted, 0 missed; 0 limit problems.
docs/recipes/cosmos3-edge.md pins nvidia/Cosmos3-Edge at 344d602b128d1bbdacb43b08d0a3626f46343e29, the publisher sha256 of the files tools/cosmos3_edge_to_mlx.py reads, and the sha256 of every file the 8-bit conversion writes (byte-identical from run to run with the versions named), with the family's checks: parity against transformers in fp32, concurrent == solo at 1, 2 and 4 streams, resumed == fresh across conversation turns. The README row and the converter's usage line point at it; the embedding kernel's comment says it rounds once.
…er on cuBLASLt) The Metal family's twin for NVIDIA GPUs, a lane backend in native/cosmos3_cuda.zig. The text model runs on qlinear's MLX 8-bit tiles (one-row decode on group sums up to 16 rows, the prompt GEMM past that) with q, k and v stacked into one projection; cosmos3.cu holds the glue at cosmos3.metal's rounding points: 8-bit embedding rows, RMS norms, interleaved M-RoPE with the cache write, relu^2, causal GQA over a stream's cache (eight rows a block, and a split-key kernel for decode rows), and every group sum computed in the kernel that writes its rows, summed in input order. The image tower widens its 8-bit weights to bf16 at load and runs on vit.zig's cuBLASLt Linears, LayerNorm, GELUs and the 72-dim full attention; a 640 x 480 frame's shapes are planned at load. On a GB10 against the transformers model on the same 8-bit weights in fp32: text logits cosine 0.99980 (top-5 identical), image prompt (758 tokens) 0.99977 (top-4 identical), both 48-token greedy exact. A 640 x 480 frame: tower 34 ms, text prompt 43 ms; decode 107 tok/s (the 8-bit projections at ~212 GB/s). Seven camera questions: first token 0.10 s, answer 0.32 s (median).
… named; relu^2 keeps NaN cosmos3.cu's kernels now call cosmos3.cuh's bodies with every rounding point kept (K) and no fault planted (F), so the contract's controls can drop exactly one. relu^2 kept fmaxf(x, 0), which turns a NaN input into 0 where torch's relu keeps it (the contract's gate 1 found it); a NaN now stays NaN and every finite output is unchanged. On a GB10 the rebuilt server and the previous one give byte-identical first-token logits and identical 64-token greedy answers for a text, a code and a synthetic image prompt.
…planted controls and nvcc 13.0.88 records Nine registrations through gates 1 to 4: the 8-bit embedding rows and the tower widening bit-equal to float64 at MLX's points, the image placement, the RMS norm rows (with and without the residual add) within the spread their fp32 steps allow, relu^2, the interleaved M-RoPE with its cache writes, and the prompt and decode attention within float64's range (core/attention_range.zig); every 64-value group sum is replayed bit for bit. Twelve controls each drop one rounding point or plant one fault, and each goes red. Gate 5 holds all eight launches with registers and shared bytes measured by nvcc 13.0.88 for sm_80, sm_86, sm_89, sm_120 and sm_121; later compilers stay pending.
…d checks on a GB10 The same pinned conversion on a GB10 against the transformers fp32 reference: first-token top-1 on four of five prompts (the fifth at a 0.026 near-tie), three of five 48-token greedy replies identical and the other two parting at the reference's near-ties, concurrent == solo at 1, 2 and 4 streams. The CUDA backend keeps no prompt states yet.
…g within 600 lines on current main
drowzeys
force-pushed
the
upstream/cosmos3-cuda
branch
from
October 26, 2026 01:13
7897c00 to
61aeb65
Compare
Contributor
Author
|
Updated alongside #1271: rebased on current main (past v1.1.5) and onto #1271's new head.
|
This was referenced Oct 26, 2026
ashhart
requested changes
Oct 26, 2026
ashhart
left a comment
Owner
There was a problem hiding this comment.
Thanks @drowzeys. On top of #1271's points (which carry over), the CUDA side needs:
- Attention changes arithmetic between one and several rows (
attn1for one row, another kernel for more), so resumed or chunked prompts won't equal fresh ones. Please use one arithmetic for both. - Decode tail padding evaluates zero times infinity:
attn1loops over all 32 value lanes and loads padding, which can turn a finite result into NaN. Mask the tail. - Concurrent serving still uses the serial fallback (
exact_width = 1); families need shared rounds through the lane core. - Native open forwards the requested streams without a complete admission budget, so capacity is advertised that may not fit.
- The vision tower expands affine weights at load; its precision and the model's fidelity need qualifying against a reference.
Owner
|
Review of #1271 (Metal) and #1272 (CUDA) against main 3f408b6 (74 behind; conflicts only in lists). Selection is clean (only
|
Owner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cosmos3-Edge's reasoner on CUDA (DGX Spark, GB10): the Metal family's twin from #1271, as a lane backend. Stacked on #1271 (its first six commits are #1271's); proposed with it in #1269. Off unless a checkpoint's
model_typeiscosmos3_edge.Changes since the first version
0d24ecb3) and onto the updated cosmos3: Cosmos3-Edge reasoner (image + text) on Metal (new family, proposal for #1269) #1271;build/cuda.zigand the CUDA contract runner kept within 600 lines on it;zig fmtfixed (the failingfmtcheck). The earlierzig-windowsfailure wastool_parse_test's timing assertion (namespaced openers without closers read in linear time), unrelated to this family.tf_cos3_*kernels are registered (zig/tests/cuda/contract_cosmos3*.zig, nine registrations) with twelve planted controls and nvcc 13.0.88 records for sm_80, 86, 89, 120 and 121 (cosmos3_cuda_records.zig). Kernel bodies moved tocosmos3.cuh, templated on the rounding points they keep, so each control is the production kernel with one point dropped or one fault planted.tf_cos3_relu2turned a NaN into 0 throughfmaxf. Fixed as on Metal; finite outputs unchanged (logit dumps and greedy answers byte-identical before and after).docs/recipes/cosmos3-edge.md, pinned revision and output hashes) now has a CUDA section; the GB10 serves the same files, hash for hash.What it adds
zig/kernels/cuda/cosmos3.cu: the glue atcosmos3.metal's rounding points (8-bit embedding rows, RMS norms, interleaved M-RoPE with the cache write, relu², causal GQA over a stream's cache plus a split-key decode kernel), every group sum computed by the kernel that writes its rows.Receipts
GB10, CUDA 13.0 (nvcc 13.0.88),
tensorfold-native 1.1.5from this branch, the pinned 8-bit conversion. Reference and prompts as in #1271: transformers fp32 with the same 8-bit weights; two text prompts, the checkpoint's public reasoning image, its i2v example at 640 px, a synthetic 640 × 480 picture.SUMMARY 347 kernels: 347 pass gates 1-4, 0 fail, 5 known findings; 104 controls: 104 red as planted, 0 missed; 52 limit problems(see below)"draft": false--prompt-cache-gib 0server (8 of 8)zig build native -Doptimize=ReleaseFast -Dnvcc=…,zig build test-cuda-hostandzig build test-kernel-contractpass;zig fmt --check build.zig zigis clean; the 5 parity prompts give the same logits and text as before the rebase.tools/zig/lean_check.py: 433 findings on current main and the same 433 on the branch.Gaps and next steps