Repository navigation
Ling-3.0-tiny bf16 forward over all 24 layers on Metal (#1247) - #3919
Conversation
|
Thank you @ThinkOffApp for the full-forward receipts and for leaving the numerical acceptance unresolved instead of raising a tolerance. The open item is our answer to your rule question: we still need to decide whether the #1247 bound is judged in total or per row, and at which length. Please keep the check reporting both distances until we settle that; no other change is needed from you now.
|
aea9c1e to
f9c125b
Compare
|
[Joshua's agent] Answering the two open items from the 07:51Z review.
|
|
Thank you @ashhart, and thank you @joshuaswarren for the clear proposal: bound judged on totals at 8 and 32 rows with 2 rows reported only, and same-routing agreement as the bar with the free-picks table kept as a diagnostic. We have that change ready locally and will push it as soon as @ashhart confirms that this is the rule for #1247. |
f9c125b to
1df1164
Compare
|
I trial-merged The first reproducibility detail was in the MLA fixture: its Python probe checks only The full I verified the probe fix after merging I then pointed only the scratch fixture cache at an empty directory and used a Python interpreter where Rechecked the exact #4293 train head Igor Lessio - AIFLOW LABS |
|
Thank you @AIFlowML for running this and for the trial merge. You are right about the probe: it only asked for torch, and the dump script also imports safetensors, so a torch only interpreter failed as DumpGen where it should skip. The probe now imports both and the skip line names both ( |
5fd9fac to
e1dd060
Compare
|
Thank you @ThinkOffApp. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
The dump script imports both; an interpreter with torch alone passed the probe and then failed as DumpGen instead of skipping. The skip line now names both packages.
e1dd060 to
1834924
Compare
|
Thank you @ThinkOffApp. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
|
Thank you @ashhart for merging this and for the credit! Next steps on our side for #1247:
Cheers |
Thank you @ashhart for the review and the merge of step 2 (#3609). This is step 3 of #1247: the bf16 forward of Ling-3.0-tiny over all 24 layers on Metal, with the published weights. It is composed from kernels that already exist and adds no GPU kernel source. Nothing is served yet.
Layer 0 is the dense MLP, the MLA layers are 3, 7, 11, 15, 19 and 23, the other 18 are KDA, and layers 1 to 23 are MoE with 8 picked experts plus the shared one. It reuses Kimi's row projections, RMS, residual add,
k3_kda,k3_mlaand expert combine, Ling'stf_ling_routeand the three MLA kernels from step 2, and LFM3's bf16-point SwiGLU. The forward refuses a config with other geometry, quantisation or expert clamps. Checkpoint tensors stay mapped and are not copied.The reference stays
zig/src/families/ling/oracle/ling_forward.py. It gained an optional--layer-tracethat writes the residual hidden rows; logits with and without it are identical. There is no second reference.One question for you
Your rule from #1247 is that Metal should be no further from float64 than bf16 rounding puts the reference itself. On the full forward we measure this, on the same expert picks for all three:
So Metal is closer than the bf16 reference in total at 8 and 32 rows and further at 2 rows, and row by row it is further on a little over half the rows. Every next-token argmax agrees across Metal, float64 and the bf16 reference at all three lengths. We did not raise a tolerance to make this pass: the check reports both numbers and marks accuracy as unresolved. Do you judge this bound in total or per row, and at which length? We will fix the test to whatever you say.
A second part of the same question, which showed up when we ran real chat prompts through a local serving branch (not part of this PR; the numbers are here because they bear on the bar). When each side picks its own experts, the picks differ near ties. On 20 short prompts, 136 generated tokens until stop:
Every one of those token differences sits at a route score gap under 0.005, and the two sets are not the same tokens (two prompts are Metal only, one is bf16 only, two are shared). With Metal's picks forced on the references, all three agree on every token except one first token where float64's margin (0.0126) is below Metal's measured error on the two competing tokens (0.0193). So Metal behaves like the reference's own bf16 rounding. Is the bar agreement on the same routing, as this PR tests, or do you want picks judged against float64's own, which the bf16 reference does not meet either?
What this changes
b7298b4ea(rebased again on 20 Nov; the only conflict wasCHANGELOG.md, where all upstream entries and this PR's one line are kept).zig/build/kernel_contract.ziggains one line that registers the Ling forward build steps beside the existing ones.Checks on this head
1df1164ba. The checks below were rerun on this head after the rebase, except the kernel contract.python3 tools/zig/lean_check.py, on the base and on this head: 168 problems, 168 on the base, 0 new (python3 tools/zig/lean_new.py).zig build <step> -Dcpu=apple_m1 --summary all:test-ling-forward: the 3 whole/chunk/resume scenarios (2, 8 and 32 rows) passed, 0 skipped, 0 failed; 50/50 build steps.test-ling-host: 64 passed, 2 skipped, 0 failedtest-ling-mla-gpu: 13 passed, 0 skipped, 0 failedzig fmt --check build.zig zig: passf9c125b59and not rerun after the 20 Nov rebase; the seven code commits are unchanged by it (git range-diff).inclusionAI/Ling-3.0-tinyat9a98e35fe1c9ee255f78dd64771c7ae15a799481, 32 shards, each matched against its upstream SHA-256.Metal against itself
Whole prompt against the same prompt in single-row chunks, and a fresh instance restored after token 1 against the whole run: byte-equal at 2, 8 and 32 rows. That covers the logits, all 18 KDA states and conv histories, and all 6 MLA caches, for the chunked run and for the resumed run. A truncated snapshot is refused.
To see that the state comparison can fail, one byte of the resumed run's last MLA cache slot was corrupted once after the logits check. The comparison went red, the fault was removed, and the three lengths passed again.
Routing
Both reference runs (float64 and bf16-point) use the expert picks the Metal run made, so the three compute the same thing. Where Metal's picks differ from the ones float64 would have chosen, the check records the gap in the route scores: 0.00135 at 2 and 8 rows and 0.01255 at 32 rows.
Error paths
Forward.initandMla.initbuild their parts into locals witherrdeferand assemble the struct last. Two forced buffer failures (one late inForward.init, after the MoE part exists, and one early inMla.init) returnOutOfMemoryand bring the owned-buffer count back to where it was. Pipeline and library cleanup is covered byerrdeferbut not counted by a test.Not covered
(37*t + 11) % 157182), not text. No tokenizer or prompt is involved.TF_LING_CHECKPOINT) and a Python with torch and safetensors (TF_LING_PYTHON, thenpython3onPATH). Without either they printSKIPand say which is missing; nothing is downloaded.Cheers