Repository navigation
metal nemotron: TF_KV_SHARE keeps prompt states as core pool pages (stacked on #1837) - #1850
Conversation
875c056 to
34f66f3
Compare
|
Rebased onto main ( |
|
Thanks @jschmied for the clean rebase. We read the two commits. |
|
Thanks @ashhart. Here are the M3 Pro checks rerun on Where this run differs from the body
Gates
ABBA speed, share against main: medians of 4 servers per arm, 3 repeats each.
Since this Mac runs under daily load, a run on your M3 or M5 Ultra would give cleaner speed numbers and the copy-store comparison. We'd gladly take your offer. |
|
Thanks @jschmied, that's a thorough rerun: every reply byte-equal, every gate green, and the three numbers that moved explained by the box's state, not the code. We'll take the Mac run you suggested: on our M3 or M5 Ultra, on this head, flag off against main, |
|
Thanks @jschmied. Here's the Mac run on an M5 Ultra with Nemotron 3.5 Lightning 30B-A3B MLX 4-bit, balanced order, against main:
All three read level. On both One correction to what we said we'd run: these arms used 1 and 8, not the 4 you suggested, and this table doesn't report the cached-token counts or the cap-8 round robin separately. It answers the question that matters for landing, that the flag off and on costs nothing here. This is queued to land, and our prep will carry the one-line rebase around |
34f66f3 to
c2854c9
Compare
|
Thanks @jschmied. Main has moved under this one. Nemotron's prompt loop now cuts its chunks in |
c2854c9 to
96cec73
Compare
|
Thanks @ashhart. All done on
Lean checker 210 and 210, new findings 0. Nemotron Metal host tests on the rebased head (Apple M3 Pro, Zig 0.17.0). The counts are from the first run on the rebased tree; since then only the new test's name changed, and the rerun on |
|
Thanks @jschmied. The cut now sits in |
96cec73 to
2e5cd2c
Compare
|
Thanks @ashhart. All three are on
|
|
Thanks @jschmied. Here are the two missing cells on the rebased head 96cec73, against its main parent c3f64ca, on an M5 Ultra with Nemotron 3.5 Lightning 30B-A3B MLX 4-bit.
Every tested reply's token IDs and text equal its fresh run and the other store's reply. Per-request cached tokens are in cached-tokens.tsv. The functional cells used greedy sampling and draft:false. The server reported 8192-row chunks, so these prompts were longer than that grid. Cap 8: 12 conversations, 12 hits, 20 evictions; the state count reached 8 and never exceeded it. All 40 replies equal fresh. 112 idle census lines satisfy free + kept == total. The counters do not distinguish page-pressure reclaim from state-cap eviction; we did not force pressure. With TF_KV_SHARE unset, warm/base/new/new/base, first process excluded:
All 192 cross-arm prompt/reply keys match. The full report includes both process medians per arm and all speed findings. TF_NEMOTRON_METAL_KV_PAGES=1 was enabled throughout. Share-enabled concurrency/drafting and forced-pressure cases remain unchecked on this head. No source changes or public post were made. These ran on |
|
@jschmied, this was in tonight's landing train, but on today's main it takes |
2e5cd2c to
3dca2b1
Compare
|
Thanks @ashhart. Done on
|
… names kv_pool and kv_prompts
…ashhart#1293) The core prompt_radix store over the Nemotron pool, opened through the CUDA adapter. A kept state is its Mamba states (Snap.pages); its rows stay in pages a later stream adopts. Marks lie on the prompt chunk grid, so a resume's chunk seams are a cold pass's. Unset or 0: the host prompt cache as before. The store's marks end chunks in prompt_flight.rows, where the prompt loop cuts them. metal.zig reads the model's window with cuda_window's modelContext instead of its own copy.
…s, as the --learn-conversations refusal does
…e core adapter, so metal.zig stays under 600 lines
) Port of ashhart#1850 onto main's prefill_metal.zig and prefill_steps.zig: Ops.open begins the store's pass before the cache opens (its held pages less the lane's promise) and resumes on the adopted pages before the host cache's restore; the pass lives per stream across prefill_step calls, its marks cut the chunks, and it ends ok on finish and not ok on error, cancel and Steps.forget. kv_prompts takes a Query now: .of(s.prompt()). Rebase notes on jschmied's 7e98a79: its hunks in backend.zig's old prefillFn are carried here instead (main moved that loop out in ashhart#3021), its traceLessons move to slide.zig is dropped (main has it in prefill_metal.zig), and metal.zig takes modelContext from cuda_window.zig with metal_shared.zig's copy removed, as the branch's merge of ashhart#2425 did.
… so metal.zig stays within 600 lines With this PR's prompt-page store on today's main, zig/src/native/metal.zig reached 609 lines. ownsQwen27, qwen27Context, Qwen27Budget, qwen27_margin and qwen27Budget move unchanged into metal_qwen27.zig, as main splits metal_admit.zig and metal_spill.zig; metal.zig keeps the same names as aliases, so callers and info's @hasDecl check are unchanged. No behaviour change.
… main git's auto-merge of 'TF_KV_SHARE's prompt pass on main's stepped pass' kept the PR's ops.end(s, false) in retain but main's retain(b, s, at) signature, leaving ops undeclared; both callers pass it again.
…slide Metal host shim exports the pool An untaught stream reads the model as shipped, so a taught prompt's kept state is not one it could reach: its pass neither resumes from the store nor keeps at its marks. test-nemotron-metal-share-host covers a taught prefix then an untaught reuse of it, with a taught control that does resume. test-slide-metal-host's core shim gets kv_pool and kv_prompts, as the drama3 and residency shims have.
…--learn with it is refused A lane host's Disk now names the shared radix store (host.disk.shared) where the family keeps prompts as pool pages: a Sliding Weights step that moves weights clears it as it clears the host cache, a flush drops its states and pages instead of answering 501, and where/load asks read its RAM resume. prompt_radix.Store.clear drops every state and page. The Metal and CUDA hosts set it beside their adapter. TF_KV_SHARE with --learn or --learn-conversations on Nemotron Metal is now refused by name before any load (core kv_prompts.learnRefusal, shared with the CUDA host).
Pass false for the pages argument introduced by TF_KV_SHARE, matching the copied-cache and learned-prompt callers. The temporary learner cache is freed after the snapshot is returned. Add a portable semantic compile check for the actual adapter callbacks so a stale call fails without a GPU or checkpoint.
…ep, as an untaught one does Two memories with one stripped tail build the same placeholder prompt, so one key named both: B could resume A's kept state and its own restore then failed unseen.
…o Bolt's 16-row chunks start on 256-row pages TF_KV_SHARE on Metal Bolt refused every start: its prompt chunk is 16 rows and the store's grid was the chunk itself, which had to be a multiple of the 256-row page. The grid is now the two's least common multiple: 256 for Bolt, still 2,048 for the other Nemotrons. Bolt keeps its 16-row cold passes.
…uest's chunk starts A pass asked the store with its prompt alone, so a request whose starts shift its cold seams off the store's grid (a 2,048-row cap with starts 100, 2148, 4196) could keep and resume at 4,096, a seam its cold pass never has.
…d schedule resumes nonzero on the real store The reviewer's gap: the keep call in Pass.keep had no test, so reverting its starts still passed. Pass.keep now calls Pass.keepInStore, the only store keep call, and a test checks the starts it sends. An aligned schedule keeps its seam at 8 and resumes there, nonzero, from the store and from the imprint ask; the shifted schedule still does not.
The mock store retains each page; the test named pages 0 and 1 without holding them and panicked before its assertion.
…d, so cuda.zig stays within 600 lines
…adix_flush.zig, so prompt_radix.zig stays within 600 lines Store keeps them as declarations of the same names, so every call site reads as before; the bodies are unchanged.
28255a8 to
80efbf0
Compare
Port of #1850 onto main's prefill_metal.zig and prefill_steps.zig: Ops.open begins the store's pass before the cache opens (its held pages less the lane's promise) and resumes on the adopted pages before the host cache's restore; the pass lives per stream across prefill_step calls, its marks cut the chunks, and it ends ok on finish and not ok on error, cancel and Steps.forget. kv_prompts takes a Query now: .of(s.prompt()). Rebase notes on jschmied's 7e98a79: its hunks in backend.zig's old prefillFn are carried here instead (main moved that loop out in #3021), its traceLessons move to slide.zig is dropped (main has it in prefill_metal.zig), and metal.zig takes modelContext from cuda_window.zig with metal_shared.zig's copy removed, as the branch's merge of #2425 did.
|
Thank you @jschmied. 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. |
Head
461d5d4acaanswers the Bolt review: the shared store keeps where a prompt chunk's seam meets a pool page's edge, so Metal Bolt starts withTF_KV_SHAREand keeps its 16-row cold passes.b5cdead663answered the folded-memory review.b7615411d9(main-rebased, with ashhart's three commits) is the base.With
TF_KV_SHARE=n, Nemotron on Metal keeps prompt states in the coreprompt_radixstore over the Nemotron KV pool, as CUDA does since #1756. Unset or 0: the host prompt cache as before.What changes
efc4cdc07: a Metal lane can adopt a kept prompt's pages. The engines'corere-exportstensorfold.kv_pool, so Metal and CUDA use the samePooltype, and main'scuda_prompt_pagesadapter is used as is.875c05684: a kept state holds only Nemotron's Mamba states (Snap.pages). Its attention rows stay in the pool pages a later stream adopts, so a shared prefix is held once.Checks (M3 Pro)
zig build test test-metal-kv-pages test-native: 590/590 steps, 1,312/1,336 tests (24 skipped); contract nemotron: 63 pass gates 1-4 with 1 known finding (main's experts relu2), 29/29 controls red as planted, limits 0 problems.Untaught streams (
22f9a28d6)prompt_pages.zigPass.begin).test-nemotron-metal-share-host(zig/src/nemotron_prompt_pages_test.zig): a taught pass keeps 256 rows, the same prompt untaught adopts no pages, gets no state and no marks, and a taught control does resume at 256. Planted control: with the bypass line removed it fails at line 89 (!u.on); with it, green.test-slide-metal-host: its core shim getskv_poolandkv_prompts, as the drama3 and residency shims. Checked by an aarch64-macos cross analysis of that test (no link): ata2a725b8dit fails oncuda_prompt_pages.zig:8(nokv_prompts), at22f9a28d6it passes.test-slide-metal-host,test-nemotron-metal-share-hostandtest-nemotron-metal-steps-hostpass on22f9a28d6(16/16 steps, 27/27 tests). On the parenta2a725b8d,test-slide-metal-hostfails to compile:cuda_prompt_pages.zig:8:19: root source file struct 'slide-drama-core' has no member named 'kv_prompts'.22f9a28d60(the same code; the head161e74387eonly folds a two-line comment into one): 2449/2449 steps, 24674/24831 tests (157 skipped),check-native-cuda-host compile-cuda-tests17/17,zig fmt --checkclean. Its one finding was that comment (lean 166 vs 165); on161e74387e, lean is 165 vs 165 andpr_checkreports 0 errorsProposed CHANGELOG line: Metal Nemotron:
TF_KV_SHARE=nkeeps prompt states as core pool pages; untaught requests bypass it.Folded memory (
b5cdead663)Pass.beginreturns an empty pass fors.untaught or s.memory_active(zig/src/families/nemotron/prompt_pages.zig). A folded-memory prompt is zeros where the snapshot goes, then the tail, so two memories with one tail share an artificial key; B could resume A's state and then its own restore failure went unseen.two folded-memory streams of one placeholder prompt neither keep nor resume each other's state(zig/src/nemotron_prompt_pages_test.zig): memory A and memory B on the same placeholder prompt; B takes no pages, no pending state, no marks. Control: a plain stream of that prompt resumes at 256.0c94a89dce(forkkvshare-1850c-planted) with the bypass line removed. Red on Linux host: 1 failed, 7/8 passed, on the new test.b5cdead663:test-nemotron-metal-share-host test-nemotron-metal-steps-host test-nemotron-prefill-widths-host test-lane-api-host: 12/12 steps, 828/828 tests.b5cdead663: green (see the follow-up comment 7249478204).b5cdead663(native md5e55fddef) and planted0c94a89dce(md5dc096f55):test-nemotron-metal-share-host test-nemotron-metal-steps-host test-slide-metal-host: 16/16 steps, 34/34 tests.d9d758fb,--slide,TF_NEMOTRON_METAL_KV_PAGES=1, greedy):TF_KV_SHARE=4on the fix, B's reply byte-equals a cold run withoutTF_KV_SHARE(sha256e3cdf831, "9032").TF_KV_SHARE=4, B answers "4417": A's reply byte for byte, in 2.9 s against 10.4 s, so it resumed memory A's state.memory_versionis 2 for A and 4 for B in all three arms.Bolt's 16-row chunks (
6fe3ad937b)kv_prompts.shareGrid(chunk, page)is the two's least common multiple: 256 for Bolt's 16-row chunks, 2,048 as before for the other Nemotrons' 2,048-row chunk.Adapter.openOnGridkeeps the store on it and no longer refuses a chunk off the pages, soerror.ChunkOffPagesis gone. Bolt's chunk stays at 16 rows.Bolt's 16-row chunks keep on the 256-row page grid, a 2,048-row chunk on its own(zig/src/nemotron_prompt_pages_test.zig,test-nemotron-metal-share-host) andBolt's 16-row chunks with the store's marks on the 256-row grid cut as a cold pass(zig/src/families/nemotron/prefill_steps_test.zig,test-nemotron-metal-steps-host): with 16-row chunks over a 600-token prompt, marks at 256 and 512 give exactly the cold pass's chunks and a keep at each.a70e4d1726(forkkvshare-1850d-planted), the grid back to the chunk itself, the old rule.native/metal.zigcallsopenOnGrid; CUDA opens withAdapter.open, which this does not touch.6fe3ad937b:test-nemotron-metal-share-host test-nemotron-metal-steps-host test-nemotron-prefill-widths-host test-lane-api-host test-gemma4-shared-host: 16/16 steps, 836/836 tests.a70e4d1726(the grid back to the chunk): red on the new Bolt geometry test, as required.6fe3ad937b: green (all steps rc=0, lean clean, CUDA host 21/21).3a875d4dc5only moves two comments; host on it:check-native-cuda-hostand the Nemotron share and steps steps, 16/16 steps and 20/20 tests. An earlier head of this commit failed only lean on a two-line comment, now one line.bytebunker/NVIDIA-Nemotron-3.5-Bolt-74B-A9B-MLX-4bit, 43.3 GB) does not fit our M3 Pro (36 GB), and Bolt refuses an M5 by design.Shifted chunk schedules (
555ca0101b,a6b9e90f21,461d5d4aca)Pass.keepInStoreis the one keep call) carry the request's own chunk starts, so a shifted cold schedule keeps and resumes only on its seams. Shared imprint asks use the ask's supplied starts.a pass asks the store with its request's own chunk starts(begin),the keep call site asks with the request's starts(keep, planted red at the starts assertion, on760c501019),a shifted schedule's store marks are its own seams(stepped cuts), andan aligned schedule keeps a seam and resumes there, nonzero(real radix store and imprint ask).461d5d4aca: 26/26 steps, 841/841 tests. Targeted x86 on the same head: green (all steps rc=0).461d5d4acareports no findings.CHANGELOG (Unreleased): Metal Nemotron:
TF_KV_SHARE=nkeeps prompt states as core pool pages, on Bolt too; untaught and folded-memory requests bypass it.