Skip to content

dsv41 metal: TF_DSV41_ROUND_PROF times each decode round and the drafter's passes (stacked on #1720) - #2951

Merged
ashhart merged 11 commits into
ashhart:mainfrom
gilby:dsv41-metal-opt/00-round-prof
Nov 24, 2026
Merged

ashhart merged 11 commits into
ashhart:mainfrom
gilby:dsv41-metal-opt/00-round-prof

Conversation

@gilby

@gilby gilby commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

DeepSeek-V4.1 on Metal has no way to see where a decode round's time goes. TF_DSV41_ROUND_PROF=1 (default off, read once at load) times every round: host prepare, encode, wait and choose, each command buffer's span on the GPU clock and the idle time between buffers, and the drafter's ingest, propose and finish, then logs mean, p50 and p95 grouped by slots, rows and drafted or plain. Unset, the target and the pass hold null pointers, no clock is read, and tokens are unchanged. The release-layer timing test (time-dsv41-metal-real) also covers 1 to 16 rows, four slots of one row, five layers, and GB/s per FP8 shape.

Checks on this head

Receipt

  • Main against branch: with the profiler unset this head is level with the stack tip on both chips: M5 Ultra 0.998 to 1.001 (mean over mean, 8 cells), M3 Ultra 0.998 to 1.003 (20 cells, all within noise by the DeepSeek-V4.1 on Metal: decode and prompt speed on M3 Ultra and M5 Ultra, token-exact (gate and order for the drafts) #2984 rule); with TF_DSV41_ROUND_PROF=1 0.997 to 1.004. Receipts: https://gist.github.com/gilby/93abf0522daeab023989979a54d78493 (M5 Ultra) and https://gist.github.com/gilby/b7971860d74a10478600592f099299f8 (M3 Ultra), measured at 3eb04181e; 86050b1ee changes only what the profiler writes at close when nothing was booked.
  • Boxes it reaches: none unless the flag is set.
  • New switch? Default, accepted values, profile row: TF_DSV41_ROUND_PROF, a flag, default off, Metal only, with its row in platform/environment.zig and docs/environment.md.
  • Exactness: token_sha256 equal across every arm of every cell on both chips, profiler on and off, 0 failed and 0 --alone / --serial mismatches.
  • Main against this branch, same machine and checkpoint, posted before asking for a run on our machines: posted in the receipt comments on this PR (links above).
  • Decode speed before and after: bench_openai level on both chips (M3 Ultra 0.999 to 1.001); tables in the receipt comments.
  • Prompt speed before and after: n/a, the prompt path is not touched.
  • Environment: measured at 3eb04181e on dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720's a43ad7b98; deepseek-ai/DeepSeek-V4.1-Flash-1017 release weights at revision 1bae0e1088993b9b82de08f59de5be5a34e42170; M5 Ultra 512 GB and M3 Ultra 512 GB; Zig 0.17.0; tests on an M5 Max.
  • Paths and platforms the change reaches, which I ran and which I could not: Metal only. Ran the synthetic-weight device suites on an M5 Max. Not run: M3, the release weights.
  • Licence of any new weights or drafter: n/a.

Checklist

  • The title and description match the head commit, including the receipt and the stack.
  • 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 in the diff or its commits. No AI attribution lines.
  • 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 (synthetic weights, and on the release weights in the receipts).
  • No precision traded for speed.
  • Decode and prompt processing are no slower than main at one stream and the widest admitted; with --drafter, no slower than without it, greedy and sampled

@gilby
gilby force-pushed the dsv41-metal-opt/00-round-prof branch from 891606d to 1eeb70e Compare November 11, 2026 23:01
@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The profiler is cleanly off by default: the target and the pass hold null pointers, forward.run keeps its 16-buffer cut, and the served test checks replies with the profiler on against the serial reference. Small things:

  1. metal/round_prof.zig:176 panics when allocating a new shape's Group fails. A diagnostic shouldn't be able to stop the server; please skip that round's booking instead, as Series.add already does for its samples.
  2. Percentiles only see the first 32,768 rounds of each shape (max_samples, :14), so a long run's later summaries mix a current mean with early percentiles. Please either reset the series at each 4,096-round summary or say "first 32,768 rounds" in the summary line.
  3. No CI has run on this head: it conflicts with main in CHANGELOG.md, and GitHub starts no run while a PR conflicts. Once dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720 has landed, please rebase onto main so the Linux and Windows builds run.
  4. With the receipt, please post the three profiled summaries you mention (1 stream plain, 1 stream drafted, 4 streams) from the release weights on the M3 Ultra. They are the most useful evidence for where the 3-4 stream gap on dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720 goes.

These five all sit on #1720 and touch the same few fields, so they'll land in this order, each rebased on the one before: #2951 (the profiler, to read the others' receipts), #2950 (opt-in), #2954, #2953 (on #2951, so forward.zig keeps one run), then #2952 (so its table is measured on the final kernels). Against main they only conflict in CHANGELOG.md.

  • Synthena (Ash's Agent)

@gilby

gilby commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. At head 3eb04181e (one new commit on top; not rebased):

  1. A new shape's Group that cannot be allocated now skips that round's booking: group() returns null and add() returns early. A test with a failing allocator checks the round is unbooked and the next one books; it panicked before the fix. While there: the profiler's own init failing now runs the server unprofiled, and a GPU span that is negative, NaN or infinite books as 0 where the conversion could have trapped. I found no other panic on its paths.
  2. Each periodic summary now logs and then resets every count and series, so its mean and percentiles cover the same rounds; the header says which ("rounds A to B (N rounds; mean and percentiles cover these rounds)"), and the summary at close covers the rounds since the last one. A test checks the reset and the header. The sample cap now applies within one window.
  3. Understood; I'll rebase onto main once dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720 has landed so the Linux and Windows builds run. I have not rebased it to follow main in the meantime.
  4. The three profiled summaries from the release weights on the M3 Ultra are queued behind the receipts running there now, and I'll post them here with the M5 Ultra's. One early result from it: the copy windows that cost dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720 its sampled code cell at 4 streams (the table is on dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720).

docs/environment.md now says what the setting does: Metal only, a summary every 4,096 rounds and one at close, a malformed value stops a Metal start, and the CUDA server never reads it. The issue line in the body now points at #2984.

At this head on an M5 Max: round_prof tests 5/5, test-dsv41-metal-all 9/9 steps and 39/39, test-dsv41-env-host passes, lean_check.py 345 on base and head, pr_check.py --pr 2951 0 errors and 0 warnings.

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. Both fixes at 3eb04181e do what we asked:

  1. A new shape's Group that can't be allocated no longer stops anything. group() returns null (metal/round_prof.zig:192-200), add() skips that round (:173), and the failing-allocator test (:318-337) shows the next round books normally. Running unprofiled when the profiler's own init fails (serve.zig:60) and booking a negative or non-finite GPU span as 0 (secondsNs, :20-22) are good additions.
  2. reset() (:203-212) clears every count and series after each periodic summary, and the header says which rounds it covers. A summary's mean and percentiles now describe the same rounds.

The code is ready. What's left:

  1. The release-weights runs you listed, on the M3 Ultra 512 GB and the M5 Ultra 512 GB. First, tools/bench_concurrent.py --alone --serial with the flag unset against the stack tip: equal token_sha256 and speed within noise. Then the three profiled summaries: 1 stream plain, 1 stream drafted and 4 streams.
  2. Once dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720 has landed, a rebase onto main so the Linux and Windows builds run. Against main only CHANGELOG.md conflicts. When dsv41 metal: a multi-stream round's per-slot stages run as one dispatch each (stacked on #1720) #2954 rebases onto this, the two meet on one import line in forward.zig, and its segs.declare call moves into runTimed's loop.

One small thing, not blocking: close() (serve.zig:127) logs a summary even when no round has been booked since the last one. That prints only a header such as "rounds 4097 to 4096 (0 rounds; ...)". Skipping the log when rounds == since would keep it quiet.

This still lands first after #1720. With #2953 closed, the order is #2951, #2950, #2954, #2973, #2983, then #2952, so that #2952's cost table is measured on the final kernels.

  • Synthena (Ash's Agent)

@gilby

gilby commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

M3 Ultra, 512 GB: the series is being re-measured now under the noise rule in #2984 (one discarded first run, base on both sides, both-under-both test); it follows in this thread.

  • Head: 3eb04181e
  • Base: a43ad7b98
  • Checkpoint: deepseek-ai/DeepSeek-V4.1-Flash-1017 release weights as published (pinned revision: not recorded in these runs)
  • Hardware: M5 Ultra, 512 GB; macOS 27.2.1 (26B131); Metal compiler 383.1 (printed by the rotary sweep of this run); the device-test and kernel-contract builds set TOOLCHAINS=com.apple.dt.toolchain.Metal.32023.922.4; the Xcode and Zig versions are not recorded in these logs
  • Tools: tools/bench_concurrent.py --tokens 128 --reps 3 --temperatures 1.0,0 --levels 1,4 --alone --serial for the off / on series; for the profiler summaries --temperatures 0 --levels 1 (1 stream) and --temperatures 0,1 --levels 4 (4 streams), also with --alone --serial; profiler enabled with TF_DSV41_ROUND_PROF=1; --no-drafts where named
  • Server flags: --context 1048576 --parallel 4 --prompt-cache-gib 0 --vision --no-update-check, TF_EXPERIMENTAL=deepseek; one fresh server per cell
  • Arm order (M5 Ultra): profiler off / on series: base, this head with the profiler off, this head with the profiler off, base, this head with TF_DSV41_ROUND_PROF=1; profiler summaries: 1 stream plain, 1 stream drafted, 4 streams --no-drafts, 4 streams default (profiler on, no base arm in that block)

Summary: with the profiler off (the default) this head matches base in every cell of the series: off over base, mean over mean, 0.998 to 1.001; with TF_DSV41_ROUND_PROF=1 it is 0.999 to 1.003 of base. Token hashes are equal across all five arms in every cell, with 0 failed or unequal --alone / --serial comparisons.

Cells under 0.98 of base: none.

Profiler off and on against base (bench_concurrent aggregate tok/s, default drafts)

Order as run: base 1, off 1, off 2, base 2, on. Ratios are over the base run named in the column; on ran last, directly after base 2, so it is shown against base 2 and against the mean of both base runs. Token hashes equal in every cell across the five arms: yes; failed / alone / serial mismatches: 0.

streams T load base 1 off 1 off 2 base 2 on off 1 / base 1 off 2 / base 2 off / base (mean over mean) on / base 2 on / base (mean over mean)
1 0 chat 56.7 56.8 56.8 56.8 56.8 1.002 1.000 1.001 1.000 1.001
4 0 chat 109.2 109.2 109.3 109.2 109.1 1.000 1.001 1.000 0.999 0.999
1 0 code 61.4 61.4 61.4 61.4 61.4 1.000 1.000 1.000 1.000 1.000
4 0 code 114.0 114.0 114.1 114.1 114.0 1.000 1.000 1.000 0.999 1.000
1 1 chat 62.8 62.7 62.8 62.7 62.8 0.998 1.002 1.000 1.002 1.001
4 1 chat 85.3 85.3 85.2 85.3 85.3 1.000 0.999 0.999 1.000 1.000
1 1 code 69.5 69.5 69.5 69.5 69.5 1.000 1.000 1.000 1.000 1.000
4 1 code 84.9 84.9 84.6 85.0 85.2 1.000 0.995 0.998 1.002 1.003

Method as run: each cell is a fresh server started just before it; a thermal-pressure check (powermetrics thermal sampler) ran at the start and the end of every cell, and a cell that was not Nominal at either end was discarded and re-run after a pause. No cell of the off / on series was discarded; all 5 cells were Nominal at both ends. The profiler-summary cells below were also all Nominal at both ends and none was discarded. One-stream --no-drafts control cells on the base tree ran between series (2 of them are relevant here) and read 46.7 / 46.7 tok/s, against a gate of at least 42 tok/s and Nominal thermal pressure. These M5 Ultra series were run before the noise rule in #2984 and have no discarded first run for that purpose; every arm is a fresh server and the order is base, this, this, base wherever a pair is shown.

Per-phase summaries printed by the round profiler at shutdown, quoted verbatim (ms, mean / p50 / p95). [tensorfold] log lines are dropped. The figures in the bullets are read from these blocks. In the 4-stream --no-drafts log a second, 28-round block follows the first at shutdown; only the first block is quoted.

M5 Ultra, 512 GB

M5 Ultra, 1 stream, plain rounds (--no-drafts):

info(dsv41): dsv41 round profile: rounds 1 to 1300 (1300 rounds; mean and percentiles cover these rounds); ms mean/p50/p95
info(dsv41): slots 1 rows 1 plain n 1300: prepare 0.146/0.010/0.689 encode 0.483/0.480/0.496 wait 20.669/20.640/21.066 choose 0.228/0.228/0.233 other 0.000/0.000/0.001 round 21.526/21.467/22.346 commit_done 21.138/21.102/21.536 gpu 20.936/20.908/21.329 gap 0.004/0.003/0.004 seam 2.162/0.002/0.009
info(dsv41): command buffer 0 n 1300: gpu 0.510/0.507/0.548 wall 21.138/21.102/21.536
info(dsv41): command buffer 1 n 1300: gpu 5.093/5.084/5.225 wall 21.016/20.982/21.412
info(dsv41): command buffer 2 n 1300: gpu 5.032/5.018/5.137 wall 20.894/20.861/21.291
info(dsv41): command buffer 3 n 1300: gpu 4.717/4.718/4.803 wall 20.777/20.747/21.174
info(dsv41): command buffer 4 n 1300: gpu 5.584/5.584/5.664 wall 20.670/20.641/21.068

M5 Ultra, 1 stream, drafted (default):

info(dsv41): dsv41 round profile: rounds 1 to 687 (687 rounds; mean and percentiles cover these rounds); ms mean/p50/p95
info(dsv41): slots 1 rows 1 plain n 254: prepare 0.011/0.010/0.016 encode 0.481/0.479/0.492 wait 20.680/20.652/21.056 choose 0.231/0.229/0.242 other 0.000/0.000/0.001 round 21.403/21.379/21.776 commit_done 21.147/21.114/21.523 gpu 20.946/20.915/21.321 gap 0.004/0.003/0.016 seam 2.023/0.002/0.009
info(dsv41): slots 1 rows 2 drafted n 76: prepare 0.363/0.019/1.155 encode 0.539/0.513/0.606 wait 27.185/27.197/27.634 choose 0.432/0.430/0.443 other 0.000/0.000/0.001 round 28.520/28.342/29.589 commit_done 27.707/27.699/28.125 gpu 27.480/27.492/27.834 gap 0.004/0.003/0.019 seam 34.042/4.892/294.934
info(dsv41): slots 1 rows 3-4 drafted n 278: prepare 0.431/0.033/1.674 encode 0.509/0.503/0.548 wait 34.287/33.572/37.737 choose 0.707/0.638/0.831 other 0.000/0.000/0.001 round 35.935/35.347/39.791 commit_done 34.781/34.064/38.232 gpu 34.564/33.860/38.041 gap 0.004/0.003/0.019 seam 5.615/4.886/5.045
info(dsv41): slots 1 rows 5-8 drafted n 79: prepare 0.887/0.052/4.870 encode 0.511/0.506/0.577 wait 44.996/43.296/49.110 choose 1.138/1.055/1.263 other 0.000/0.000/0.001 round 47.533/48.378/54.471 commit_done 45.492/43.783/49.632 gpu 45.217/43.567/49.351 gap 0.004/0.003/0.019 seam 4.896/4.880/5.125
info(dsv41): command buffer 0 n 687: gpu 0.750/0.772/1.213 wall 30.189/31.928/47.130
info(dsv41): command buffer 1 n 687: gpu 7.335/7.695/11.465 wall 30.062/31.794/47.001
info(dsv41): command buffer 2 n 687: gpu 7.305/7.740/11.535 wall 29.935/31.665/46.865
info(dsv41): command buffer 3 n 687: gpu 6.861/7.106/11.107 wall 29.815/31.544/46.749
info(dsv41): command buffer 4 n 687: gpu 7.719/8.080/11.655 wall 29.703/31.432/46.638
info(dsv41): drafter n 441: ingest_wall 0.710/0.405/0.668
info(dsv41): drafter n 441: ingest_gpu 0.257/0.214/0.404
info(dsv41): drafter n 433: propose_wall 4.069/4.065/4.201
info(dsv41): drafter n 433: propose_gpu 3.816/3.821/3.914
info(dsv41): drafter n 433: finish 0.395/0.401/0.432

M5 Ultra, 4 streams, --no-drafts:

info(dsv41): dsv41 round profile: rounds 1 to 4096 (4096 rounds; mean and percentiles cover these rounds); ms mean/p50/p95
info(dsv41): slots 1 rows 1 plain n 2600: prepare 0.296/0.011/0.735 encode 0.486/0.482/0.508 wait 20.737/20.717/21.143 choose 0.361/0.392/0.414 other 0.000/0.000/0.001 round 21.881/21.823/22.715 commit_done 21.208/21.183/21.610 gpu 20.995/20.973/21.392 gap 0.004/0.004/0.004 seam 2.253/0.002/0.010
info(dsv41): slots 4 rows 3-4 plain n 1496: prepare 0.033/0.034/0.040 encode 0.603/0.599/0.623 wait 33.721/29.070/40.059 choose 1.111/0.830/1.456 other 0.000/0.000/0.001 round 35.469/30.509/42.129 commit_done 34.306/29.650/40.648 gpu 34.091/29.435/40.425 gap 0.005/0.004/0.021 seam 7.787/0.009/0.019
info(dsv41): command buffer 0 n 4096: gpu 0.620/0.542/0.970 wall 25.992/21.481/40.273
info(dsv41): command buffer 1 n 4096: gpu 6.317/5.199/9.942 wall 25.857/21.357/40.116
info(dsv41): command buffer 2 n 4096: gpu 6.279/5.113/9.894 wall 25.724/21.235/39.963
info(dsv41): command buffer 3 n 4096: gpu 5.878/4.781/9.368 wall 25.598/21.118/39.822
info(dsv41): command buffer 4 n 4096: gpu 6.684/5.639/9.996 wall 25.481/21.014/39.686

M5 Ultra, 4 streams, default:

info(dsv41): dsv41 round profile: rounds 1 to 3327 (3327 rounds; mean and percentiles cover these rounds); ms mean/p50/p95
info(dsv41): slots 1 rows 1 plain n 1274: prepare 0.012/0.011/0.016 encode 0.487/0.481/0.522 wait 20.739/20.723/21.127 choose 0.362/0.391/0.416 other 0.000/0.000/0.001 round 21.600/21.583/22.007 commit_done 21.212/21.197/21.592 gpu 21.006/20.991/21.386 gap 0.004/0.004/0.004 seam 2.252/0.002/0.011
info(dsv41): slots 1 rows 2 drafted n 106: prepare 1.034/0.954/3.346 encode 0.547/0.525/0.602 wait 27.261/27.276/27.951 choose 0.690/0.753/0.783 other 0.000/0.000/0.001 round 29.532/29.383/32.283 commit_done 27.790/27.782/28.455 gpu 27.535/27.546/28.126 gap 0.004/0.004/0.004 seam 35.116/4.895/272.419
info(dsv41): slots 1 rows 3-4 drafted n 319: prepare 1.357/1.331/3.462 encode 0.526/0.518/0.578 wait 34.398/33.517/38.007 choose 1.123/1.105/1.474 other 0.000/0.000/0.001 round 37.405/36.365/42.009 commit_done 34.908/34.016/38.506 gpu 34.656/33.758/38.127 gap 0.005/0.004/0.020 seam 5.515/4.853/5.067
info(dsv41): slots 1 rows 5-8 drafted n 111: prepare 2.341/2.020/5.040 encode 0.523/0.516/0.571 wait 45.290/44.146/49.756 choose 1.788/1.804/2.155 other 0.000/0.000/0.001 round 49.941/50.194/56.569 commit_done 45.796/44.725/50.256 gpu 45.398/44.145/49.592 gap 0.005/0.004/0.020 seam 4.909/4.891/5.148
info(dsv41): slots 1 rows 9-16 drafted n 8: prepare 0.139/0.132/0.163 encode 0.504/0.505/0.515 wait 100.940/100.531/101.888 choose 5.702/5.705/5.784 other 0.000/0.000/0.002 round 107.285/106.870/108.227 commit_done 101.429/101.009/102.384 gpu 101.207/100.798/102.174 gap 0.007/0.004/0.024 seam 1.267/0.001/5.255
info(dsv41): slots 2 rows 2 plain n 6: prepare 0.025/0.019/0.038 encode 0.608/0.551/0.727 wait 28.414/27.952/29.465 choose 0.762/0.756/0.773 other 0.000/0.000/0.000 round 29.808/29.278/30.963 commit_done 29.000/28.485/30.147 gpu 28.428/28.260/28.872 gap 0.007/0.004/0.022 seam 0.018/0.010/0.033
info(dsv41): slots 2 rows 9-16 drafted n 3: prepare 0.126/0.126/0.127 encode 0.586/0.587/0.589 wait 84.212/84.223/84.273 choose 4.318/4.311/4.332 other 0.000/0.000/0.001 round 89.242/89.244/89.298 commit_done 84.775/84.783/84.840 gpu 84.555/84.578/84.615 gap 0.015/0.019/0.023 seam 70.446/70.583/70.600
info(dsv41): slots 3 rows 3-4 plain n 27: prepare 0.032/0.032/0.035 encode 0.578/0.569/0.596 wait 34.741/34.785/34.983 choose 1.090/1.091/1.106 other 0.000/0.000/0.001 round 36.441/36.465/36.741 commit_done 35.302/35.334/35.599 gpu 35.055/35.084/35.319 gap 0.005/0.004/0.004 seam 0.012/0.009/0.033
info(dsv41): slots 4 rows 3-4 plain n 1473: prepare 0.036/0.034/0.045 encode 0.601/0.594/0.634 wait 33.637/29.104/39.917 choose 1.110/0.829/1.461 other 0.000/0.000/0.001 round 35.385/30.539/42.006 commit_done 34.220/29.676/40.506 gpu 34.000/29.466/40.284 gap 0.008/0.004/0.021 seam 8.335/0.010/0.024
info(dsv41): command buffer 0 n 3327: gpu 0.709/0.637/1.025 wall 29.693/29.426/40.664
info(dsv41): command buffer 1 n 3327: gpu 7.221/7.147/10.069 wall 29.553/29.274/40.511
info(dsv41): command buffer 2 n 3327: gpu 7.217/7.265/10.067 wall 29.416/29.124/40.361
info(dsv41): command buffer 3 n 3327: gpu 6.768/6.711/9.533 wall 29.287/28.985/40.219
info(dsv41): command buffer 4 n 3327: gpu 7.554/7.444/10.101 wall 29.165/28.855/40.083
info(dsv41): drafter n 687: ingest_wall 1.897/0.422/1.601
info(dsv41): drafter n 687: ingest_gpu 0.424/0.227/1.325
info(dsv41): drafter n 566: propose_wall 4.070/4.043/4.209
info(dsv41): drafter n 566: propose_gpu 3.822/3.805/3.925
info(dsv41): drafter n 566: finish 0.390/0.385/0.430

What the blocks show:

  • 1 stream plain (1300 rounds): round 21.526 ms, of which wait 20.669 ms (96.0%) and gpu 20.936 ms (97.3%); encode 0.483, choose 0.228, prepare 0.146 ms.
  • 1 stream drafted: round 28.520 ms at 2 rows (n 76), 35.935 ms at 3-4 rows (n 278), 47.533 ms at 5-8 rows (n 79); wait is 95.4% of the round at 3-4 rows. Drafter per round: propose_wall 4.069 ms, ingest_wall 0.710 ms (p50 0.405), finish 0.395 ms.
  • 4 streams --no-drafts (1496 rounds at 4 slots): round 35.469 ms, wait 33.721 ms (95.1%), gpu 34.091 ms; p50 round 30.509 ms against p95 42.129 ms.
  • 4 streams default: 1473 of the 3327 rounds summarised ran at 4 slots as plain rounds: round 35.385 ms, wait 33.637 ms (95.1%). Drafted rounds appear only with fewer streams active (largest: 107.285 ms at 9-16 rows, n 8). Drafter: propose_wall 4.070 ms, ingest_wall 1.897 ms (p50 0.422, p95 1.601), finish 0.390 ms.
  • Rows at 1 slot in the 4-stream blocks come from warm-up requests and the --alone and --serial passes.

Not run: a profiler off / on pair for the 2- and 3-stream cells; the profiler summaries on a base arm (base has no profiler); the checkpoint's pinned revision is not recorded.

Raw JSON, server logs and driver scripts: https://gist.github.com/gilby/93abf0522daeab023989979a54d78493

@ashhart

ashhart commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby for the M5 Ultra receipt. With the profiler off, this head is 0.998 to 1.001 of base (mean over mean). With TF_DSV41_ROUND_PROF=1 it is 0.999 to 1.003. Every token hash is equal, with 0 --alone or --serial mismatches. On the M5 Ultra that meets the bar for a diagnostic that's off by default.

These series came before the discarded first run in #2984's noise rule. Base ran first, so any first-run lift favours base, not this branch. We'll take the M5 Ultra numbers as they are, with no need to rerun them.

The summaries are already useful. At four plain streams a round takes 35.5 ms, and 95% of that is waiting on the GPU. Prepare, encode and choose add up to under 2 ms. So the multi-stream time is GPU work, which is where #2954 and #2973 aim.

What's left:

  1. The M3 Ultra series under the noise rule, with the same profiled summaries.
  2. Once dsv41 metal: the lane target, the prompt cache and the native server over Metal #1720 lands, a rebase onto main so the Linux and Windows builds run.

The empty summary at close() (serve.zig:127) is still optional. After that, this lands first in the stack.

  • Synthena (Ash's Agent)

@gilby

gilby commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

M3 Ultra, 512 GB: the receipt promised above, run on 2026-11-13 under the noise rule in #2984 (one discarded first run per series, base on both sides, both-under-both test).

  • Head: 3eb04181e
  • Base: a43ad7b98
  • Checkpoint: deepseek-ai/DeepSeek-V4.1-Flash-1017 release weights as published, read from local disk (pinned revision: not recorded in these runs)
  • Hardware: M3 Ultra, 512 GB; the macOS version, Metal compiler, Xcode and Zig versions are not recorded in these logs
  • Tools, from the base tree in every arm: tools/bench_concurrent.py --tokens 128 --reps 3 --alone --serial at 1, 2, 3 and 4 streams, temperature 0 and 1; tools/bench_openai.py --tokens 256 --reps 3 at temperature 0 and 1
  • Server flags: --context 1048576 --parallel 4 --prompt-cache-gib 0 --vision --no-update-check, TF_EXPERIMENTAL=deepseek; one fresh server per cell; every TENSORFOLD_PREFILL_* and TF_DSV41_* setting is unset unless the row names it
  • Arm order, per series: one discarded run (base), base, this, this, base; a cell starts only at Nominal thermal pressure after a 60 s settle and its end level is recorded; a cell that ends at Heavy is discarded and retried once, and if it ends at Heavy again it is kept and flagged
  • Server binaries (sha256 prefix): base 0a5638a8e95e, this f01bd6b3beed

Summary: with the profiler unset (the default) this head is level with base on this chip: aggregate decode this over base, mean over mean, is 0.998 to 1.003 in all 20 cells (16 bench_concurrent cells 0.998 to 1.003, 4 bench_openai cells 0.999 to 1.001; single-run ratios 0.996 to 1.007), every cell within noise by the #2984 rule, none faster and none slower. With TF_DSV41_ROUND_PROF=1 the two profiler servers read 0.997 to 1.004 of the profiler-off runs of the same cell; those two servers are single runs, not a bracketed series, so that comparison is information only. Token hashes are equal in every cell, including the profiler-on servers.

Cells under 0.98 of base: none.

Profiler unset against base: aggregate tok/s (bench_concurrent) and decode tok/s (bench_openai, median of 3 requests)

Order as run: base 1, this 1, this 2, base 2. Ratios: this 1 over base 1, this 2 over base 2, and mean over mean. Verdict by the #2984 rule: slower only if both this runs are under both base runs and the mean gap is over 1%, faster the mirror image, otherwise within noise. Verdicts: 0 faster, 0 slower, 20 within noise, out of 20 cells. bench_openai rows are 1 stream and are listed with the bench_concurrent rows (the load column names the prompt).

streams T load base 1 this 1 this 2 base 2 this 1 / base 1 this 2 / base 2 this / base (mean over mean) verdict end level (b1 / t1 / t2 / b2)
1 0 chat 43.7 44.0 43.7 43.8 1.007 0.998 1.002 within noise Nom/Nom/Nom/Nom
1 0 code 47.1 47.1 47.0 47.1 1.000 0.998 0.999 within noise Nom/Nom/Nom/Nom
1 1 chat 47.8 47.8 47.8 47.8 1.000 1.000 1.000 within noise Nom/Nom/Nom/Nom
1 1 code 52.1 52.2 52.1 52.1 1.002 1.000 1.001 within noise Nom/Nom/Nom/Nom
2 0 chat 55.8 55.8 55.8 55.9 1.000 0.998 0.999 within noise Nom/Nom/Nom/Nom
2 0 code 59.7 59.6 59.6 59.7 0.998 0.998 0.998 within noise Nom/Nom/Nom/Nom
2 1 chat 50.8 50.7 50.9 50.8 0.998 1.002 1.000 within noise Mod/Mod/Nom/Mod
2 1 code 49.1 49.0 49.1 49.0 0.998 1.002 1.000 within noise Mod/Mod/Nom/Mod
3 0 chat 68.8 68.8 68.9 68.6 1.000 1.004 1.002 within noise Nom/Nom/Nom/Nom
3 0 code 72.3 72.3 72.4 72.3 1.000 1.001 1.001 within noise Nom/Nom/Nom/Nom
3 1 chat 55.8 55.8 55.6 55.8 1.000 0.996 0.998 within noise Mod/Mod/Mod/Mod
3 1 code 56.6 56.6 56.5 56.6 1.000 0.998 0.999 within noise Mod/Mod/Mod/Mod
4 0 chat 78.6 78.4 78.6 78.2 0.997 1.005 1.001 within noise Nom/Nom/Mod/Mod
4 0 code 84.2 84.1 84.0 84.1 0.999 0.999 0.999 within noise Nom/Nom/Mod/Mod
4 1 chat 61.7 61.6 61.6 61.7 0.998 0.998 0.998 within noise Mod/Mod/Mod/Mod
4 1 code 62.3 62.5 62.5 62.3 1.003 1.003 1.003 within noise Mod/Mod/Mod/Mod
1 0 fibonacci-raw 54.5 54.5 54.4 54.4 1.000 1.000 1.000 within noise Nom/Nom/Nom/Nom
1 0 gpu-chat-no-think 43.8 43.9 43.8 43.7 1.001 1.001 1.001 within noise Nom/Nom/Nom/Nom
1 1 fibonacci-raw 49.8 49.9 49.8 49.9 1.001 0.999 1.000 within noise Mod/Nom/Mod/Nom
1 1 gpu-chat-no-think 43.6 43.6 43.8 43.8 0.999 0.999 0.999 within noise Mod/Nom/Mod/Nom

End level key: Nom = Nominal, Mod = Moderate, Heavy = Heavy, * = ended at Heavy twice, kept and flagged.

Exactness: token hashes are equal across all four runs in every one of the 20 cells (all reps of each cell compared), with 0 failed requests and 0 --alone / --serial mismatches. Checked against the raw JSON: hash equality over the four runs of each cell, and the failed, alone and serial counts over every run including the discarded ones.

Profiler on (TF_DSV41_ROUND_PROF=1), information only

Two single servers on this head with the profiler enabled, run after the bracketed series: one at 1 stream (temperatures 0 and 1, --alone --serial) and one at 4 streams (same). Aggregate tok/s against the mean of the four profiler-off runs of the same cell (base 1, base 2, this 1, this 2) and against the mean of the two base runs. These are single runs, not a bracketed series, so no verdict is given.

streams T load profiler on mean of the 4 off runs on / off mean on / base mean end level
1 0 chat 43.7 43.8 0.998 0.999 Moderate
1 0 code 47.1 47.1 1.001 1.000 Moderate
1 1 chat 47.7 47.8 0.998 0.998 Moderate
1 1 code 52.1 52.1 1.000 1.000 Moderate
4 0 chat 78.8 78.5 1.004 1.005 Moderate
4 0 code 84.1 84.1 1.000 0.999 Moderate
4 1 chat 61.7 61.7 1.001 1.000 Moderate
4 1 code 62.2 62.4 0.997 0.998 Moderate

Token hashes of the profiler-on servers equal those of the off runs in all 8 cells, 0 failed or unequal comparisons. Two of the lines the profiler prints at shutdown, verbatim (ms, mean / p50 / p95; the 1-stream server and the 4-stream server):

info(dsv41): slots 1 rows 1 plain n 508: prepare 0.014/0.013/0.019 encode 0.503/0.501/0.517 wait 27.448/27.461/27.827 choose 0.313/0.193/0.465 other 0.000/0.000/0.001 round 28.278/28.313/28.764 commit_done 27.938/27.951/28.308 gpu 27.680/27.691/28.050 gap 0.009/0.008/0.015 seam 3.508/0.002/0.012
info(dsv41): slots 2 rows 2 plain n 6: prepare 0.026/0.023/0.034 encode 0.643/0.585/0.760 wait 37.262/36.970/38.267 choose 0.868/0.864/0.886 other 0.000/0.000/0.002 round 38.799/38.451/39.925 commit_done 37.880/37.551/38.986 gpu 37.316/37.229/37.792 gap 0.008/0.006/0.014 seam 0.027/0.011/0.060

Discarded, retried and flagged cells

  • The first run of every series is the discarded run and is in no table; the nine discarded runs (one per series) ended at: c-c1 Nominal, c-c2t0 Nominal, c-c2t1 Moderate, c-c3t0 Moderate, c-c3t1 Moderate, c-c4t0 Nominal, c-c4t1 Moderate, c-oai0 Nominal, c-oai1 Nominal. None of them ended at Heavy.
  • The 4-stream profiler-on server (c-on4) ended at Heavy on its first try, was discarded and re-run once after cooling; the second try ended at Moderate and is the one above. The first try's raw files are in the gist as .try1 files.
  • No cell of the bracketed series ended at Heavy, so none was retried and none is flagged. Kept cells that ended above Nominal are the ones marked Mod in the table; in every series base and this agree within the table's ratios, and the profiler-on 1-stream server ended at Moderate.

Method as run: each cell is a fresh server started after the previous one was stopped and a 60 s settle, and a cell starts only when the powermetrics thermal sampler reports Nominal (the driver polls every 30 s); the level is recorded again at the end of the cell. One run per series is discarded and not in any table, base is on both sides, and the series are per stream count and temperature (bench_concurrent: 1 and 2 streams in one series, 3 and 4 in another where noted) and per temperature (bench_openai). A 2-minute multi-stream cell that starts at Nominal usually ends at Moderate on this machine, so Moderate does not discard a cell; only an end at Heavy does: the cell is then discarded, cooled to Nominal and re-run once, and if it ends at Heavy again it is kept and flagged. Tools and server flags are the ones in the header. Every arm, the raw JSON, the server logs and the driver scripts are in the gist.

Not run: a repeat of the profiler-on servers as a bracketed series; the checkpoint's pinned revision, the macOS version and the toolchain versions are not recorded; kernel-contract runs are not part of this series' data.

Raw JSON, server logs and driver scripts: https://gist.github.com/gilby/b7971860d74a10478600592f099299f8

@gilby

gilby commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

New head: 86050b1ee (one commit on top of 3eb04181e, not rebased).

86050b1ee: the optional point from your 12 Nov note. write returns at once when no round was booked since the last summary, so the summary at close after a periodic one no longer prints a bare header such as "rounds 4097 to 4096 (0 rounds; ...)". A new test writes a fresh profile (nothing) and a profile after one round (its header); it found 104 bytes before the change. It changes only what the profiler writes when nothing was booked, and nothing at all with TF_DSV41_ROUND_PROF unset, so the M5 Ultra and M3 Ultra receipts posted above (taken at 3eb04181e) still describe the served code.

Your asks:

  1. (12 Nov 13:18 and 23:50) The M3 Ultra series under the DeepSeek-V4.1 on Metal: decode and prompt speed on M3 Ultra and M5 Ultra, token-exact (gate and order for the drafts) #2984 rule: posted on 13 Nov (20 cells, all within noise, every token hash equal). The profiled summaries from that run, quoted in full below from the two profiler servers' logs (release weights, M3 Ultra 512 GB, head 3eb04181e):

M3 Ultra, 1 stream, default drafts:

info(dsv41): dsv41 round profile: rounds 1 to 1305 (1305 rounds; mean and percentiles cover these rounds); ms mean/p50/p95
info(dsv41): slots 1 rows 1 plain n 508: prepare 0.014/0.013/0.019 encode 0.503/0.501/0.517 wait 27.448/27.461/27.827 choose 0.313/0.193/0.465 other 0.000/0.000/0.001 round 28.278/28.313/28.764 commit_done 27.938/27.951/28.308 gpu 27.680/27.691/28.050 gap 0.009/0.008/0.015 seam 3.508/0.002/0.012
info(dsv41): slots 1 rows 2 drafted n 129: prepare 0.342/0.024/1.729 encode 0.562/0.542/0.635 wait 36.554/36.571/37.097 choose 0.495/0.244/0.889 other 0.000/0.000/0.001 round 37.954/37.834/39.509 commit_done 37.099/37.123/37.614 gpu 36.822/36.866/37.242 gap 0.007/0.007/0.011 seam 73.126/6.506/508.058
info(dsv41): slots 1 rows 3-4 drafted n 470: prepare 0.396/0.040/1.860 encode 0.533/0.531/0.558 wait 44.781/43.432/49.439 choose 0.788/0.371/1.718 other 0.000/0.000/0.001 round 46.498/45.289/51.807 commit_done 45.299/43.949/49.945 gpu 45.035/43.702/49.697 gap 0.007/0.007/0.008 seam 6.453/6.445/6.715
info(dsv41): slots 1 rows 5-8 drafted n 198: prepare 0.526/0.064/2.238 encode 0.527/0.528/0.547 wait 61.505/64.137/67.252 choose 1.633/2.123/2.560 other 0.000/0.000/0.001 round 64.192/65.969/71.479 commit_done 62.017/64.654/67.773 gpu 61.754/64.345/67.519 gap 0.007/0.007/0.011 seam 6.558/6.548/6.861
info(dsv41): command buffer 0 n 1305: gpu 0.937/0.969/1.641 wall 40.267/41.562/66.358
info(dsv41): command buffer 1 n 1305: gpu 9.683/9.931/15.874 wall 40.139/41.433/66.224
info(dsv41): command buffer 2 n 1305: gpu 9.765/10.041/16.175 wall 40.006/41.298/66.090
info(dsv41): command buffer 3 n 1305: gpu 9.206/9.275/15.551 wall 39.878/41.163/65.965
info(dsv41): command buffer 4 n 1305: gpu 10.413/10.501/16.411 wall 39.759/41.043/65.845
info(dsv41): drafter n 813: ingest_wall 1.002/0.598/0.941
info(dsv41): drafter n 813: ingest_gpu 0.413/0.328/0.622
info(dsv41): drafter n 797: propose_wall 5.378/5.373/5.517
info(dsv41): drafter n 797: propose_gpu 5.079/5.076/5.212
info(dsv41): drafter n 797: finish 0.469/0.469/0.490

M3 Ultra, 4 streams, default drafts:

info(dsv41): dsv41 round profile: rounds 1 to 3328 (3328 rounds; mean and percentiles cover these rounds); ms mean/p50/p95
info(dsv41): slots 1 rows 1 plain n 1274: prepare 0.014/0.013/0.019 encode 0.504/0.501/0.524 wait 27.433/27.443/27.807 choose 0.384/0.453/0.467 other 0.001/0.001/0.001 round 28.335/28.361/28.768 commit_done 27.923/27.931/28.289 gpu 27.668/27.679/28.037 gap 0.008/0.007/0.013 seam 3.749/0.003/0.011
info(dsv41): slots 1 rows 2 drafted n 108: prepare 0.937/0.772/2.061 encode 0.570/0.550/0.641 wait 36.492/36.529/37.004 choose 0.722/0.870/0.889 other 0.001/0.001/0.002 round 38.722/38.667/40.218 commit_done 37.044/37.082/37.522 gpu 36.767/36.824/37.244 gap 0.007/0.006/0.010 seam 60.536/6.452/469.412
info(dsv41): slots 1 rows 3-4 drafted n 316: prepare 1.293/1.141/2.898 encode 0.539/0.537/0.574 wait 44.708/43.196/49.547 choose 1.175/1.291/1.722 other 0.001/0.001/0.001 round 47.715/46.263/53.736 commit_done 45.231/43.717/50.171 gpu 44.953/43.415/49.822 gap 0.006/0.006/0.007 seam 6.427/6.395/6.714
info(dsv41): slots 1 rows 5-8 drafted n 113: prepare 1.557/1.735/2.566 encode 0.528/0.530/0.557 wait 61.104/58.738/67.292 choose 1.958/2.139/2.560 other 0.001/0.001/0.002 round 65.148/62.696/72.300 commit_done 61.617/59.252/67.778 gpu 61.350/59.006/67.505 gap 0.006/0.006/0.010 seam 6.517/6.500/6.826
info(dsv41): slots 1 rows 9-16 drafted n 8: prepare 0.146/0.142/0.158 encode 0.516/0.518/0.520 wait 144.253/143.445/145.478 choose 7.011/7.041/7.121 other 0.001/0.001/0.001 round 151.927/151.084/153.194 commit_done 144.755/143.941/145.978 gpu 144.495/143.687/145.719 gap 0.007/0.007/0.007 seam 1.651/0.001/6.955
info(dsv41): slots 2 rows 2 plain n 6: prepare 0.026/0.023/0.034 encode 0.643/0.585/0.760 wait 37.262/36.970/38.267 choose 0.868/0.864/0.886 other 0.000/0.000/0.002 round 38.799/38.451/39.925 commit_done 37.880/37.551/38.986 gpu 37.316/37.229/37.792 gap 0.008/0.006/0.014 seam 0.027/0.011/0.060
info(dsv41): slots 2 rows 9-16 drafted n 3: prepare 0.147/0.148/0.149 encode 0.621/0.619/0.625 wait 118.145/118.171/118.253 choose 5.205/5.187/5.256 other 0.001/0.000/0.003 round 124.119/124.194/124.196 commit_done 118.741/118.767/118.853 gpu 118.470/118.517/118.534 gap 0.007/0.007/0.007 seam 98.948/98.681/99.572
info(dsv41): slots 3 rows 3-4 plain n 27: prepare 0.036/0.036/0.038 encode 0.611/0.611/0.620 wait 45.314/45.394/45.717 choose 1.285/1.283/1.301 other 0.001/0.001/0.001 round 47.246/47.331/47.635 commit_done 45.906/45.981/46.312 gpu 45.640/45.715/46.055 gap 0.008/0.006/0.011 seam 0.012/0.009/0.023
info(dsv41): slots 4 rows 3-4 plain n 1473: prepare 0.042/0.042/0.052 encode 0.630/0.624/0.657 wait 44.791/38.838/53.019 choose 1.004/0.346/1.821 other 0.000/0.000/0.001 round 46.468/39.817/55.432 commit_done 45.403/39.439/53.627 gpu 45.008/39.164/53.286 gap 0.127/0.006/0.007 seam 14.152/0.012/0.025
info(dsv41): command buffer 0 n 3328: gpu 0.873/0.810/1.273 wall 39.270/39.009/53.830
info(dsv41): command buffer 1 n 3328: gpu 9.424/9.378/13.130 wall 39.128/38.845/53.666
info(dsv41): command buffer 2 n 3328: gpu 9.547/9.594/13.354 wall 38.984/38.688/53.508
info(dsv41): command buffer 3 n 3328: gpu 8.987/8.960/12.674 wall 38.847/38.543/53.365
info(dsv41): command buffer 4 n 3328: gpu 10.118/10.003/13.518 wall 38.720/38.404/53.228
info(dsv41): drafter n 688: ingest_wall 2.589/0.655/2.287
info(dsv41): drafter n 688: ingest_gpu 0.630/0.373/1.939
info(dsv41): drafter n 567: propose_wall 5.388/5.352/5.542
info(dsv41): drafter n 567: propose_gpu 5.093/5.073/5.222
info(dsv41): drafter n 567: finish 0.467/0.465/0.490

What these show on the M3 Ultra: one plain row takes 28.3 ms a round, of which 27.4 ms is waiting on the GPU; drafted rounds take 38.0 ms at 2 rows, 46.5 ms at 3-4 and 64.2 ms at 5-8; at four slots a plain round of 3-4 rows takes 46.5 ms with 44.8 ms of wait, and prepare, encode and choose stay under 2 ms. As on the M5 Ultra, the multi-stream time is GPU work.

Still owed: the 1 stream plain summary (--no-drafts) on the M3 Ultra. That run was not part of the series; it is one short server and I'll post its block here.

  1. (12 Nov 13:18 and 23:50) The rebase onto main: I am not pushing a rebase of a branch under review to follow main, so this head stays on a43ad7b98 and is ready to be rebased at landing in the DeepSeek-V4.1 on Metal: decode and prompt speed on M3 Ultra and M5 Ultra, token-exact (gate and order for the drafts) #2984 order. A local rebase onto today's main conflicts only in CHANGELOG.md, and every commit is = outside it in git range-diff.

At 86050b1ee on an M5 Max: test-dsv41-metal-all 9/9 steps and 39/39 tests; zig build test passes apart from dashboard_test, which fails the same way on this base and is fixed on main by #2946; lean_check.py 345 on base and head; pr_check.py --pr 2951 0 errors and 0 warnings.

@gilby

gilby commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

M3 Ultra, 512 GB: the profile summaries with TF_DSV41_ROUND_PROF=1 --no-drafts that the earlier comment said were still owed, at head 86050b1ee.

  • Checkpoint: deepseek-ai/DeepSeek-V4.1-Flash-1017 revision 1bae0e1088993b9b82de08f59de5be5a34e42170, release weights as published, read from local disk
  • Hardware: M3 Ultra, 512 GB
  • Server flags: --context 1048576 --parallel 4 --prompt-cache-gib 0 --vision --no-update-check, TF_EXPERIMENTAL=deepseek, one fresh server per cell
  • Thermal: a cell starts at Nominal pressure after a 60 s settle and the end level is recorded
  • Head: 86050b1ee (server binary sha256 prefix 05eaca15bfe0)
  • Tool: tools/bench_concurrent.py --tokens 128 --reps 3 --temperatures 0,1 --levels L --alone --serial for L = 1 and L = 4, one fresh server each, TF_DSV41_ROUND_PROF=1, --no-drafts (the startup line says "DSpark off"); both servers ended at Nominal and neither was retried; token hashes equal and 0 failed, 0 unequal in every cell of both runs

1 stream, plain rounds. The summary the server printed at shutdown, verbatim (ms, mean / p50 / p95; one block, rounds 1 to 2600):

info(dsv41): dsv41 round profile: rounds 1 to 2600 (2600 rounds; mean and percentiles cover these rounds); ms mean/p50/p95
info(dsv41): slots 1 rows 1 plain n 2600: prepare 0.162/0.012/0.834 encode 0.506/0.504/0.522 wait 27.460/27.460/27.810 choose 0.278/0.175/0.464 other 0.001/0.001/0.001 round 28.406/28.361/29.195 commit_done 27.952/27.949/28.298 gpu 27.700/27.699/28.049 gap 0.007/0.007/0.013 seam 3.850/0.002/0.010
info(dsv41): command buffer 0 n 2600: gpu 0.592/0.593/0.610 wall 27.952/27.949/28.298
info(dsv41): command buffer 1 n 2600: gpu 6.635/6.630/6.744 wall 27.833/27.831/28.178
info(dsv41): command buffer 2 n 2600: gpu 6.677/6.675/6.771 wall 27.705/27.703/28.050
info(dsv41): command buffer 3 n 2600: gpu 6.270/6.275/6.347 wall 27.577/27.577/27.927
info(dsv41): command buffer 4 n 2600: gpu 7.525/7.531/7.596 wall 27.461/27.462/27.811

4 streams. The periodic summary covering rounds 1 to 4096, verbatim:

info(dsv41): dsv41 round profile: rounds 1 to 4096 (4096 rounds; mean and percentiles cover these rounds); ms mean/p50/p95
info(dsv41): slots 1 rows 1 plain n 2600: prepare 0.317/0.013/0.878 encode 0.501/0.499/0.519 wait 27.466/27.470/27.823 choose 0.402/0.478/0.491 other 0.000/0.000/0.001 round 28.686/28.615/29.509 commit_done 27.953/27.957/28.309 gpu 27.694/27.699/28.052 gap 0.008/0.007/0.014 seam 3.883/0.003/0.011
info(dsv41): slots 4 rows 3-4 plain n 1496: prepare 0.039/0.040/0.046 encode 0.627/0.625/0.641 wait 44.935/38.884/53.091 choose 1.038/0.373/1.835 other 0.000/0.000/0.001 round 46.639/39.888/55.546 commit_done 45.543/39.488/53.696 gpu 45.168/39.185/53.393 gap 0.094/0.006/0.007 seam 13.372/0.010/0.020
info(dsv41): command buffer 0 n 4096: gpu 0.743/0.606/1.234 wall 34.377/28.174/53.173
info(dsv41): command buffer 1 n 4096: gpu 8.220/6.696/12.933 wall 34.241/28.053/53.012
info(dsv41): command buffer 2 n 4096: gpu 8.317/6.726/13.070 wall 34.102/27.926/52.854
info(dsv41): command buffer 3 n 4096: gpu 7.816/6.321/12.422 wall 33.970/27.806/52.708
info(dsv41): command buffer 4 n 4096: gpu 8.981/7.568/13.342 wall 33.847/27.692/52.570

The shutdown block of this server covers only the last 28 rounds (rounds 4097 to 4124), because the summary at 4096 rounds had already been printed; verbatim:

info(dsv41): dsv41 round profile: rounds 4097 to 4124 (28 rounds; mean and percentiles cover these rounds); ms mean/p50/p95
info(dsv41): slots 4 rows 3-4 plain n 28: prepare 0.043/0.042/0.047 encode 0.622/0.619/0.643 wait 52.750/52.700/53.571 choose 1.823/1.814/1.925 other 0.000/0.000/0.001 round 55.239/55.199/56.083 commit_done 53.355/53.314/54.172 gpu 53.064/52.970/53.905 gap 0.006/0.006/0.007 seam 0.181/0.010/0.019
info(dsv41): command buffer 0 n 28: gpu 1.229/1.224/1.291 wall 53.355/53.314/54.172
info(dsv41): command buffer 1 n 28: gpu 13.002/12.994/13.229 wall 53.192/53.155/54.011
info(dsv41): command buffer 2 n 28: gpu 13.239/13.285/13.527 wall 53.036/53.000/53.854
info(dsv41): command buffer 3 n 28: gpu 12.268/12.208/12.666 wall 52.887/52.842/53.705
info(dsv41): command buffer 4 n 28: gpu 13.326/13.333/13.587 wall 52.751/52.701/53.572

Reading them: in the 1-stream block one plain row takes 28.406 ms a round, of which 27.460 ms is waiting on the GPU (2600 rounds). In the 4-stream block the rounds with four slots of 3-4 rows take 46.639 ms on average (1496 rounds), of which 44.935 ms is waiting on the GPU; prepare, encode and choose together are 1.70 ms. The 28-round block, all at 4 slots of 3-4 rows, reads 55.239 ms a round with 52.750 ms of it waiting on the GPU.

Raw JSON, server logs and drivers: https://gist.github.com/gilby/7eae3dd8607156d2bcbe11e5313c8e06

@tacosta

tacosta commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

I’m preparing the dense MTP work for #2485 as an unpublished local branch. ATC reports conflicts in zig/src/platform/environment.zig and environment_test.zig with this profiling setting. PR #2952 touches the same shared area; could we coordinate a single intended registry/test shape and landing order across both PRs? No #2485 code has been pushed, and I’m not requesting a review of it yet.

@gilby

gilby commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Yes — let's coordinate one shape. Our settings can move to whatever registry/test shape #2485 needs; we are not attached to how they read.

What we have in that shared area: our #2951 adds five TF_DSV41_* checkpoint-path and Engram rows plus one for the round profile, in zig/src/platform/environment.zig with their cases in environment_test.zig; #2952 adds the draft cost-table rows (TF_DSV41_CALIB, _DIR, _FILE and the measurement knobs). All are DeepSeek-only, unset means off, and none changes another family's tokens or defaults. We only append rows — we do not touch the table's machinery — so our rows can be re-expressed in whatever shape #2485 leaves it.

Landing order: #2485 first. Once it is pushed and in, we rebase #2951, #2952 and our other drafts onto it, keep yours' signatures, and append our rows in your shape. If you can tell us the row shape and where the test cases live when the branch is up, we will prepare the rebase against that so there is no second conflict when you are ready to land. Our served runs all have these settings unset, so the landing order does not move any number we have reported.

@tacosta

tacosta commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Thanks; that sequencing fits our planned stack: the shared-lanes prerequisite PR will target main, then the dense-MTP PR will target the prerequisite branch.

The local MTP change adds this environment rule:

.{ .name = "TF_MTP_TREES", .scope = .cuda, .kind = .flag, .forms = "0 or 1 (default 0; opt in to sampled MTP tree drafting)" },

Its valid-value cases are in zig/src/platform/environment_test.zig:

.{ .name = "TF_MTP_TREES", .raw = "0", .n = 0 },
.{ .name = "TF_MTP_TREES", .raw = "1", .n = 1 },

The branches are still local while we finish coordinating the other ATC overlaps, so there is no public branch ref yet. We’ll share the branch when preflight clears; the 2K TTFT regression will remain explicit in the draft PR.

@gilby
gilby marked this pull request as ready for review November 16, 2026 10:27
@gilby

gilby commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Marked ready for review as-is at 86050b1ee (still stacked on #1720; not rebased yet so its shape is preserved while coordinating with #3374 and #2485).

Coordination note vs #3374 (lead/metal4)

#3374 (6f67c89f3, ff1d0d00b8) also introduces TF_DSV41_ROUND_PROF and zig/src/families/deepseek_v41/metal/round_prof.zig, so the two overlap on the filename, env var, and forward.run hook:

  • What #3374 has that #2951 does not: pending deferred timestamp reads + round_prof.forget() for Metal 4 queues (first.m4 != null, where commit feedback GPU timestamps arrive after wait() returns), plus q.roundBegin / q.roundEnd round naming for TF_METAL4_TIMELINE. #2951 calls cb.gpuStart() / cb.gpuEnd() immediately after cbs[n - 1].wait() in forward.runTimed (bookBuffers), so #2951 as written does not defer GPU timing reads across rounds on Metal 4.
  • What #2951 has that #3374 does not:
    • Grouping by [slots][row_bucket][drafted|plain] (1..16 slots × 1, 2, 3-4, 5-8, 9-16 rows × drafted/plain) rather than exact row count 0..16 alone.
    • Per-round host phase breakdown (prepare, encode, wait, choose, seam, other), round/commit_done, per-command-buffer GPU and wall spans (cb_gpu, cb_wall), inter-CB gap, and drafter timings (ingest_wall, ingest_gpu, propose_wall, propose_gpu, finish).
    • Windowed mean/p50/p95 summaries (every 4,096 rounds and on close() when rounds were booked) with failing-allocator and non-finite GPU span guards.
    • Commit 1eeb70e9b in zig/tests/dsv41_metal/timing_real.zig (1 to 16 rows, 4 slots of 1 row, five layers, GB/s per shape).

On testing: we exercised #2951 (TF_DSV41_ROUND_PROF=1 and unset) on Metal 3 across both an M5 Ultra 512 GB and an M3 Ultra 512 GB, and exercised #3374 with TF_DSV41_ROUND_PROF unset in post-queue stack runs; we have not run TF_DSV41_ROUND_PROF=1 side-by-side on #3374's profiler itself.

Options once #3374 / #2485 order is settled

  1. If #3374 lands first and its 66-line cumulative counter is sufficient on main: we can drop #2951's round_prof.zig (closing #2951) and re-open 1eeb70e9b (timing_real.zig) cleanly by itself.
  2. If you want both Metal 4 support and the detailed breakdown / p50 / p95 / drafter timing: we can rebase #2951 onto #3374 (and #2485 if landed first), keep q.roundBegin/q.roundEnd + pending/forget() for m4 != null deferred timestamps, and keep #2951's rich grouping, phases, percentiles, and timing_real.zig coverage.

Either way, as noted above with @tacosta, we will adapt environment.zig / environment_test.zig to #2485's table shape when rebasing.

@gilby

gilby commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Measured side-by-side M5 Ultra (512 GB) comparison on common base baed91009 (deepseek-ai/DeepSeek-V4.1-Flash-1017, --parallel 4 --context 1048576 --prompt-cache-gib 0, Nominal thermal level before and after every arm):

  • Workload on each fresh server: tools/bench_concurrent.py --levels 1,4 --temperatures 0,1 --tokens 128 --reps 1 --alone --serial, followed by one 1,050-token plain ("draft": false, temperature: 0, ignore_eos: true) completion (3,555 decode rounds total).
  • Exactness across all 7 arms: failed=0, --alone unequal=0, --serial unequal=0, identical token_sha256 on every greedy bench_concurrent cell and identical plain1050 SHA-256 (fa25f5f91850de999f403fae72bae8b57bb994a4713bca53720eec06e76308d4).
Arm Code T0 N1 Chat T0 N1 Code T1 N1 Chat T1 N1 Code T0 N4 Chat T0 N4 Code T1 N4 Chat T1 N4 Plain 1050 tok/s Notes
#2951 M3 prof off 60.5 57.0 69.4 63.0 121.5 119.1 91.1 91.1 44.78 Metal 3
#2951 M3 prof on 61.3 56.8 69.7 62.9 121.4 118.8 90.8 91.0 44.79 Full 3,555-round summary at close
#3374 M3 prof on 61.2 56.5 69.4 62.7 121.3 118.7 90.8 91.0 44.67 Logged at 1024/2048/3072; dropped last 483 rounds
#3374 M4 prof off 61.8 57.1 70.1 63.4 123.5 121.0 91.8 92.1 45.43 Metal 4 default
#3374 M4 prof on 61.8 57.1 70.0 63.3 123.4 120.9 91.8 92.0 45.43 Logged at 1024/2048/3072; dropped last 483 rounds
#3374 + #2951 M4 off 61.8 57.1 70.0 63.4 123.4 120.9 91.8 92.1 45.43 Matches #3374 off
#3374 + #2951 M4 on 61.9 57.3 70.4 63.5 123.5 121.0 91.8 92.1 45.55 Zero profiler overhead; full 3,555-round Metal 4 breakdown

What the comparison shows & recommendation

  1. Combined (#3374 first, #2951 rebased on #3374) keeps all Metal 4 gains with zero profiler overhead. On Metal 4 (#3374 + #2951), running for (cbs) cb.failure() right after wait() + q.roundEnd() awaits Metal 4 commit feedback (other = 10–11 µs) before bookBuffers() / cb.gpuSeconds(), so timestamps read cleanly without sleeps (zig build -j1 test-dsv41-metal-all 53/53 passed on M5 Max including Metal 4 RoundProf verification).
  2. What #2951 reveals on Metal 4 that #3374's 66-line profiler hides:
    • encode drops from 0.482 -> 0.219 ms on 1-slot 1-row plain (n=2320) and 0.598 -> 0.290 ms on 4-slot 3–4 row plain (n=508), while DSpark ingest_wall drops 1.348 -> 0.566 ms.
    • #3374 (every = 1024, no close flush) emitted 2 periodic summaries during bench_concurrent and stopped at round 3,072 (dropping the last 483 rounds of the 1,050-token request), and averaged 1-slot drafted (34.146 ms GPU) and 4-slot plain (33.640 ms GPU) together under 4 rows.
  3. Best path: Land #3374 first for Metal 4 + TF_METAL4_TIMELINE, then rebase #2951 onto #3374 (cb.failure() before bookBuffers(), dropping #3374's minimal 66-line counter + forget(), and keeping timing_real.zig 1eeb70e9b).

Full 7-arm logs, summary JSON, and the tested 2951-on-3374.patch are in this gist: https://gist.github.com/gilby/c40da6d0d1ad5cc9785d1b63aeab4262.

@AIFlowML

Copy link
Copy Markdown
Contributor

The current 040b840f head trial-merges cleanly into d21617008, which contains the #1720 merge, but test-dsv41-metal fails to compile. Exact main reproduces the old Target.argmax fixture error. The PR adds a second error because metal4_test.zig still calls pkg.round_prof after the existing clock profiler moved to round_clock_prof.zig and lost its package export.

In scratch I retained the compatibility export to round_clock_prof.zig and made the stale argmax fixture use a scalar first-maximum reference. No profiling logic changed. The following passed all 101 tests on M5 Max with Zig 0.17.0, including the Metal 4 check that reads and drops the pending round before closing its queue.

zig build test-dsv41-metal test-environment-host \
  -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j2 --summary all

This validates the compile repair and queue-close regression. It leaves the release-model timing results on their original receipts.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby for the detailed profiling work.

Our last rebase of this branch removed the round_prof export that a newer Metal 4 test on main uses, so that test module no longer compiles. That one is on us, and we'll fix it here.

Two small notes on the profile output, neither blocking. With TF_DSV41_TREE on, tree launches appear in the per-row summary but not the new per-phase summary. And if the last round lands exactly on a 4,096-round summary, drafter timings recorded during shutdown are dropped; we'll fix that too.

  • Synthena

@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

@gilby The round_prof export is restored, and both profile-output gaps from my last note are fixed: tree launches now appear in the per-phase summary, and a final round on a 4,096-round boundary keeps its drafter timings. The profiler host checks pass, but it hasn't been rerun on Metal. Nothing is needed from you.

  • Synthena

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The Metal 4 export and both profiling-output fixes are present.

One issue remains in the optional FP8 timing run: the expanded default layer list includes layer 21, which has no indexer projection under the default configuration, but the shape list unconditionally unwraps that weight. Could you add the indexer shape only when its weight exists, while still timing the other projections, and add a small host regression for a non-index layer?

  • Synthena

@gilby

gilby commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in commit e71417af78:

  • Added Layer.fp8ProjectionShapes in zig/src/families/deepseek_v41/metal/weights.zig (reused by zig/tests/dsv41_metal/timing_real.zig), appending ix_wq_b only when non-null instead of unwrapping w.ix_wq_b.?, so non-index layers (such as layer 21 in the expanded default list) still time the other six projections without crashing.
  • Added host regression fp8 projection shapes omit indexer on non-index layers and include it when present wired into test-dsv41-round-prof-host (zig/build/dsv41_metal.zig).

Verified on this commit: zig build test-dsv41-round-prof-host --summary all (5/5 tests passed), zig build time-dsv41-metal-real compile, zig fmt --check build.zig zig, git diff --check origin/main...HEAD, python3 tools/pr_check.py --base origin/main (0 error(s)), and python3 tools/zig/lean_check.py (165 vs 165, 0 new).

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you, @gilby. The optional indexer projection is now added only when present, while the other six timing shapes remain. The focused host case checks both forms, and the timing run uses that same helper. The compatibility export and both earlier profile-output fixes are present too.

No further source correction is requested. What's left is the device comparison on the integrated profiler: with TF_DSV41_ROUND_PROF unset, generated token IDs equal to main, on Metal 3 and on Metal 4 where supported, with the release checkpoint. We don't hold DeepSeek-V4.1 on a Mac with enough memory, so that receipt needs to come from your side. The host and compile results are useful but don't replace it. This head merges cleanly with current main.

  • Synthena

@gilby

gilby commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Device comparison for origin/main (ef0ecb9a6d) cleanly merged with #2951 (e71417af78) on Apple M5 Ultra, 512 GiB against the release DeepSeek-V4.1 checkpoint on both Metal 3 (TF_METAL4=0) and Metal 4 (TF_METAL4=1):

Checkpoint & Configuration

  • Model: DeepSeek-V4.1-Flash-1017, revision 1bae0e1088993b9b82de08f59de5be5a34e42170 (config.json sha256 8be45ce0476004a3f529fd896115a4a2e800a129ad2d3ec05b16050f52e21879, built-in DSpark drafter + Engram tables + --vision)
  • Server: tensorfold-dsv41 serve ... --parallel 4 --context 1048576 --prompt-cache-gib 0 --vision --no-update-check (TF_EXPERIMENTAL=deepseek, TF_DSV41_ENGRAM_CACHE=4194304)
  • Checks per backend (main vs #2951, TF_DSV41_ROUND_PROF unset):
    1. Direct "return_token_ids": true comparison (128 generated tokens, T=0.0 and T=1.0, seed 1234, across /v1/completions and /v1/chat/completions) comparing exact token_ids arrays and token_sha256.
    2. tools/bench_concurrent.py --alone --serial --tokens 128 --reps 2 --temperatures 0,1.0 --levels 1,4 --seed 1234 (8 cells, 40 concurrent runs + --alone solo references + --serial "draft": false checks).
    3. Follow-up TF_DSV41_ROUND_PROF=1 integrated-profiler verification (190 rounds across the 4 direct prompts).

1. Metal 3 (TF_METAL4=0)

  • TF_DSV41_ROUND_PROF unset (0 profile summary lines emitted):
    • Direct token_ids vs main: 4/4 identical 128-token sequences (0 diffs); token_sha256 (main == #2951):
      • /v1/completions T=0.0: c013cb6669c10d0a... ([455, 2019, 1531, 2188, 411, ...])
      • /v1/chat/completions T=0.0: 4ff2822916dd7f01... ([2581, 1309, 3287, 16, 21017, ...])
      • /v1/completions T=1.0: 074ad574467a16a4... ([52480, 4181, 66910, 582, 17722, ...])
      • /v1/chat/completions T=1.0: 9b594c96c25eaef1... ([2581, 1309, 3287, 28, 8470, ...])
    • bench_concurrent.py: 40/40 concurrent rows match main's token_sha256 (0 diffs); 0 failed, 0 unmeasured, 0 --alone unequal, 0 --serial unequal (plain_drafted = 0).
  • TF_DSV41_ROUND_PROF=1: Emits complete dsv41 round profile (190 rounds across slots 1 rows 2 / 3-4 / 5-8, command buffer 0..4, and drafter stats), and all 4/4 128-token token_ids arrays remain identical to main.

2. Metal 4 (TF_METAL4=1, info: dsv41 metal: Metal 4 command queue)

  • TF_DSV41_ROUND_PROF unset (0 profile summary lines emitted):
    • Direct token_ids vs main: 4/4 identical 128-token sequences (0 diffs), identical token_sha256 digests as above.
    • bench_concurrent.py: 40/40 concurrent rows match main's token_sha256 (0 diffs); 0 failed, 0 unmeasured, 0 --alone unequal, 0 --serial unequal (plain_drafted = 0).
  • TF_DSV41_ROUND_PROF=1: Emits complete dsv41 round profile (190 rounds + command buffer 0..4 + drafter stats), and all 4/4 128-token token_ids arrays remain identical to main.

Throughput Reference (TF_DSV41_ROUND_PROF unset)

Cell (N, T) Metal 3 main vs #2951 agg (per-stream) Metal 4 main vs #2951 agg (per-stream)
code N=1, T=0 73.8 (73.8) vs 73.7 (73.8) 74.7 (74.7) vs 74.6 (74.6)
code N=4, T=0 150.2 (39.5) vs 150.1 (39.5) 151.9 (40.0) vs 151.8 (40.0)
chat N=1, T=0 74.9 (75.0) vs 74.9 (75.0) 75.9 (75.9) vs 75.8 (75.8)
chat N=4, T=0 146.4 (39.0) vs 146.4 (39.0) 148.2 (39.5) vs 148.0 (39.5)
code N=1, T=1 88.6 (88.6) vs 88.6 (88.7) 89.8 (89.8) vs 89.7 (89.7)
code N=4, T=1 109.0 (28.2) vs 109.0 (28.2) 109.8 (28.5) vs 109.8 (28.5)
chat N=1, T=1 79.3 (79.3) vs 79.3 (79.3) 80.3 (80.2) vs 80.2 (80.2)
chat N=4, T=1 110.0 (28.9) vs 110.1 (28.9) 111.0 (29.1) vs 110.9 (29.1)

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @gilby. The new Metal 3 and Metal 4 release-model comparisons answer the remaining request: profiling off matches main, and the four direct cases still match with profiling on. The optional-indexer guard, compatibility export and both output fixes remain present.

The relevant Metal source matches the measured integration, and this head merges cleanly with current main. No further source correction or duplicate device run is requested. Exact-tree CI remains before landing.

  • Synthena

gilby and others added 11 commits November 24, 2026 20:21
…ts of one row, five layers and GB/s per shape
…oked since the last one

The summary at close followed a periodic one even when no round had been booked in between, and
printed only a header such as "rounds 4097 to 4096 (0 rounds; ...)". write now returns at once when
no round was booked since the last summary. A test writes a fresh profile (nothing) and one after a
round (its header); it found 104 bytes before the change.
@ashhart
ashhart force-pushed the dsv41-metal-opt/00-round-prof branch from e71417a to cbf8254 Compare November 24, 2026 20:21
@ashhart
ashhart merged commit c576f59 into ashhart:main Nov 24, 2026
3 of 12 checks passed
@ashhart

ashhart commented Nov 24, 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 added a commit to gilby/TensorFold that referenced this pull request Nov 24, 2026
ashhart added a commit that referenced this pull request Nov 24, 2026
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.

4 participants