Repository navigation
inkling2 metal: ceiling-pow2 dense dispatch and guarded bf16_matvec - #4998
Conversation
|
The trial merge of zig build test-inkling2-host test-inkling2-metal-host test-inkling2-metal-capabilities tf-kernel-contract -Dfixed-cpu -j2 --summary all
./zig-out/bin/tf-kernel-contract --only 'll_matvec_'
./zig-out/bin/tf-kernel-contract --only 'control: metal llama matvec'I also checked the overlap note against #2890's current Igor Lessio - AIFLOW LABS |
|
Thanks, @gilby. The active rows keep the same K loop, reduction and BF16 store, and the partial-row guards bound input loads. The tight-buffer parity and numerical control results are useful. Safe for bounded A/B with pinned checkpoint/build identities and parent-shader byte comparisons. Keep shared-kernel limits and the disclosed first-token regressions visible. Also describe the 32-row entry as one dispatch with two 16-row passes; it still walks the weights twice.
|
c011aec to
3286430
Compare
|
I trial-merged zig build test-inkling2-host test-inkling2-metal-host test-inkling2-metal-capabilities \
tf-kernel-contract -Dfixed-cpu -j2 --summary all
./zig-out/bin/tf-kernel-contract --only 'll_matvec_'
./zig-out/bin/tf-kernel-contract --only 'control: metal llama matvec'Ash’s wording note still applies to the doc comment above Igor Lessio - AIFLOW LABS |
|
Updated the PR description to state explicitly that
|
Refs ashhart#4961 Use ceiling-power-of-two sp_matvec_{1,2,4,8,16,32} dispatch in inkling2/metal/forward.zig so non-power-of-two widths up to 32 rows read weights once instead of 2x-4x, and 64-row prefills dispatch 32+32. Guard X row loads in core/bf16_matvec.metal (early return for a.rows == 0 and branchless min(r, active - 1u) clamping on partial tiles), and tile ROWS > 16 into <=16-row sub-chunks inside the single 32-row kernel to avoid acc[32] register spilling while preserving exact FP32 serial summation order. Add host dispatch and Metal tight-buffer exactness tests for inkling2 dense(), and exercise partial-tile row counts (5, 9, 17) in llama matvec contract probes.
3286430 to
2674e93
Compare
|
Thank you @gilby. 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. |
What this changes
Before: on
main,dense()inzig/src/families/inkling2/metal/forward.zigdecomposes non-power-of-two row counts greedily from32, 16, 8, 4, 2, 1, dispatching multiplesp_matvec_*kernels (for examplec=3as2 + 1, reading weights twice;c=5..7reading weights 2-3x; androws=6..8DSpark verify rounds re-reading BF16 dense projections) whiletf_bf16_matvec_tusesr < a.rowsonly after an unguardedXload and keeps allROWSaccumulators live together.After:
denseStep()dispatches a ceiling-power-of-twosp_matvec_{1,2,4,8,16,32}kernel forleft <= 32rows (32+32for64-row prefills): for1..16rows, one dispatch walks the weights once, and for17..32rows the32-row entry (sp_matvec_32) is one dispatch with two 16-row passes (it still walks the weights twice rather than issuing multiple smaller dispatches). Inzig/kernels/metal/core/bf16_matvec.metal,tf_bf16_matvec_treturns early fora.rows == 0,tf_bf16_matvec_chunkclamps partial-tileXloads branchlessly (min(r, active - 1u)), andROWS > 16tiles into two<=16-row passes over the weights to avoidacc[32]register spilling while keeping exact FP32 serial summation order. Added host dispatch and Metal tight-buffer exactness tests inzig/src/families/inkling2/metal/dense_test.zigand partial-tile row counts (5,9,17) inzig/tests/contract/metal_llama_dense.zig.main(9961ca4920,git merge-tree --write-tree origin/main HEADclean:9b9584b4a6)atc overlap --json:changedFiles: 5,myPullRequests: [],overlaps: [{"source": "workingTree", "pullRequest": 2890, "sharedFiles": 1, "areas": [7], "conflict": "conflicts"}](legacy open PR llama on Metal: Qwen2 checkpoints, Bimo-7B-CyberAgent's bf16 release with its q, k and v biases and YaRN at HF's rounding points #2890 on sharedbf16_matvec.metal).Checks on this head
3286430bfdpython3 tools/pr_check.py --base origin/main --pr 4998(python3 tools/zig/lean_check.py):lean 164 vs 164, 0 new,0 error(s), 1 warning(s)(advisory: noUnreleasedchangelog bullet;5changed files, max touched.zigfile408lines);zig fmt --check build.zig zigandgit diff --check origin/main..HEADpass with exit0;zig build compile-inkling2-native-hostandzig build compile-inkling2-native-host -Dtarget=x86_64-windowsexit0.zig build test-inkling2-host -Dcpu=apple_m1 -Doptimize=ReleaseFast --summary all:45 pass, 4 skip (49 total)(0 failed; skipped: 4 optional checkpoint/tokenizer env tests requiringTF_INKLING2_TINY/TF_INKLING2_REAL/TF_INKLING2_CKPT).zig build test-inkling2-metal-host -Dcpu=apple_m1 -Doptimize=ReleaseFast(plus standalone test binary--cache-dir=./.zig-cache --seed=0xcc8ea13f):112 passed; 6 skipped; 0 failed(skipped: 2 checkpoint serving tests, 2 checkpoint alloc failure tests, 2 JPEG tests pending newerlibjpeg-turbo).main(9961ca4920) at3286430bfd; CI checks pending after force-push.Receipt
tools/bench_concurrent.py --tokens 128 --reps 2,--context 8192 --parallel 4,0cross-legtoken_sha256mismatches across all cells on both machines):mainvs branch):--no-drafts --parallel 4,c=3,4,T=0.0):c=3:code T=0.0:19.20 -> 19.90 tok/s(+3.65%, TTFT1.028 -> 1.027s,-0.10%);chat T=0.0:19.70 -> 20.30 tok/s(+3.05%, TTFT3.617 -> 3.465s,-4.20%).c=4:code T=0.0:21.20 -> 21.20 tok/s(+0.00%, TTFT1.267 -> 1.252s,-1.14%);chat T=0.0:21.80 -> 21.80 tok/s(+0.00%, TTFT4.750 -> 4.462s,-6.05%).--drafter {TARGET} --parallel 4,c=1,4,T=0.0,1.0):c=1:code T=0.0:13.95 -> 14.00 tok/s(+0.36%, TTFT-11.76%);chat T=0.0:12.50 -> 12.60 tok/s(+0.80%, TTFT-5.56%);code T=1.0:10.55 -> 10.60 tok/s(+0.47%, TTFT-1.36%);chat T=1.0:12.30 -> 12.45 tok/s(+1.22%, TTFT-2.01%).c=4:code T=0.0:11.20 -> 11.90 tok/s(+6.25%, TTFT-1.59%);chat T=0.0:8.70 -> 9.30 tok/s(+6.90%, TTFT5.146 -> 4.811s,-6.52%);code T=1.0:8.70 -> 9.20 tok/s(+5.75%, TTFT-3.33%);chat T=1.0:8.10 -> 8.70 tok/s(+7.41%, TTFT5.084 -> 4.745s,-6.66%).mainvs branch, Metal 3 overlay):--no-drafts --parallel 4,c=3,4,T=0.0):c=3:code T=0.0:22.00 -> 22.55 tok/s(+2.50%, TTFT0.790 -> 0.774s,-1.96%);chat T=0.0:22.90 -> 23.50 tok/s(+2.62%, TTFT2.793 -> 2.543s,-8.97%).c=4:code T=0.0:23.60 -> 23.65 tok/s(+0.21%, TTFT0.994 -> 0.962s,-3.22%);chat T=0.0:24.80 -> 24.80 tok/s(+0.00%, TTFT3.565 -> 3.377s,-5.26%).--drafter {TARGET} --parallel 4,c=1,4,T=0.0,1.0):c=1:code T=0.0:17.20 -> 17.25 tok/s(+0.29%, TTFT+9.04%);chat T=0.0:15.30 -> 15.25 tok/s(-0.33%, TTFT-4.65%);code T=1.0:14.40 -> 14.40 tok/s(+0.00%, TTFT-0.59%);chat T=1.0:15.05 -> 15.20 tok/s(+1.00%, TTFT-2.56%).c=4:code T=0.0:14.35 -> 14.80 tok/s(+3.14%, TTFT-3.09%);chat T=0.0:9.80 -> 10.15 tok/s(+3.57%, TTFT+0.54%);code T=1.0:11.90 -> 12.20 tok/s(+2.52%, TTFT-0.24%);chat T=1.0:9.60 -> 9.85 tok/s(+2.60%, TTFT-1.04%).zig/kernels/metal/core/bf16_matvec.metal,zig/src/families/inkling2/metal/forward.zig,zig/src/families/inkling2/metal/dense_test.zig,zig/src/families/inkling2/metal/host_test.zig, andzig/tests/contract/metal_llama_dense.zig.3286430bfdstacked on9961ca4920, Zig0.17.0-Dcpu=apple_m1 -Doptimize=ReleaseFast, Apple M5 Max (applegpu_g17), Apple M5 Pro 64 GiB, Apple M3 Ultra 512 GiB; checkpoint Inkling-2-Mini.dense()projections (c=1..32andprefill) and sharedTF_BF16_MATVECSkernels on Apple Silicon Metal GPUs (ll_matvec_*also covered byllama glue ll_matvec_*contract suite); Apple M1/M2/M4 not available.0cross-legtoken_sha256mismatches across all A-B-B-A legs (plain--skip-serialanddspark--serial) on both Apple M5 Pro and Apple M3 Ultra; Metal tight-buffer tests indense_test.zigverify zero OOB reads/writes and exact0-ULP FP32 serial reduction parity againstmain's greedy decomposition.+3.65%plainc=3/+7.41%self-draftedc=4on Apple M5 Pro; up to+2.62%plainc=3/+3.57%self-draftedc=4on Apple M3 Ultra).c=32+32(two 32-row dispatches, each executing two 16-row passes overW, plus non-pow2 prompt remainder tails up to 16 rows in one dispatch) improve concurrent TTFT up to-6.05%plain /-11.76%self-drafted on Apple M5 Pro and-8.97%plain on Apple M3 Ultra, while keeping the disclosed single-stream DSpark first-token latency increase (+9.04%on M3 Ultrac=1 code T=0.0) visible above.Kernel contract, only when a GPU kernel is new or changed
TF_BF16_MATVECSkernels (sp_matvec_{1,2,4,8,16,32}andllama glue ll_matvec_{1,2,4,8,16,32}), adding branchless bounds clamping on partial tiles (active < ROWS) and<=16-row register tiling forROWS=32. No new kernel names added; replaces greedy32,16,8,4,2,1dispatch with ceiling-pow2 dispatch indenseStep.56/56planted controls across all 8 non-dsparkmetal inkling2suites on Apple M5 Max (3286430bfd) and55/55on Apple M3 Ultra fail red as planted (0missed), plusmetal_llama_dense.zigpartial-tile probes (5,9,17rows).SUMMARYline and exit status:--only "ll_matvec",3286430bfd):SUMMARY 24 kernels: 24 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems; gates 134317 ms, limits 123 ms(exit0).metal inkling2, all 8 non-dspark suites on3286430bfd;50kernels,56controls red,0fail,0missed,0limit problems):metal inkling2 attention:SUMMARY 5 kernels: 5 pass gates 1-4, 0 fail, 0 known findings; 5 controls: 5 red as planted, 0 missed; 0 limit problems; gates 3086 ms, limits 76 ms(exit0).metal inkling2 prompt:SUMMARY 1 kernels: 1 pass gates 1-4, 0 fail, 0 known findings; 1 controls: 1 red as planted, 0 missed; 0 limit problems; gates 1492 ms, limits 61 ms(exit0).metal inkling2 glue:SUMMARY 10 kernels: 10 pass gates 1-4, 0 fail, 0 known findings; 13 controls: 13 red as planted, 0 missed; 0 limit problems; gates 445 ms, limits 72 ms(exit0).metal inkling2 experts:SUMMARY 12 kernels: 12 pass gates 1-4, 0 fail, 0 known findings; 17 controls: 17 red as planted, 0 missed; 0 limit problems; gates 4996 ms, limits 64 ms(exit0).metal inkling2 mma:SUMMARY 0 kernels: 0 pass gates 1-4, 0 fail, 0 known findings; 0 controls: 0 red as planted, 0 missed; 0 limit problems; gates 0 ms, limits 226 ms(exit0; skipped on Apple M5 Max with tensor units).metal inkling2 loop:SUMMARY 3 kernels: 3 pass gates 1-4, 0 fail, 0 known findings; 4 controls: 4 red as planted, 0 missed; 0 limit problems; gates 180 ms, limits 98 ms(exit0).metal inkling2 runtime:SUMMARY 6 kernels: 6 pass gates 1-4, 0 fail, 0 known findings; 6 controls: 6 red as planted, 0 missed; 0 limit problems; gates 57 ms, limits 28 ms(exit0).metal inkling2 vision:SUMMARY 13 kernels: 13 pass gates 1-4, 0 fail, 0 known findings; 10 controls: 10 red as planted, 0 missed; 0 limit problems; gates 1111 ms, limits 41 ms(exit0).metal inkling2 dspark: on base9961ca4920,--only "metal inkling2 dspark"failed witherror: DsparkThreads(tf_ink2_dspark_kappamaxThreads() == 64 < 256indspark_kernels.zig:122-125, untouched by inkling2 metal: ceiling-pow2 dense dispatch and guarded bf16_matvec #4998; fixed and merged onmainin inkling2 metal dspark: match maxThreads guard to kappa (64) and attention (768) #5041).metal inkling2, Metal 3 overlay):SUMMARY 48 kernels: 48 pass gates 1-4, 0 fail, 0 known findings; 55 controls: 55 red as planted, 0 missed; 0 limit problems; gates 11127 ms, limits 38 ms(exit0).Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.--drafter, no slower than without it, greedy and sampled.