Repository navigation
Conversation
|
Thanks @drowzeys. This is a careful port: transformers-level first-token logits (cosine 0.9998, top-5 identical) and identical greedy answers on text and images. A new family is welcome on our side when it's off by default and leaves the rest of the engine byte-identical, which this does. Before we land it (and #1272 on top), the gaps you listed need to close:
Once those are in, we'll run it on our hardware and land it. - Synthema, Ash's AI Assistant. |
435802b to
5a04a61
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.
5a04a61 to
b1422dc
Compare
|
Thanks for the review. Rebased on current main (past v1.1.5) and updated; CI is green. Point by point:
Also fixed: the One note for running the full contract on a Mac: plain |
ashhart
left a comment
There was a problem hiding this comment.
Thanks @drowzeys. Cosmos3 is selected only by model_type = cosmos3_edge, existing families and kernels are unchanged, and the shader is registered with 13 contract cases, 8 controls and 11 launch records, which is great to see. Before device runs:
- Decode and flash attention use different probability precision: decode multiplies FP32 probabilities by V (
cosmos3.metalaround 147) while flash rounds them to BF16 (around 236), and text switches between them at eight rows (forward.zig:216). On the same inputs they give different bits (a two-key witness gives 0xbd9b vs 0xbd98), so a resumed or chunked prompt wouldn't equal a fresh one. Please use one arithmetic for both, with 7/8-row seam tests. - NAX prompt projections are on by default on tensor-unit Macs and replace the tile projections at 33 rows, but the load-time check compares only tile and twin. Please qualify NAX against the plain projection at every served shape (32/33 rows, image projections, restored tails).
- Concurrency is a serial fallback (
factsFor(1, streams),hidden_rows = false, streams take turns). Families need to serve multiple streams through the lane core's shared rounds with unchanged per-stream arithmetic. - The advertised 4- and 6-bit formats can't load: the loader requires a specific packed layout with no fallback. Please list only the formats that load.
|
Thanks @drowzeys for Cosmos3-Edge on Metal. We're closing this for now, as our 26 Oct review hasn't had a reply. Please do reopen it once attention uses one arithmetic at every width, streams share rounds, and it serves a published checkpoint in its own format. |
Cosmos3-Edge's reasoner (NVIDIA, 4B) serves natively on Metal: text and image chat through the OpenAI server, matching transformers at fixed prompts. Proposed in #1269 as a new family. Off unless a checkpoint's
model_typeiscosmos3_edge; other families' code paths are unchanged.Changes since review
cos3_*pipeline the engine launches is registered (zig/tests/contract/metal_cosmos3*.zig, references incosmos3_ref.zig, gate 5 records inregistry_cosmos3.zig), including the tower's and prompt rows' flash attention (cos3_flash_128,cos3_flash_72) and the decode attention. Eight planted controls, each a source mutation (a dropped bf16 point, an unwritten last output, relu² bymaxalone, a wrong scale group, swapped M-RoPE axes, a skipped rescale, a dropped last key), all go red. Gate 1 found a real bug:cos3_relu2turned a NaN into 0 (maxdrops NaN); fixed, finite outputs bit-identical. Three attention forms nothing launched are removed.tools/bench_concurrent.py --levels 1,2,4 --alone --serial: every concurrent reply equals its solo run, every solo run equals"draft": false. Resumed == fresh: turns 2 and 3 of text and image conversations resumed from the prompt cache's kept states (1,886 and 318 cached tokens) equal the same conversations on a server with--prompt-cache-gib 0.docs/recipes/cosmos3-edge.mdpinsnvidia/Cosmos3-Edgeat344d602b128d1bbdacb43b08d0a3626f46343e29, lists the publisher sha256 of every file the converter reads and the sha256 of every file it writes. The conversion is byte-identical from run to run (transformers 5.20.2, torch 2.14.1, mlx 0.32.4, numpy 2.4.6, macOS); the GB10 in cosmos3: Cosmos3-Edge reasoner on CUDA (stacked on #1271, proposal for #1269) #1272 serves the same files. No weights are republished.Also: rebased on current main (past v1.1.5, at
0d24ecb3; two list conflicts with Spark-X resolved),zig fmtfixed (the failingfmtcheck), and a stray local launch script dropped from the history.What it adds
cosmos3inzig/src/families/cosmos3/: SigLIP2 image tower (variable size, the learned 16 × 16 position grid resized as torch does), projector (LayerNorm, 2 × 2 merge, 4608 → 11520 → 2048) and the dense 28-layer text model (GQA 16/8, relu² MLP, interleaved M-RoPE [24, 20, 20]) behind the lane engine's backend.zig/kernels/metal/cosmos3/cosmos3.metal, including flash attention on simdgroup matrices (a 640 × 480 frame's tower: 145 → 30 ms).tools/cosmos3_edge_to_mlx.py(a development tool) writes the reasoner as MLX 8-bit affine (groups of 64); the generation tower, VAE and action heads are left out.Receipts
M5 Ultra (macOS 27.0.1, Xcode Metal toolchain 32023.921.5),
tensorfold-native 1.1.5built from this branch, the 8-bit conversion above. Reference: transformers fp32 on CPU with the same 8-bit weights dequantized in. Prompts: two text questions; the checkpoint's publicassets/example_reasoning_input.png(512 × 341) with its own prompt; itsassets/example_i2v_input.jpgresized to 640 × 370 PNG; a synthetic 640 × 480 picture of shapes and a word.--only cosmos3SUMMARY 13 kernels: 13 pass gates 1-4, 0 fail, 0 known findings; 8 controls: 8 red as planted, 0 missed; 0 limit problemsSUMMARY 183 kernels: 183 pass gates 1-4, 0 fail, 2 known findings; 46 controls: 46 red as planted, 0 missed; 0 limit problems--offline(M1/M2 compiles)"draft": falsebench_concurrent, 256 tokens)zig build native,zig build testandzig build test-golden(-Dcpu=apple_m1) pass;--only cosmos3gives the same 13 / 8 / 0 line; the 5 parity prompts give the same logits and text as before the rebase. The full 183-kernel run was on the v1.1.5 base.zig build test-kernel-contract: pass.zig fmt --check build.zig zig: clean.tools/zig/lean_check.py: 433 findings on current main and the same 433 on the branch, zero new; every new file is under 600 lines.tf-rotary-sweep, then--rotary-accuracy FILE); plainzig build kernel-contractstops withUnrecordedRotaryCompileron main too. The 2 known findings are the documented affine_mm q4 ones.--offlinereports one inherited record,glm gather glm_rows_bf16_nax(recorded 0/0, this Xcode compiles it for 1,024), in a file this PR does not touch.Gaps
Credits: NVIDIA for Cosmos3-Edge (OpenMDW 1.1); the family ports the transformers reference (Apache-2.0), noted in THIRD_PARTY_NOTICES.