Skip to content

dsv41 metal: MXFP4 routed experts for decode rows over Kimi's plan, down and combine - #1707

Merged
ashhart merged 2 commits into
ashhart:mainfrom
gilby:dsv41-metal-pr/03-mxfp4-experts
Nov 1, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
gilby:dsv41-metal-pr/03-mxfp4-experts

Conversation

@gilby

@gilby gilby commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

DeepSeek V4.1's MXFP4 routed experts for decode rows: tf_dsv41_xp_up (fp8 act_quant, clamped SwiGLU, route weight) and the down, plan and combine as a DeepSeek-only copy of Kimi K3's (experts_kimi.metal: tf_dsv41_route_plan, tf_dsv41_xp_down_one/_multi, tf_dsv41_xp_combine), whose down chain is exact over the whole E8M0 scale range. Kimi K3's shipped kernels (kimi/experts.metal, kimi_common.h) are unchanged: git diff main -- zig/kernels/metal/kimi is empty and tf-kernel-contract --only kimi passes. All registered with the kernel contract; docs/kernel-contract.md describes the checks.

Part 3 of 18 of the stack for #1676; stacks on dsv41-metal-pr/02-fp8-kernels (part 2, #1706).

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision: TensorFold 61305ae on main 2761c24 (native Zig 0.17.0; no MLX or PyTorch); Apple M3 Ultra (60-core GPU), 96 GB, macOS, for the kernel and device tests; checkpoint deepseek-ai/DeepSeek-V4.1-Flash-1017.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false: n/a: kernels only; the kernel contract checks each launch geometry's bits against the others and against float64.
  • Decode speed before and after, from tools/bench_openai.py: measured on the PR that turns serving on.
  • Prompt speed before and after: the cold first request's ttft_s from tools/bench_cache.py --require-cold on a long prompt, or "n/a" with the reason when the change cannot reach prompt processing: measured on the PR that turns serving on.
  • Tests run, with pass, fail and skip counts: zig build test tf-kernel-contract -Dcpu=apple_m1: exit 0, 583/583 steps, 0 fail, 36 skip; kernel contract, tf-kernel-contract --only dsv41 (Metal): SUMMARY 14 kernels: 14 pass gates 1-4, 0 fail, 0 known findings; 20 controls: 20 red as planted, 0 missed; 0 limit problems; gates 40783 ms, limits 129 ms; tf-kernel-contract --only kimi: SUMMARY 1 kernels: 1 pass gates 1-4, 0 fail, 0 known findings; python3 tools/zig/lean_check.py: 4838 files, 424 problems, the same count as main (4807 files, 424). Zig's summary counts only the test binaries it ran in that invocation, so the step count is the comparable figure.
  • Not run, and why: CUDA: no CUDA code changes; Metal on M1, M2, M4 and M5: one M3 Ultra only (the contract's limits check covers the M1 to M5 pipeline limits).

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
  • No precision traded for speed. If the bits change, the description says which sums change and why.
  • A new or changed GPU kernel is registered with the kernel contract (docs/kernel-contract.md); each backend's SUMMARY line is in the receipt.
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

@gilby

gilby commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

On the Kimi K3 point: this part no longer touches Kimi's shipped kernels. DeepSeek has its own copy of the expert plan, down chains and combine (deepseek_v41/experts_kimi.metal, kernels tf_dsv41_route_plan, tf_dsv41_xp_down_one/_multi, tf_dsv41_xp_combine), with the full-range E8M0 scale in the copy only; git diff main -- zig/kernels/metal/kimi is empty. The stack is rebased on current main (2761c24) with main's shared files changed only by one-line hooks, so later parts add to the family's own files. Receipts for #1705, #1706 and this part are updated in their descriptions.

gilby and others added 2 commits November 1, 2026 08:38
…own and combine

tf_dsv41_xp_up runs the gate/up (fp8 act_quant of the input, clamped SwiGLU, route weight, act_quant of the result)
over Kimi K3's MXFP4 kernels, which DeepSeek V4.1's experts share. Kimi's down chain takes the E8M0 scale as two
normal floats so every scale byte but 255 is exact. Registered with the contract, checked against the release's
real FP4 expert bytes and end to end through the GPU's own plan.
@ashhart
ashhart force-pushed the dsv41-metal-pr/03-mxfp4-experts branch from 61305ae to e51eb97 Compare November 1, 2026 09:57
@ashhart
ashhart merged commit e62ae88 into ashhart:main Nov 1, 2026
9 checks passed
@ashhart

ashhart commented Nov 1, 2026

Copy link
Copy Markdown
Owner

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.

@ashhart

ashhart commented Nov 1, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby! DeepSeek V4.1's MXFP4 expert kernels on Metal, under the kernel contract, are in 1.2.1: https://github.com/ashhart/TensorFold/releases/tag/v1.2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants