Repository navigation
Ling-3.0-tiny KDA on Metal using existing k3_kda (#1247) - #3055
Conversation
|
Thanks @ThinkOffApp. This is the right shape for step 1 of #1247: no new kernel, and Kimi K3's path doesn't change. Kimi's metallib is built from a fixed list of Your two questions:
On more rows: yes, as a seam. Run 4 rows as one segment, then 2 + 2 with the state and conv window carried, and check the two GPU outputs are bit-equal. Serving cuts rounds like that. Add one longer case too, say 32 rows, against Before it can land:
Once those are in, we'll run
|
|
/atc claim |
|
Thanks @ashhart. Review items on
CI on |
|
Thanks @ashhart, and a correction from our side on point 4 of the reply above. When I wrote that, the 32-row case gated against Every GPU case now also prints worst Head |
|
Thanks @ashhart. One question now that the ymax gate is out of kda.zig as you asked. The f32 host mixer Do you want a host gate of |
|
@ThinkOffApp yes, a host gate, but gate the math and the rounding separately rather than with one loose bound:
Please don't pin
|
|
Thanks @ashhart, the host gate is in as you described.
Host: 54 pass, 2 skip. GPU 6/6 on M5 Max. |
|
Thanks @ashhart, one small follow-up: we fixed the host math bound at 2^-16 instead of searching for it. 2x margin held on both fixtures (43.60x / 31.34x on M5), so the run-time k loop is gone. |
|
@ThinkOffApp thanks, that's what we asked for. The arithmetic is checked on every platform at 2^-16 with 31-44x margin, the bf16 rounding is pinned bit for bit (ties, subnormals, the largest finite, inf and NaN), and
|
|
Thanks @ashhart ! Linux zig job on Host-gate margins as printed on Linux: Same as M5. mixF64 vs dump 8.26e-10 / 1.10e-9, also the same. No libm difference on these fixtures. |
|
Thanks @ThinkOffApp. The fixed
|
Wire Ling-tiny's KDA layers onto Kimi's k3_kda (full-width gate, D=128, 4 taps). Host mixF64 matches a float64 dump of oracle/kda_inner.py at ~1e-9; that copy equals Model.kda at 2.8e-14 on a fake Ckpt. k3_kda vs the dump is 0.0102 / 0.0119 at 2 / 4 rows, gated at 2 x (2^-7 of the largest |y|). mix/mixF64 return error.KdaWidthTooWide when W > 2048 so ReleaseFast cannot overrun the stack window. ling_forward.py is untouched. No new kernel. No push.
Fold the 11 new lean_check hits (multi-line comments and one comment past 120 columns) so CI's zig job can pass the style gate and actually build.
Gate k3_kda against mix with GLM's per-element bound (each row's own max), report the float64 gap per row, check 4 vs 2+2 with S/conv carried, and 32 rows vs mixF64. Load Kimi's shipped metallib instead of compiling kda.metal from source. Drop the docstring-phrase test.
Print worst |mix - mixF64| per GPU case. The 32-row test still GLM-gates against mix; a GLM bound against mixF64 cannot hold at bf16.
checkDump fails if the fixture is truncated or oversized. The 4-row GPU test name matches the 2-row one: gated against mix, mixF64 printed.
mixAs(f32, no bf16) vs the float64 dump, per element |e| <= |y| * 2^-16 + rowmax * 2^-16. roundBf16 is checked bit for bit. mix vs dump stays a printed number.
Ash's 2x-margin clause is a one-time choice. 2^-16 holds, so k is a constant; the test no longer steps k down at run time.
9aa2269 to
b410345
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. |
Register tf_ling_mla_rope_cache, tf_ling_mla_rope_q and tf_ling_mla_gate_expand with planted source controls, the way Ling KDA and route were done in ashhart#3055.
|
Thanks @ThinkOffApp! This is in TensorFold 1.2.10, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.10
|
Register tf_ling_mla_rope_cache, tf_ling_mla_rope_q and tf_ling_mla_gate_expand with planted source controls, the way Ling KDA and route were done in ashhart#3055.
Register tf_ling_mla_rope_cache, tf_ling_mla_rope_q and tf_ling_mla_gate_expand with planted source controls, the way Ling KDA and route were done in #3055.
Wires Ling-3.0-tiny's KDA layers onto Kimi's existing
k3_kda(full-width gate, D=128, 4 taps). Mixer reference is a stdlib copy of Model.kda's mixer (oracle/kda_inner.py, conv through y).ling_forward.pyis untouched.mixandmixF64returnerror.KdaWidthTooWidewhen W > 2048, so ReleaseFast cannot overrun the stack conv window. Nothing is served yet.GPU tests load the embedded
kimi.metallib(fast fp32 functions), the same library the engine loads, not a precise-math compile ofkda.metal.Launchis the helper that takes the inputs and returnsy(open+dispatch+y()). On81891ffc9,checkwas 190 lines andcheckDump180 with the same buffer and dispatch setup copied. Those two paths are nowGpu25 +Launch158 +check56 +checkDump62. The file is 460 lines vs 438 because the new cases went in: GLM helpers,checkSeam(45 lines), a 32-rowcheck(32), and two extratestlines. The helper is there; the net line count is not a cut of 130.What this changes
k3_kdamatches it at Ling-tiny's shape. MLA/RoPE, the 24-layer forward, experts, and serving remain.2cd0ec7fa). Merged main twice; the only conflict each time wasCHANGELOG.md(our Ling line kept at the top of Unreleased).atc overlap --json:atc: Invalid .github/atc.jsonon this clone; overlap was not run.Checks on this head
346deda67dab4918c9fa81cd9af7fbddd4c1dca2python3 tools/zig/lean_check.py, on the base (0fed2e4a5) and on553dab807: 341 on the base, 341 on the head, 0 new (python3 tools/zig/lean_new.py).zig build test-ling-host -Dcpu=apple_m1 --summary all: 53 pass, 2 skip (55 total)zig build test-ling-kda-gpu --summary all: 6 pass (6 total), re-run after each mergezig fmt --check build.zig zig: passgit diff --check: pass553dab807green (19m37s: lean,zig build test,test-kernel-contract,test-golden, serving pins, security,fuzz-cortheon). fmt and pytest green. Head is now346deda67after merging2cd0ec7fa.kda_vs_model.py(stdlib copy vs Model.kda)GPU vs mix (GLM per-element, each row's own max)
|e| <= |y| * 2^-8 + rowmax * 2^-8 + 1e-30aszig/tests/cuda/glm_ref_kda.zig:136. 0 misses on 2, 4, dump 2, dump 4, and 32 rows.Float64 gap per row (reported, not gated)
k3_kda vs mixF64, 16 heads, this M5 Max. dump = float64 y from
kda_inner.py.Host: mixF64 vs dump 8.26e-10 (2 rows) and 1.10e-9 (4 rows), still gated
< 1e-8. mix vs dump printed per row, not gated (2-row 0.004143 / 0.007375; 4-row 0.003533 / 0.006835 / 0.008783 / 0.018985).Loading the shipped metallib did not move the dump gaps (still 0.0102 / 0.0119) or the 2-row vs mixF64 figure (0.008604) relative to the earlier precise-source compile.
Seam
4 rows as one
SEG_COMMITsegment equals 2 then 2 with S and conv carried (bit-equal GPU y).Not covered: r = identity; fake Ckpt (random tensors, not a real Ling checkpoint).
Receipt
n/a: nothing serves Ling yet. Exactness is the host and Metal checks above.
Checklist