Repository navigation
Conversation
|
Ran it on the M5 Max (macOS 27.2, 128 GB): #3455's head
Sampled rounds now scale with streams, and 4 sampled streams reach about 85% of greedy's aggregate. Greedy is Tokens:
The one-stream code cell gained 15% too. That fits the copy-draft verify rounds we suspected: they drew on the The two local builds aren't bit-for-bit reproducible (two builds of the same tree gave different binary hashes), |
bcdafbc to
c046cce
Compare
c046cce to
7ee2ac2
Compare
…whole row (#3396) gpu_rule.sample sorted every logit of the row to keep at most 1,024 candidates, and gpu_full.plan sorted it for one place and the first 1,024. Both now take the same candidates by selection: a bounded heap for the first n, sorted, and a quickselect for place top_k - 1. rule.better is a strict total order over key bits then id, so each is the full sort's own answer and every draw keeps its token. The normalizer over the whole row is now summed only when top_k is 0, the one case that reads it. On a 150,144-token row (the host test, ReleaseFast), a top_k 20 draw takes 0.45 ms instead of 17 ms, and a top_k 0 draw 40 ms instead of 55 ms. Every host draw through gpu_rule or gpu_full gets this, among them Flint's shared rounds. test-gpu-draw-host checks every pick, plan and place against main's full sort, kept in the test, across spread, tied, signed-zero, NaN and infinity and masked rows, top_k 0/1/1023-1025/len/past len, top_p 0/0.5/0.95/1, min_p 0/0.05/0.6, four temperatures and an id map. A control that breaks ties the other way is caught.
Keep the old planner and its helpers in a test-only snapshot. Reject a dropped top-p cut with the same plan comparison used by the parity grid.
7ee2ac2 to
f75f4e4
Compare
What this changes
When two or more streams share a round, Flint draws every row's token on the CPU through
lanes.gpu_full.draw. Fortop_k1 to 1,024 that callsgpu_rule.sample, which sorted all 150,144 logits of the row to keep at most 1,024candidates. For
top_k0 or above 1,024,gpu_full.plansorted the whole row too, for one place (top_k - 1) and,under
top_p, the first 1,024. #3396 measured the cost: sampled shared rounds 3.4 times longer at two streams and 6.4at four, while greedy rows (one pass for the largest) scaled.
Both functions now take the same candidates without the full sort:
gpu_select.top: a bounded heap keeps the bestn(at most 1,024) in one pass, then sorts only those.gpu_select.nth: a quickselect finds placetop_k - 1fortop_kabove the 1,024 candidates (median of three,falling back to a sort of the remaining range after
2 log2(n) + 4partitions).gpu_rule.samplesums the normalizer over the whole row only whentop_kis 0, the one case that reads it.Exact by construction.
rule.betteris a strict total order: the key bits of the value (a bijection over everyf32, NaN and infinities included), then the lower id. So the heap's first
nand the quickselect's place are thefull sort's own candidates, bit for bit, and every draw keeps its token. No switch: nothing to turn on or off.
Every host draw through
gpu_ruleorgpu_fullgets this, not only Flint's shared rounds: MiniMax M3's and oneother Metal family's shared rounds, Kimi K3, Llama, and Flash Next's grammar draws.
Checks
zig build test-gpu-draw-host(new): runs thegpu draw:tests in Debug and in ReleaseFast. 16 of 16 pass ineach.
refSample,refPlan, thereference sort).
rows that are mostly −inf (masked).
top_k0, 1, 2, 20, 1,023, 1,024, 1,025, len−1, len, len+5 and the u32 maximum;top_p0, 0.5,0.95 and 1;
min_p0, 0.05 and 0.6; temperatures 1e−7, 0.3, 1 and 2.5; a seed per row; positions varied;every third draw through an id map.
gpu_rule.sample,gpu_full.draw, andgpu_full.planbyte for byte. Any differencefails.
topandnthequal the full sort's firstnand its placek, byte for byte, on shuffled input.betterfails both the pick and the place tests.zig fmt --checkis clean. The new and changed files are at most232 lines.
test-shared-lane-regressions-hostandtest-cuda-host: see below.Timing
From the timing test in
test-gpu-draw-host: one row of 150,144 spread logits, temperature 1,top_p0.95. Eachfigure is the median ns per draw, main's code against this change, in the same binary. Two runs agreed within 1%.
top_k20 (Flint's default)top_k0 (full vocabulary)top_k0 still makes its full-row passes (mass,race), which this change doesn't touch. Only its sort is gone.Not run
is for Flint on M5 Max: sampled requests lose throughput at 2 and 4 streams (greedy scales) #3396's author to measure with
flint_streams.py, main against this change.Checklist
check (at least twice as fast) fails, because both sides are the same sort; the mutation and the planted control
fail the equality tests. They need no GPU.