Repository navigation
DeepSeek-V4.1 on Metal: opt-in draft cost table timed at start, default pricing unchanged (stacked on #2983) - #2952
Conversation
0b51e33 to
c8c30ea
Compare
|
Thanks @gilby. Pricing from the machine's own table makes sense, and the tests cover the parts that matter for exactness: every slot's state hashes the same before and after the measurement, the stats and the prompt cache are untouched, and replies after a measured start equal the serial decode. Since the verify window keys each row's draw by its position, depth can only change speed. Asks:
If #2950 or #2951 lands first: 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
|
|
Real-weights receipt, and this is not ready. One M3 Ultra 512 GB, The measured table on this chip: Two problems:
I'll fix both (a pass timed the way a round runs it, and a calibration that fits in about 2 s) and rerun before asking for anything. The table itself is useful: about 9 ms a row from 1 to 16 rows on an M3 Ultra, and only a small step at row 17 (169.5 to 190.4 ms, where the second launch starts). |
|
Thanks. Head is now
On Rerun on one M3 Ultra 512 GB, release weights, at
The two start lines: What that fixes and what it does not. The two-stream loss is gone: two streams are 2.5 to 4.4% ahead of the stack tip, and one-stream code 2 to 3% ahead. Two things are still wrong: one cell is behind by more than noise (one stream, sampled chat, 46.1 and 46.5 against 47.5 and 47.5), and the calibration still reports 10.1 s over 11 timed runs, with load at 15.2 s against 5.1 s, though the timed windows add up to about 1.1 s. So most of that time is outside the timed runs and I have not found it yet. Not ready; I'll post again when both are closed, with three starts on each chip as you asked. At this head on an M5 Max: |
|
This push narrows the PR: with Commits since the last head Why the default changed. On an M5 Ultra, pricing from the measured table at
Two more checks on why. An unpushed variant that changed the acceptance estimate the depth rule uses did not recover the cells (chat 1 stream sampled 0.980, chat 2 streams greedy 0.981, Result: pricing from the measured table is not adopted for the default, and stays as an opt-in. Receipt at the final head,
Summary: token hashes equal to base in every cell of every arm (0 differences; Cells under 0.98 of base: none (unset). Opt-in
Opt-in
Startup lines, base and this head with the setting unset (identical in the 1 and 2 stream, the 3 and 4 stream and the Opt-in Refusal of a malformed value. Method as run: each cell is a fresh server started just before it, and the first server of each piece is run and discarded. Base is measured on both sides of this head (base, this, this, base). A thermal-pressure check ( Not run: M3 Ultra (pending, above); CUDA; cold-prompt cells for this head (nothing in the prompt path is changed, which is a reading of the diff and not a measurement); the kernel contract and device tests on this head (no GPU kernel is new or changed). Raw JSON, server logs and driver scripts: https://gist.github.com/gilby/d7cf0e381966791ac5ec9dc686e95de2 |
|
Thanks @gilby. Narrowing this to an opt-in is the right call, and the evidence for it is clear. Three chat cells were slower with the measured table in both series (for example, 1 stream sampled at 0.972 and Small things on
One pointer, not a blocker: In the order, this stays after #2983, so that its table is measured on the final kernels.
|
|
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).
Summary: two series, (a) Cells under 0.98 of base: none in series (a). In series (b) one, in the rerun only: 1 stream, temperature 1, chat at 0.978 (its first run was 0.981). (a) 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.
End level key: Nom = Nominal, Mod = Moderate, Heavy = Heavy. Exactness: token hashes equal across all four runs in every one of the 12 cells, 0 failed requests, 0 Startup line. With the setting unset, all 25 servers of series (a) print exactly one cost line, the default one, and nothing else about calibration; no log of the series mentions calibration. Verbatim from one of them: (b) Same order, rule and columns. The first run of each series (all 12 cells), then the rerun of the two series that had slower cells.
Verdicts, first run: 5 faster, 3 slower, 4 within noise. Exactness: token hashes equal across all four runs in every one of the 12 cells, 0 failed, 0 mismatches. Rerun. The 1-stream series and the
All 6 rerun cells, in full:
The rerun has 3 faster cells, 3 slower (1 stream T0 code, 1 stream T1 chat, openai T1 gpu-chat-no-think) and 0 within noise; token hashes equal in all 6, 0 mismatches. The faster cells are the same in the first run and the rerun (1 stream T0 chat 1.017, 1.016; 1 stream T1 code 1.043, 1.044; What the measured table printed. The first Over the 14 Discarded, retried and flagged cells
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 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 ( Not run: Raw JSON, server logs and driver scripts: https://gist.github.com/gilby/8f3815c1164339f45cf8f9d6b2fa73f4 |
…table on both chips
|
New head: Your "small things" of 12 Nov 23:50, point by point:
The Receipts: the three new commits are documentation, the CHANGELOG and the ledger, so the M5 Ultra and M3 Ultra receipts above (taken at At |
|
M5 Ultra, 512 GB: the three fresh starts with
Each start is a fresh server; the calibration is what the start measured over its 21 timed runs before serving.
The spread over the three fresh starts on the M5 Ultra: 1-row verify 20.753 to 20.787 ms (0.16% of the mean), 16-row verify 106.981 to 109.939 ms (2.7%), pass 4.651 to 4.744 ms (2.0%). The default table is what serves when All four starts ran at Nominal thermal pressure and the smoke passes all passed; the smoke numbers themselves are in the gist, not in the table. These starts are on this PR's current head, before the kernel PRs ahead of it in the #2984 order; the measured table moves with those kernels, so I'll take the starts again on the rebased stack at landing. Still owed: none from the 13 Nov list, apart from that repeat at landing. Raw logs and the smoke-pass JSON: https://gist.github.com/gilby/b57f35979333d8f758e7189dd4b11661 |
|
I’m preparing the dense MTP work for #2485 as an unpublished local branch. ATC reports a conflict in |
|
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 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. |
|
Thanks; that sequencing fits our planned stack: the shared-lanes prerequisite PR will target 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 .{ .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. |
…table on both chips
a97716e to
90b0bd6
Compare
|
Rebased Rebase +
|
| Start | Load wait | Calibration time (runs) | Verify 1 / 16 rows (ms) |
Drafter pass (ms) | Code T0 (tok/s) | Chat T0 (tok/s) |
|---|---|---|---|---|---|---|
measure-1 |
10 s | 3.24 s (25 runs) | 20.716 / 85.382 | 4.583 | 65.5 | 60.8 |
measure-2 |
8 s | 3.22 s (25 runs) | 20.724 / 84.763 | 4.534 | 65.5 | 61.0 |
measure-3 |
9 s | 3.16 s (25 runs) | 20.717 / 84.509 | 4.524 | 65.4 | 61.0 |
TF_DSV41_CALIB unset): load 4 s, logged dsv41 draft costs: default, verify 1 / 16 rows 42.000 / 117.000 ms, pass 5.600 ms (nothing timed); code 65.4 tok/s, chat 59.9 tok/s.#3365 compat (TF_DSV41_CALIB unset + TF_DSV41_CALIB_FILE set): load 4 s, logged dsv41 draft costs: cached ... with no startup timing; code 63.7 tok/s, chat 61.0 tok/s.failed=0, --alone unequal=0, --serial unequal=0, identical token_sha256 across all 5 starts (c013cb6669c1... code, 7a2c89be2e6c... chat).90b0bd662: test-environment-host, test-dsv41-env-host, test-dsv41-shared, test-dsv41-serve-host, test-dsv41-draft (18/18 steps, 303/309 passed, 6 skipped); zig build -j1 test-dsv41-metal-all on M5 Max (11/11 steps, 71/71 passed); python3 tools/pr_check.py --base fd93b546c --pr 2952 (0 errors, 0 warnings, lean 341 vs 341, 0 new).(We also exercised TF_DSV41_CALIB=measure inside our combined post-queue test stack including #3374 Metal 4, #2950, #2954, #2973, #2983, and #3278: there TF_DSV41_CALIB=measure timed 2.78 s, 18.239 / 73.699 ms, pass 3.705 ms on M5 Ultra 512 GB and 3.47 s, 26.865 / 105.805 ms, pass 5.100 ms on M3 Ultra 512 GB with matching token_sha256 — lower than the 20.7 / 84.5–85.4 ms / 4.52–4.58 ms measured on #2983 alone because #3374, #3360, and #2954 sit above #2983.)
Recommended stacking and landing order
Right now #2952 is stacked directly on #2983 (fd93b546c). Across the open DeepSeek-V4.1 Metal queue, the cleanest full landing order is:
- Independent hotfix on
main:#3522(metal_dsv41_limitstensorOnlycheck). - Kernel / decode / Metal 4 foundation:
#2973->#2983(note#2983atfd93b546calready contains#2973's rebased commits on3a56d4eb9) ->[maintainer decode & Metal 4 stack (#3405 / #3360 / #3354 / #3374 + #3351)]. - Host/runtime PRs in clean dependency order:
#2950->#2954(factorssegs.declare,window, andargmaxcleanly) ->#3278(wirespool_bufsintosegsandsnapshotsover#2954+#2983) ->#2952last (soTF_DSV41_CALIB=measuremeasures the final Metal 4 / decode / slot-dispatch / pool kernels, andcalib.zigwipe resets#2950'sfilling/hit_on,#3278'ssnapshots.clear()/pool.give(), and#1722'simages). - Vision (
#1721->#1722): independent of#2950/#2954/#3278/#2952aside fromboot/serveinit order,fixture_serve.Opts, and resettings.imagesinsidecalib.zig's wipe (if#1722lands before#2952). - Profiler (
#2951) & env registry (#2485):#2951is ready as-is (86050b1ee) with a coordination note vs#3374'sround_prof.zig(timing_real.zigcommit1eeb70e9bis also orthogonal if extracted), and#2951/#2952will follow#2485'senvironment.zigshape once#2485lands.
|
Thanks @gilby. Your head keeps We carried the tile and expert-row prerequisites, put calibration last, and the integration now clears stepped and tree state, pauses both profilers while measuring and restores their counters. On an M5 Ultra the checks pass (421 tests), and the DeepSeek contract passes 108 kernels with all 208 controls caught. Every mode must keep the same output tokens, and the earlier measured-mode timing losses stay stated as they are. The three fresh measured starts, the default and file comparisons on the final kernel stack, the release-checkpoint token and speed checks on a 512 GB Mac, and CI are ours. Nothing more is needed from you.
|
|
I reran For the public stack, Igor Lessio - AIFLOW LABS |
c6abc3b to
dfaca3d
Compare
The depth rule priced Metal rounds with the CUDA-shaped defaults. Metal now times dry windows of 1 to 16 rows, the second launch from row 17 and a DSpark pass with its ingest at load, on a time budget, through the lane core's calibration path. TF_DSV41_CALIB keeps its meaning; measure is the Metal default, and TF_DSV41_CALIB_BUDGET_MS bounds the repeats. The prompt cache is not fed and every slot is left as new.
…t table The first measurement took 12.7 s and priced the pass at 62 ms. It now times rows 1, 2, 4, 8 and 16, the 4 + 4 window, rows 17 and 32 and the pass once each after an untimed window and pass, repeats the passes only while the budget lasts, and interpolates the rows between. The startup line reports the ingest share of the pass and the timed runs.
… table by device and weights The Metal measurement now checks every TF_DSV41_CALIB* setting before it times anything, so a malformed value stops the start naming the setting, its text and the accepted forms; only a measurement that fails falls back to the defaults. The settings have rows in platform/environment.zig and docs/environment.md. A stored table carries the device and checkpoint identity, so another chip or other weights never read it. dropWindow's comment says it is for calibration, with wipe after.
…very window a lone stream can make The measurement prefilled the calibration text into each slot twice and ran thirty one-row windows to grow a continuation, which cost about nine seconds on the release model outside the timed runs. It now prefills one short prompt in each slot it needs once, takes the window tokens from the text itself, and clears only the slots it used. Rows 1 to 6 are timed rather than interpolated, since a lone stream's drafts make exactly those windows.
…t be one The pass's entry was a single sample taken right after the largest windows, so whatever the first ingest after them costs became the table's pass. The pass is now run once untimed and five times back to back, as a round runs it, and the fastest is kept; the first ingest after the windows is reported apart. A table whose pass is dearer than twice its own 1-row window is refused when measured and when read back from a stored file.
…budget The slot term is the 4 + 4 window less the 8-row one, each a single sample once the budget was spent. Both now run twice more side by side after the passes, marked so the budget never drops them; only the other row counts are optional.
…ults On the M5 Ultra the measured table made code faster and sampled chat slower in three cells, with the rule near-indifferent between the depths. The table is still timed at start and reported, with its checks and settings, but the default table prices the rounds unless TF_DSV41_CALIB names a source, so served depths are unchanged. The lanes test and the Metal device test run from the Metal test steps.
Unset or blank keeps the default table with nothing timed and no extra startup line, so load time and behaviour are the base's. measure, zig, cached and real time or read the table, check it, report it and price from it. The table_prices switch is gone.
dfaca3d to
ada6655
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
On Metal, DeepSeek-V4.1's draft depth rule prices its rounds from the CUDA-shaped built-in table. This adds a way to time a table on the loaded model and price from it, as an opt-in: with
TF_DSV41_CALIBunset or blank on Metal (andTF_DSV41_CALIB_FILEunset) nothing is timed and the built-in table prices the rounds exactly as on base (same startup lines, same load time, same depths, same tokens); namingmeasuretimes a table at start (about two to three seconds), checks it, reports it and prices the rounds from it,zigstores that table and reads it back on the device and checkpoint that stored it,cachedandrealread a stored one. Preserves#3365(TF_DSV41_CALIB_FILEstill reads that JSON file directly whenTF_DSV41_CALIBis unset or blank). A malformedTF_DSV41_CALIB*value stops a Metal start naming the setting, and a table whose pass costs more than twice its own 1-row window is refused. Pricing never changes a token.The PR started as "price the rounds from a table measured at load" by default. On an M5 Ultra that made the code cells 1 to 6% faster and three chat cells 2 to 4% slower (repeated on a rerun), so the default stays the built-in table and the measured table is kept as an opt-in. The measurements are in the receipt comments on this PR.
fd93b546c, which includes#1720,#3365, and#2973; GitHub PR target remainsmainwhile#2983is open, so the 13 PR commits sit cleanly onfd93b546c):2065d5bc0dsv41 metal: price drafts from a cost table timed on the loaded model753574089dsv41 metal: time a sparse set of windows and a warm pass for the cost table18d190bdddsv41 metal: refuse a malformed timing setting, and key a stored cost table by device and weightsc84b8cacadsv41 metal: measure the cost table over a two-row prompt, and time every window a lone stream can make6efaef6a5dsv41 metal: time the pass back to back, and refuse a pass that cannot be one3b8dc251ddsv41 metal: the slot term's windows keep their repeats whatever the budget6c9584d8bdsv41 metal: report the timed cost table and keep pricing by the defaults2fc3bb988dsv41 metal: time nothing unless TF_DSV41_CALIB names a source1d9a3cc6bdsv41 metal: the TF_DSV41_CALIB refusal names the Metal default as it is62693f6ffdocs: the TF_DSV41_CALIB row describes each mode once73955271fdocs: the optimization ledger's row for DeepSeek-V4.1's measured cost tablec58e925c3changelog: DeepSeek-V4.1 on Metal: opt-in draft cost table timed at start, default pricing unchanged (stacked on #2983) #2952's line says what a user gets from the opt-in table on both chips90b0bd662dsv41 metal: keep TF_DSV41_CALIB_FILE active when TF_DSV41_CALIB is unsetChecks on this head
90b0bd662(rebased onto#2983fd93b546c). Full 16-cell / 4-stream base-vs-branch unset + opt-in parity receipts were collected earlier at55ae488ba(M5 Ultra) and284548471(M3 Ultra); on rebased90b0bd662over#2983, verified host, draft, M5 Max device tests,TF_DSV41_CALIB_REPS=0refusal, 3 freshTF_DSV41_CALIB=measurestarts + 1 unset start + 1TF_DSV41_CALIB_FILEstart on M5 Ultra (512 GB), plus combined post-queue stack runs (TF_DSV41_CALIB=measure) on both M5 Ultra and M3 Ultra.python3 tools/pr_check.py --base fd93b546c --pr 2952:27changed files;lean 341 vs 341, 0 new;0 error(s), 0 warning(s).zig fmt --checkandgit diff --checkexit0.zig build test-environment-host test-dsv41-env-host test-dsv41-shared test-dsv41-serve-host test-dsv41-draft -Dcpu=apple_m1 --summary all):18/18steps succeeded,303/309tests passed (6skipped:test-dsv41-draft148/148,test-dsv41-serve-host14 pass, 5 skip,test-dsv41-shared103 pass, 1 skip,test-dsv41-env-host14/14,test-environment-host24/24).zig build -j1 test-dsv41-metal-all --summary all):11/11steps succeeded,71/71tests passed (0failures,0skips:16 + 32 + 23), including the newcalib_testcase checkingTF_DSV41_CALIBunset +TF_DSV41_CALIB_FILEset.#2983(fd93b546c),cost_table_test.zig,calib_pass_test.zigandcalib_test.zigdo not build, since each uses what this PR adds (Plan.initWide,calib_measure.launch_bound, the stored table'sid,Costs.plausible, the pass'singesttiming,metal.calib); before90b0bd662, havingTF_DSV41_CALIBunset whileTF_DSV41_CALIB_FILEwas set was overridden to"default"inserve.Metal.knobs().90b0bd662: CUDA (the shared filesdraft/costs.ziganddraft/calib_env.zigalso serve the CUDA engine; only the host tests that include them ran); cold-prompt cells (nothing in the prompt path changed).Receipt
90b0bd662on#2983(deepseek-ai/DeepSeek-V4.1-Flash-1017, release weights,Nominalthermal before and after every start):TF_DSV41_CALIB=measure TF_DSV41_CALIB_REPS=0exited1withtensorfold: TF_DSV41_CALIB_REPS="0": expected a whole number of timed runs from 1 to 50.TF_DSV41_CALIB=measurestarts (25 timed runs each): measured in3.24 s,3.22 s,3.16 s; verify1 / 16rows20.716 / 85.382 ms,20.724 / 84.763 ms,20.717 / 84.509 ms; pass4.583 ms,4.534 ms,4.524 ms; slot0.00 ms.dsv41 draft costs: default, verify 1 / 16 rows 42.000 / 117.000 ms, pass 5.600 ms(load4 s, nothing timed).TF_DSV41_CALIBunset +TF_DSV41_CALIB_FILEset: loggeddsv41 draft costs: cached ...with no startup timing (4 s).bench_concurrent.py --levels 1 --temperatures 0 --tokens 128 --reps 1 --alone --serial:failed=0,--alone unequal=0,--serial unequal=0, identicaltoken_sha256across all 5 starts (c013cb6669c1...code,7a2c89be2e6c...chat).90b0bd662on M5 Ultra 512 GB): https://gist.github.com/gilby/af3b469c4f32b2271a8229744ea448a555ae488ba) and M3 Ultra (284548471): https://gist.github.com/gilby/d7cf0e381966791ac5ec9dc686e95de2 (M5 Ultra), https://gist.github.com/gilby/8f3815c1164339f45cf8f9d6b2fa73f4 (M3 Ultra).deepseek_v41) on Apple GPUs; with the setting unset (andTF_DSV41_CALIB_FILEunset) none of its behavior changes. The CUDA engine sharesdraft/costs.ziganddraft/calib_env.zig; CUDA was not run.TF_DSV41_CALIB(existed for CUDA, now registered for Metal inplatform/environment.zig): unset or blank readsTF_DSV41_CALIB_FILEwhen set and otherwise usesdefaulton Metal (nothing timed),cachedon CUDA; acceptedcached,default,real,measureorzig, in any case; anything else stops a Metal start naming the setting, the text and the accepted forms. Ten moreTF_DSV41_CALIB_*settings (_DIR,_FILEalready added for#3365,_SHAPE,_STAT,_REPS,_WARM,_RECHECK,_CYCLE,_DEEP_REPS,_BUDGET_MS) are registered the same way.docs/environment.mdhas one row for each; there is nodocs/profiles.mdrow, since none of them selects a policy.#2983fd93b546c(base vsorigin/mainat3a56d4eb9), head90b0bd662; Zig0.17.0; M5 Ultra, 512 GB, macOS27.2.1(26B131);deepseek-ai/DeepSeek-V4.1-Flash-1017release weights at revision1bae0e1088993b9b82de08f59de5be5a34e42170; M3 Ultra, 512 GB, and M5 Max for device tests.TF_DSV41_CALIBunset,measure,TF_DSV41_CALIB_FILE, andTF_DSV41_CALIB_REPS=0), M5 Max device test suite, and earlier M3 Ultra series; could not run CUDA or another Metal chip.tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false:token_sha256equal across all 5 starts on90b0bd662(failed=0,--alone unequal=0,--serial unequal=0), and equal across all earlier 13 M5 Ultra / M3 Ultra arms.#29833-start + unset +CALIB_FILEreceipt on M5 Ultra below).tools/bench_openai.py: at55ae488bawithTF_DSV41_CALIBunset (median of 3): fibonacci-raw 71.0 / 71.1 (T 0) and 65.4 / 65.5 (T 1), gpu-chat-no-think 56.7 / 56.7 (T 0) and 56.8 / 56.8 (T 1); at90b0bd662on#2983,bench_concurrent.py1-stream T=0 unset vs 3measurestarts: code65.4vs65.5 / 65.5 / 65.4tok/s, chat59.9vs60.8 / 61.0 / 61.0tok/s.Checklist
cost_table_test.zig,calib_pass_test.zigandcalib_test.zig; see Checks on this head)."draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.--drafter, no slower than without it, greedy and sampled (withTF_DSV41_CALIBunset, the default;measureis opt-in and not no-slower everywhere, as above)