mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3783] [Engine] Batch slots on Metal: --batch N rows decode together #4780
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4780
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3783
Author: @catalinb13
Created: 10/23/2026
Status: 🔄 Open
Base:
main← Head:metal-batch📝 Commits (10+)
b158818metal: the request's sampling (the CUDA sampler's chain, on the CPU over the window's head logits)0d6e5batests: tools/metal_sampling_test.py (the request's sampling through --serve: reproducible seeds, picks draw for draw against a reference sampler on the dumped logits, penalties, logit_bias) and metal/tests/engine/host_sampler_parity.cpp3a49b02docs: Mac sampling (MAC.md Sampling: the keys, the order, seeds, the host pick's cost, greedy vs sampled decode)093ed30metal: release prompt scratch buffers before workspace growth02e9f27fix(serve): stop reporting stale cache occupancy after refused parkingb9252edMerge current main and exercise prompt growth without caller autorelease pools9844762conversation cache: --conversation-cache-min-tokens WRITE[,READ] gates parked reads1be9c7dmetal: opt-in fp16-slab expert path (mpp) for streaming prompt chunks1d7f1b5gap harness + attribution rounds 1-4; kprof gate reverted to baselinea9b951bmetal: M1 Max A/B hooks (STRATA_METAL_GEMV_TILE/MOE_TILE/GDN_SCAN); decode copy-overlap on by default on Metal📊 Changes
341 files changed (+53789 additions, -1723 deletions)
View changed files
📝
.gitignore(+3 -0)📝
docs/BATCHING.md(+77 -2)➕
docs/DECODE_2X_PLAN.md(+179 -0)📝
docs/DETAILS.md(+2414 -1196)📝
docs/MAC.md(+257 -238)➕
gap/arms-base.txt(+13 -0)➕
gap/arms-final.txt(+7 -0)➕
gap/arms-kprof.txt(+2 -0)➕
gap/arms-needle.txt(+5 -0)➕
gap/arms-needle2.txt(+7 -0)➕
gap/arms-needle3.txt(+2 -0)➕
gap/arms-profile.txt(+9 -0)➕
gap/arms-round10.txt(+9 -0)➕
gap/arms-round11.txt(+9 -0)➕
gap/arms-round12.txt(+7 -0)➕
gap/arms-round13.txt(+15 -0)➕
gap/arms-round14.txt(+13 -0)➕
gap/arms-round15.txt(+13 -0)➕
gap/arms-round16.txt(+17 -0)➕
gap/arms-round17.txt(+15 -0)...and 80 more files
📄 Description
Closes #3284. This repo's rules ask a feature's scope to be agreed in an issue first; there has been no comment there, so treat this as that proposal — the feature is opt-in, measured, and the whole record is in
docs/BATCHING.md. Happy to discuss scope before merge.Problem
On a Mac the engine answers one request at a time and every other client queues (
docs/MAC.md: "--parallel (batch slots) is not ported"). One person plus their coding agents — a small office — leave the machine between requests at ~2 GB/s of weight reads when the bandwidth is several times that, while the same model on a PC gains multiples by decoding waiting requests together.Result
--batch Non the Metal engine runs N conversations in one window. Measured on an M1 Max (64 GB, Qwen3.8-Flash-Next IQ3_XXS), 21–23 Oct 2026:The interleave cases hold too: a 4888-token prompt reads in while slots decode (126 slot tokens during the read); a read that gives way at a chunk boundary (
YIELDED 2 1024) goes on in its slot; a request stopped part-way in a slot hands back to the solo path and reproduces its solo reply; a next turn reads from its slot's parked state; a prompt chunk cancelled mid-read resumes from its checkpoint (1024 reused + 3866 read). WithSTRATA_BATCH_VERIFY=1the engine byte-compares each slot region's GDN states, QSA cells, tails, dead and pooled rows and PLE history against the window that made them, and reported all match for every region; the per-step kernel captures show each row's folds up to the batched PLE block bit-exact against its solo run.The default path is unchanged: without
--batchthe window builds and runs exactly the commands it did before, and every unit gate passes both ways.Approach
--batchcombines with--conversation-cache-mib: a prompt reads through the main window and is copied into its slot's region before its rows first run.gdn_parity's new plane-row check pins it (it fails with the pre-fix address and passes after).Validation
Revisions and environment. The measurements were made on this fork's Mac line at
783a55fc(the batch commits2d50ea42..783a55fc), M1 Max, 64 GB, macOS 27, Qwen3.8-Flash-Next IQ3_XXS.upstream/mainwas merged into the branch after the runs (merge commit1ff3a385, main at5c8dd322); the post-merge tree rebuilds on this machine, and the merge touches none of the batch code.Passed:
metal/testshost gates on783a55fc(M1 Max, macOS 27):gdn_parity(incl. the new plane-row check and its negative control),gdn_prompt_parity,window_cells_test,host_sampler_parity,runtime_hello,moe_mm_parity,gemv_parity,qsa_parity,buffer_free_test— all green.tools/batch_interleave_test.pyrun twice — prompt reads interleaving with slot decoding, the yield at a chunk boundary, the stop-into-slot hand-back, the parked-state next turn, the mid-read checkpoint resume.STRATA_BATCH_VERIFY=1on the 2- and 4-slot runs — per-slot state byte-compare all match, per-step 315-probe trajectories printed for every row.tools/token_chain.py/tools/prompt_chain.pyon the 47 GB shard (30.5 tok/s, 147 tok/s; the 2-chunk wrap pastmaxBufferLength).--batchabsent match this branch's pre-batch measurements (23–33 tok/s) — the solo path did not regress.Failed:
--batch 4, and three interleave slots across two runs. At every miss both continuations answer their own prompt and the window's logits differ from solo's by the PLE-block noise above, so argmax breaks the tie the other way (the interleave runs print both texts: a colon against a comma, one period,static intagainstint).docs/BATCHING.md's Metal section carries the same doctrine CUDA already ships: token identity of a batched row is luck, coherence and no cross-talk are the contract. With serialized admissions the flips repeat exactly (4 slots: 88 and 13 across independent runs); when prompt reads interleave with decoding, arrival timing changes what each row shares its dispatches with and which slot flips can move between runs.Not run:
src/coreandsrc/programhunks sit inside#if defined(STRATA_GPU_METAL)and the non-Metal bodies are unchanged text, but I cannot certify a build I did not run — CI must.--batch-groupspipelining on Metal, layer split with batch, batch counts past 4 (the regions would not fit 64 GB with the model), multi-day serving under real user load, and vision towers with batch.What is in this branch, honestly
The seven batch commits (
2d50ea42..783a55fc) sit on this fork's Mac line, which upstream has not taken: conversation parking on macOS, the device-flag cut handshake, M1/M2 GEMV speedups, the purge/hash fix, and merges of the still-open #3301, #3527, #3615 and #3333 plus my open #3287 and #2645. That is why the commit list is longer than the feature;upstream/mainis merged into the branch (1ff3a385), so the diff applies cleanly, and the batch changes are marked in the commit subjects. I am happy to rebase onto whichever pieces land first, or to split.Limits
Opt-in and experimental on Macs. No layer split or pipelined groups in a batch window. Each extra slot costs a full per-conversation region in RAM (15.4 GB for four here). The gain is real on this box (up to ~1.7x at two slots) and falls as rows grow; nobody has measured more than four.
How to try it
It starts the engine with
--batch, runs the same prompts alone and together, byte-compares every reply, and refuses to run while another big server holds the memory (see the script's header). For sampled rows add--keys "temperature=0.7 seed=7".🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.