Repository navigation
nemotron metal: a GPU round prices its head depth from the window-cost table - #1115
Conversation
|
Thanks @jishnuvenugopal. We rebased this onto current main and ran it against main on two M3 Ultra machines with Nemotron 3.5 Lightning 30B-A3B (MLX 4-bit), in alternating base/new runs.
M3 also has no tensor units in the row projections, so the priced depth should help it as much as M4. Instead, it looks like the table picks a shallower round than the fixed rule at short contexts, where the deeper levels were still paying off. Could you check the depth this chooses after a 2k prompt on an M3-class chip and compare it against the old rule's accepted tokens per round? We'll land this once single-stream decode is no slower than main on M3 and the M4 gain holds. - Synthema, Ash's AI Assistant. |
ashhart
left a comment
There was a problem hiding this comment.
Thanks @jishnuvenugopal. We rebased this onto current main (clean) and ran it on an M3 Ultra with Nemotron 3.5 Lightning 30B-A3B, main and this PR alternating (main, PR, PR, main). Tokens are identical (0 of 8 prefill rows differ, drafted equals plain), and the per-prompt results repeat within about 1% across both pairs:
| prompt | main decode tok/s | PR decode tok/s |
|---|---|---|
| 2k #1 | 170.5 / 169.6 | 150.3 / 154.4 (-10 to -12%) |
| 2k #2 | 171.7 / 171.2 | 154.5 / 154.0 (-10%) |
| 2k #3 | 156.2 / 155.8 | 205.1 / 204.0 (+31%) |
| 2k #4 | 170.7 / 170.5 | 150.6 / 149.7 (-12%) |
| 8k #1 | 184.2 / 184.0 | 237.1 / 237.1 (+29%) |
| 8k #2 | 133.5 / 132.9 | 181.7 / 180.5 (+36%) |
The 1/2/4/8-stream sweep aggregate is within -1% to +2.5%. So the cost table picks much better depths on some prompts, but costs 10-12% on others, and we can't land a slowdown on any cell. A likely cause, found in review: when level 2 never lands, round_depth.zig (around lines 63-67) keeps stepping back up on the assumption that the next level survives at the current rate, so the depth alternates 2, 1, 2, 1, ... and half the rounds pay for a wider window with no extra tokens. Backing off after a failed probe, or tracking the deeper level's realized survival, should keep the wins without the losses. Two smaller points: the no-table branch (around line 19) can't run because gpu_round.zig already indexes the table, and its fallback doesn't match today's 4-or-all behaviour. We'll rerun the same cells as soon as there's an update.
|
Review against main 3f408b6. Tokens are identical, as before; the slowdown we measured has a clear cause. When level 2 never lands, the step-up test assumes it will, so depth alternates 8 rounds at 1 and 8 at 2 indefinitely (the first test even encodes the drop from 2 back to 1). Simulating with the PR's own M4 cost table, with the first draft always landing and the second never, half of 160 rounds run at the useless depth 2 and throughput is 15.1% below a fixed depth of 1, consistent with the 10–12% we saw on an M3 Ultra. Please stop stepping up once a level has shown it doesn't land (and add that case as a red-before/green-after test). Also, the empty-cost-table branch can't run, because |
|
Thanks @jishnuvenugopal. Pricing the head depth from the window-cost table is a real win on some prompts, so rather than wait we'll finish it on our side, keeping your commit: the depth stops stepping back up once a level has shown it doesn't land, with a test for that case, and the empty-cost-table fallback matches main's rule. Then we'll rerun the same Nemotron cells against main, and land it if no cell is slower. |
…t table round_depth chose between all of the head's levels and a fixed 4, a rule that treats a verify window of up to 5 rows as costing about one row. The backend's window-cost table says otherwise on a chip whose row projection runs per row (M1 to M4): there a deeper window costs more than the tokens it adds. Depth.init now prices each depth s as costs.at(s + 1) + s * head_ms and starts at the depth with the most expected tokens per ms under a 0.75 per-level survival prior. Every 8 rounds Depth.next compares the realized tokens per ms of each depth up to the current one, and steps one level deeper only when the current depth's full windows would pay for the extra row.
af33202 to
09c0123
Compare
|
Thanks @jishnuvenugopal, this is merged. Your commit is in as it was, with one of ours on top (
Results with Nemotron 3.5 Lightning 30B-A3B (MLX 4-bit), alternating main, PR, PR, main:
We also ran your commit alone against today's main on both Macs. It came out within 1% everywhere, so the 10-16% M3 slowdown from 24 Oct doesn't reproduce on today's main. The fix covers the case the simulation showed, so it stays. |
|
Thanks @jishnuvenugopal: the priced draft depth for Nemotron on Metal shipped in TensorFold 1.1.9. |
Thank you, @ashhart, for the GPU round and the head-depth rule in
round_depth.zigthat this refines, and for thewindow-cost table the Metal backend already measures at load (
copy_lanes.Costs): it is what lets the depth be pricedinstead of fixed.
What this changes
round_depth.Depth(zig/src/families/nemotron/round_depth.zig) started a GPU round at all8levels and dropped to afixed
4when the levels past 4 brought under a tenth of the tokens. That treats a verify window of up to 5 rows ascosting about one row, which the backend's window-cost table contradicts on a chip whose row projections run without
tensor units (
zig/kernels/metal/core/row_projection.metal): on an M4 each row adds 7 to 9 ms to a 20 ms window.Depth.initnow takes the table and the head step time fromgpu_round.runand prices each depthsascosts.at(s + 1) + s * head_ms. It starts at the depth with the most expected tokens per ms under a 0.75 per-levelsurvival prior, or at
min(4, most)when the table is empty. Every 8 roundsDepth.nextcompares the realized tokensper ms of each depth up to the current one, and goes one level deeper only when the current depth's full windows would
pay for the extra row. A fixed depth is unchanged.
round_depth.zigjoinsnemotron.zig's test block for its two newtests.
This is the depth of one stream's GPU round on Metal. It does not touch the depth rule of shared rounds, where several
streams verify together, which #1059 is about (thanks, @plotarmordev).
Verified outcome
essay-style text it was 9% slower (42.8 against 47.2 tok/s). A round that drafted 4 or 8 levels deep paid for verify
rows whose tokens were mostly thrown away.
goes deeper only when the deeper rows keep paying for themselves.
tensorfold run(51.1to 60.1 tok/s on code, 42.8 to 54.3 on essay text) and 16% to 26% faster under
serve, 26% to 33% faster onhigh-acceptance copy prompts (78.6 to 99.0 tok/s copying a paragraph, 81.5 to 108.3 copying an 8K list), and now 15%
to 139% above plain decoding on every prompt measured. Every reply is token for token the same as before. Four
requests at once, prompt speed and memory are unchanged. Not measured: any chip with tensor units (M5), where this
changes the depth a round starts at.
Receipt
Environment: branch
perf/nemotron-round-depth-costsonmainat d1018b3 (1.1.1), Zig 0.17.0, Apple M4 (32 GB),macOS 27.0.1,
TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bitat d9d758fb. Load averages 1.4 to 2.9 (noother workload), recorded per run.
Exactness:
tensorfold run, 256 tokens, temperature 0, four prompts (fibonacci-raw, gpu-chat-no-think,sql-chat-no-think, essay-chat-no-think). Each prompt's plain run (
--no-drafts), fixed depths 1 to 4, and two runs ofmain and two of this branch at
--gpu-round 8: all 8 drafted runs per prompt equal the plain run's 256 tokens (32 of32:
54195f74313a,dc6df8c9622e,bdba18f79184,498e92e027a3).serve:tools/bench_openai.pytoken_shac91869ce1808and5ef050084ac3on all four launches,tools/bench_concurrent.py --alone --serial0 unequal, 0 failedon all four, andbench/d4_copy.pytext_sha8d5581a06df6,fd621d8d4fc4,dcd1880a0a4f(server token_sha5414bb3db7e3,15045d7e74d1,eba0eb1969af) equal across all 16 drafted and plain runs per prompt.Decode before and after,
tensorfold run --max-tokens 256 --warmup, one window-cost table timed by the first draftedrun and kept by every later run of both builds (1 to 5 rows: 19.74, 27.22, 35.96, 43.36, 52.50 ms; head step 1.505
ms), tok/s (the depth the rule chose, in rounds):
The rule picks a depth from the table and the prompt's own acceptance; on fibonacci-raw a fixed depth 3 is faster
still (64.2) and a fixed depth 1 is 0.3 to 1.4 tok/s ahead on the other three, so a better prior is possible, but no
single fixed depth is best on all four prompts, and a fixed 1 would be wrong on a chip whose table is flat.
Decode before and after,
serve --parallel 4 --context 34816 --prompt-cache-gib 0, four alternated launches (thisbranch, main, this branch, main) on one shared window-cost table timed by main, measured with
tools/bench_openai.py --tokens 256 --reps 2 --temperatures 0,tools/bench_concurrent.py --levels 1,4 --tokens 128 --reps 2 --temperatures 0 --alone --serial, andbench/d4_copy.py(four more alternated launches on the same table; 256 tokens, 172 for theparagraph, temperature 0, median of two reps), tok/s:
bench_openai.pyfibonacci-rawbench_openai.pygpu-chat-no-thinkbench_concurrent.pycode, 1 stream (128 tok)bench_concurrent.pychat, 1 stream (128 tok)bench_concurrent.pycode, 4 streams (aggregate / steady)bench_concurrent.pychat, 4 streams (aggregate / steady)d4_copy.pycopy-paragraph, drafted (plain: 46.3 to 47.3)d4_copy.pycopy-8k-list, drafted (plain: 45.0 to 45.9)d4_copy.pychat-control, drafted (plain: 46.8 to 47.3)Four streams at once is unchanged within noise: that path does not use the GPU round's depth rule.
Prompt speed before and after,
tools/bench_cache.py --contexts 2048,8192,32768 --max-tokens 1 --require-coldatserve --parallel 4 --context 34816 --prompt-cache-gib 0on one shared window-cost table (cache_state: "cold"andidentical
token_sha7d7179c146d0,28c7d2ef7f39,ffa6059b954aon every run), median TTFT (and tok/s). Taken ond46d17a (1.1.0 and docs), this branch's previous base; the prompt pass does not read the round depth, and
d1018b3 changes only imports in the Nemotron Metal path:
Peak physical footprint (
vmmap -summary, after the benchmark suites): 23.0 GiB current and 23.0 GiB peak on allfour decode launches of both builds; 22.3 to 22.4 GiB current and 22.7 GiB peak on the prefill launches. 0 leak lines
in every server log.
Tests run, uncached, on this branch and on main at d1018b3:
zig fmt --check build.zig zig,git diff --check origin/main,zig build -Dcpu=apple_m1,zig build test -Dcpu=apple_m1(4930/4951 passed, 21 skipped; main4927/4948, 21 skipped),
zig build test-kernel-contract(65/65),zig build test-golden(306/319 and 26/26 equal, 0unexpected differences, as on main),
zig build fuzz-cortheon(11/11),flashnext_batch_serve_test.py(8 OK),cross-builds
-Dtarget=x86_64-linux-gnu -Dcpu=x86_64_v3and-Dtarget=aarch64-linux-gnu,zig build native -Dcpu=apple_m1 -Dversion=1.0.0, andlean_new.py(443 problems, 444 on the base, 0 new). The 3 more tests are the 2new ones and 1 existing one the macOS test binary now reaches through
round_depth.zig(copy rows that keep landing price a long window; ones that miss price none), all passing. New, inround_depth.zig:a steep per-row window table starts at 1 level and steps up only when windows saturate(expected 1, found 4whenDepth.initstarts atmain's
@min(4, cap), the only failure) anda flat tile window table starts at 4 levels, steps up on full windows, and drops back when deep levels miss(an invented flat table, see below). They run in the macOS test binary; theubuntu and Windows jobs do not build the Nemotron Metal family.
Not run, and why: no M5 or other tensor-unit chip here. On such a chip the rows of a window share one tile, so the
table is flat to 16 rows and this rule will start deeper than 1; main starts at 8 and drops to 4. Whether the start
the table picks matches or beats main there is unmeasured, and the flat table in the test is invented. Please run
tensorfold run --gpu-round 8on an M5, before and after, before this lands. M1 to M3 and CUDA: not run (CUDA isnot touched).
Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.(Above: drafted equals plain 32 of 32 on the CLI;
bench_openai.py,bench_concurrent.py --alone --serial, andd4_copy.pyall match across main and this branch.)every reply's tokens are equal.)
SUMMARYline is in the receipt. (n/a: no kernel is added or changed.)bench_cache.py --require-coldat 2K, 8K and 32K.)the open question above.)