Repository navigation
llama: Nanbeige4.3-33B on Metal, the bf16 release served as published, every kernel in the contract - #1415
llama: Nanbeige4.3-33B on Metal, the bf16 release served as published, every kernel in the contract#1415BobClawblaw wants to merge 7 commits into
Conversation
|
This is sound and exact by design:
Before it lands:
The branch merges cleanly into main. fmt and lean are clean, host tests pass, and the llama contract passes 15/15 on an M3; the 6 tensor-unit forms need an M5. |
bcc53e7 to
f92916d
Compare
|
Thanks. Pushed f92916d (rebased onto main 15a0b2a, a new third commit; the first two are unchanged apart from the rebase): Teacher-forced misses. 13 of the 1,500 positions. In every one, HF's and the engine's contenders are within one bf16 step on both sides (0.125 below 32, 0.25 from 32 to 64). HF's two tie at 3 of them, the engine's at 8, and neither ties at 22 or 166. Both sides break ties to the lower id. Position 1370 has three contenders, not two:
Admission. The family now admits only the checkpoints listed in No tensor units. Licence. The recipe doc now has a Licence section: Nanbeige4.3-33B is Apache-2.0 at c1093c501cc6460427c0ac634db7223d0450c0ee. The download command is pinned to that revision. Nanbeige4.1-3B (Apache-2.0 at 9c4555c37921c0982af8fffeee1e0a6e6b953c4f) goes in #1417's doc, since the drafter comes in there. Test machine. Understood, and thanks for running the device check on a clean M5. The receipts in the PR were taken beside the other server, as the PR says. Also removed: On these commits over main a1e6d34: |
|
Thanks @BobClawblaw. The full list of teacher-forced misses is a real help, and the qualification gate ( Three things before we run it on a device:
With those in, we'll repeat the checks on an M5 Ultra. |
f92916d to
2e91754
Compare
|
Thanks. Pushed 2e91754 (two commits on the last head, rebased onto main d0c9dc9): 1. Row 1370. You're right: it's not a two-way tie, and neither is 425 (three tokens within a bf16 step there too).
The three lie within 0.116 of each other, under half a bf16 step (0.25 at 32-64), and 388 sits 0.0016 above the rounding midpoint 38.125. HF's run puts 754 a step high; the engine puts 388 a step low. So each side is one step off on one contender, and the reference is off too. To find where the engine's arithmetic departs, I stopped its forward after each layer count at row 1370 (a local probe, not in the PR) and compared the residual with HF's Judged against the float64 pass over all 1,500 positions with the repository's near-tie rule ( 2. The exactness mode fails. 3. A clean receipt, with no other model server or GPU job on the Mac, on this branch's build (a CPU float64 reference run, one layer's weights at a time, overlapped its first minutes):
Token idsCI on these commits over main 03d08f1 (the pushed heads are rebased onto d0c9dc9, which adds only a CI workflow time limit): on #1417's head, which carries all three, |
|
Thanks @BobClawblaw. On One more change, to the teacher-forced checker. |
A new `llama` family for the native Metal engine: dense Llama-architecture checkpoints (heads of 128, default RoPE, no biases, an untied head) in bf16, read in place from the shards with nothing converted. It keeps HF modeling_llama's rounding points (a bf16 residual, LlamaRMSNorm, RoPE with bf16 cos and sin, SiLU), runs prompt chunks on gemm_nax's tensor-unit GEMM and decode windows on a simdgroup-a-row matvec, decode attention on sdpa_vector lanes at absolute positions, and sampled draws on tf_sample_full. tf-llama-run checks greedy tokens, every position's logits, and that windows and one-row steps agree bit for bit. Measured on an M5 Ultra against HF's bf16 run of the release: 1,500 positions teacher-forced at mean KL 0.0015 and top-1 99.1%; decode 16.4 tokens/s a stream and 28-32 with two; cold prompts 1.3k tokens/s at 8k tokens and 563 at 131k. docs/recipes/nanbeige-4.3-33b-metal.md has the rest.
The family's Metal kernels through gates 1-5 (zig/tests/contract/metal_llama*.zig, the roll call and sources in contracts.zig): the glue (embedding, the norms at HF's rounding points, the residual add, RoPE with bf16 cos and sin, the SiLU gate, the decode attention's partials and their merge, the argmax draw by its stated NaN rule), the six row-projection forms, the four GEMM forms and the prompt attention at both served geometries, each with its float64 reference, served shapes and tiles, launched as forward.zig launches it; gate 5 reads the pipelines on this GPU. tf-kernel-contract --only llama on the M5 Ultra: 21 kernels, 21 pass gates 1-4, 0 fail, 0 known findings, 0 limit problems.
…out tensor units by name; the teacher-forced misses and the licence in the doc tf-llama-run takes exact's window width as an argument and loses its environment switches (LLAMA_LAYERS, LLAMA_WINDOW).
…hecks a planted row is reported
… near-tie, a float64 reference, the doc's misses and a one-process receipt
…ty, on either side, before comparing
…s rounding points (--bf16-points)
2e91754 to
567379e
Compare
|
Thanks. Pushed 567379e (two commits on the last head, rebased onto main e4cc630): Non-finite rows.
Re-judging the real 1,500 positions against the float64 pass gives the same result as before (1,483 equal, 17 near-ties, pass). CI on these commits over main ea01ae1: |
What
Fixes #1414. A
llamafamily for the native Metal engine, brought up on Nanbeige/Nanbeige4.3-33B (model_typellama: a dense 33B with 52 layers, 56 query and 8 key heads of 128, a 166,912-token vocabulary, 512K context, thinking and XML tool calls in its chat template). It serves the bf16 release as published, pinned to revisionc1093c501cc6460427c0ac634db7223d0450c0ee: no conversion, bf16 keys and values, no fast math. Recipe doc:docs/recipes/nanbeige-4.3-33b-metal.md.How
zig/src/families/llama/follows the Spark-X2.6 Metal family with HF'smodeling_llamain bf16 as the reference, at its rounding points: a bf16 residual with each add rounded,bf16(w * bf16(x * rsqrt(mean(x^2) + eps))), RoPEbf16(bf16(x c) + bf16(o s))with bf16 cos and sin of the fp32 angle,bf16(bf16(silu(g)) * u). Projections read the release's bf16 rows in place from the mapped shards (no copies, no stacking): prompt chunks of up to 2,048 rows on the tensor-unit GEMM (gemm.metal), decode windows onll_matvecwith fp32 sums rounded once. Attention: prompt chunks on the tensor units over a position-major cache (attention_nax.metal), decode rows on sdpa_vector lanes over key blocks at absolute positions. The lane host's shared rounds, pipelined lone steps drawn on the GPU (argmax ortf_sample_full), copy drafts and the prompt cache; a--context/LLAMA_LOAD_LIMIT_GBbudget (75% of RAM by default) sizes the caches.tf-llama-runchecks greedy tokens, logits, forced steps and window exactness on real weights.Every kernel is registered with the kernel contract (
zig/tests/contract/metal_llama*.zig,zig/src/families/llama/contracts.zig): the glue, the six row-projection forms, the four GEMM forms and the prompt attention at both served geometries, gates 1-5 on this Mac:Measured (M5 Ultra, 256 GB, macOS 27)
Against HF's own code (transformers 4.57.1, bf16 on the CPU): 1,500 teacher-forced positions, mean KL 0.0015, top-1 99.1%; 64 positions after a 9,000-token prompt, mean KL 0.0013, top-1 100%. Three of six 64-token greedy chats equal HF's token for token; the other three part at an exact bf16 tie of the two best logits. One-row steps and 7- or 16-row windows give the same logits bit for bit (
tf-llama-run ... exactfails on any differing row and checks a planted one every run) after 64- and 1,500-token prompts; a turn resumed from a kept prompt state equals the same request after a restart.Served (
--context 131072 --parallel 2 --prompt-cache-gib 8): one stream 16.4 tok/s (61 ms a step, the weights' 62 GiB read at 1.08 TB/s), two streams 28-32 together, each reply equal to its run alone; cold prompts 1,259 / 1,313 / 1,074 / 866 tok/s at 2.1k / 8.3k / 33k / 61k tokens, a 131,132-token prompt at 563 tok/s; a resumed turn starts in 0.34 s against 4.5 s cold. Structured output 18/18, tools 5/5, seeded sampling 9/9, a 60-turn soak beside a decoding stream 60/60, 12 concurrent replies equal to the request alone, needles at 10/50/90% of 128,550 tokens exact. The recipe repo with the harness evidence: github.com/BobClawblaw/nanbeige43-33b-bf16-m5-ultra.Receipt
--context 131072 --parallel 2 --prompt-cache-gib 8andLLAMA_LOAD_LIMIT_GB=150, an idle 93 GiB server of another model loaded beside it for the speed lines below; the one-process receipt follows them.tools/bench_concurrent.py --levels 1,2 --tokens 128 --temperatures 0,0.7 --alone --serial: every reply equals its request alone and"draft": false(alone equal 12/12, serial equal 12/12, failed 0).tools/bench_openai.py --tokens 256 --reps 3 --temperatures 0,0.7: 16.3 tok/s on the chat prompt and 18.2 on the raw prompt greedy, 16.1-16.2 sampled (before: n/a, no engine served this model). Two streams together: 31.0 (chat) and 34.1 (code) greedy.tools/bench_cache.py --require-coldon a 9,000-token prompt: the cold first request's ttft 6.93 s (1,299 tok/s); before: n/a. Repeated raw-token prompts inbench_cache.pyreportcached_tokens0 (the family's prompt cache resumes chat turns: the harness's turns check resumes 5,493 of 5,649 tokens in 0.34 s against 4.4 s cold); the cold first request is what the receipt asks for.tf-llama-run ... exact0 differing rows after 64- and 1,500-token prompts at windows of 16 and 7 (the planted row reported each time); six prompts two at a time on--parallel 2return each one's token ids alone; three chats with an 8,500-token first turn resume their second turn from the prompt cache (8,521-8,528 of 8,554-8,568 tokens kept) with the ids of a server without the cache.tools/zig/llama_teacher_judge.py(the repository's near-tie rule,qwen27_margins.py; exits 1 otherwise, and refuses a row holding NaN or ±Inf on either side): against HF's bf16 run 13 of 1,500 positions differ, 425 and 1370 red (three tokens within a bf16 step); againsttools/zig/llama_f64_reference.py's float64 pass of the release the engine passes (1,483 equal, 17 near-ties) and HF's run is red at 425. The recipe lists every differing position with both verdicts.zig build testandtest-kernel-contractexit 0 on llama: Nanbeige4.3-33B on Metal, the bf16 release served as published, every kernel in the contract #1415's head; on llama: a smaller Llama drafting for the served one (--drafter), replies unchanged (builds on #1415) #1417's head, which carries llama: Nanbeige4.3-33B on Metal, the bf16 release served as published, every kernel in the contract #1415,zig build test,test-kernel-contract,test-golden,fuzz-cortheon,dev-tools,test-server-securityandtest-pull-securityall exit 0;zig fmt --checkis clean, the lean check finds 0 new problems (426 on main and on each head),llama_teacher_judge_test.pypasses, andtf-kernel-contract --only llamaon the M5 Ultra givesSUMMARY 21 kernels: 21 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems. Rebased onto main e4cc630 for this push (its lane-host commits change onlyTENSORFOLD_PREFILL_SHARE, off by default, and a flag only GLM's CUDA backend reads): both heads rebuilt,zig build testexits 0 on both andtest-kernel-contracton llama: Nanbeige4.3-33B on Metal, the bf16 release served as published, every kernel in the contract #1415's, fmt is clean, lean finds 0 new, the bf16 1,500-position logits are bit-identical to the judged run on both, and a drafted greedy chat equals the plain one.TENSORFOLD_PREFILL_SHARE(off by default) and a flag only GLM's CUDA backend reads.Checks
zig build test,zig fmt --check, the lean check (no new problems),test-kernel-contract,test-golden,fuzz-cortheon,dev-tools,test-server-security,test-pull-security: all exit 0 on this branch. Only the M5's tensor units were checked; M1-M4 Macs and smaller RAM are untested. Logprobs are refused by name (the release's tokenizer decodes through aStripstep the engine's tokenizer does not count as token-local). Only the checkpoints inqualified(config.zig: Nanbeige4.3-33B) are admitted, by the geometry their configs name; otherllamacheckpoints are refused by name, as are Macs without tensor units (M1-M4). Tied heads, other head sizes, Llama 3's scaled RoPE and biased projections are refused at load. Nanbeige4.3-33B is Apache-2.0 at the pinned revision.Follow-up: a smaller Llama drafting for the served one, from its bf16 release (#1417). The published MLX quants (#1416) are withdrawn: no implementation of the reference's rounding points meets the near-tie rule against float64 at every position on them (details there).