Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25901
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 58c2e52 with merge base be23a26 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
e7f20b5 to
15e60eb
Compare
15e60eb to
c30542f
Compare
|
@claude /pr-review Please review the current head
Changes since the previous head Please focus on: whether serial-only is really the plain path (executor branches, method loading, round structure), the resolver and flag semantics, the cell-cache tree step and retain/resolve invariants, and the strength of the equivalence test. |
|
Claude finished @Gasoonjia's task in 46m 9s —— View job Request Changes: I found no defect in the serial-only PairTree DFlash2 path, but the Detailed reviewPR Review: #25901SummaryThis PR adds PairTree DFlash2 bounded-tree verification for Muse Glimmer on CUDA, made of three pieces: a separate The problems found:
Every changed file was reviewed. The binary API Design
Infrastructure
Testing
Code Quality
RecommendationRequest Changes. Three things block approval:
The ordering of the |
A tree step declares, per token, the step index of its parent, so one forward can verify a tree of speculative continuations per sequence. A root continues its sequence and a child sits one position past its parent. Of the step's own cells, a query attends only its ancestors, never their siblings; history and the sliding window are unchanged. After the forward, retain_tree keeps an accepted root-to-node path per tree and frees every other cell the step claimed. A tree no one retains stays pending until the next verb that changes the table resolves it: each tree keeps its root and the single path below it up to the first branch, so siblings never become history. While a tree is pending, pos() already reports its sequences as that resolution leaves them, so positions a caller derives from it hold for the next step. The DFlash draft layout, whose steps are owner blocks, refuses tree steps. The tests cover sibling isolation, retained paths continuing as history, implicit resolution and pos() while pending, several sequences, windowed layers, branch reclamation, malformed trees and keep sets, and a fuzz of the mask against a brute-force rule. A test-only hook, reached through the shared CellCacheTestPeer test header, makes siblings visible for negative controls; the fuzz runs again with it on and must then catch the leak. Authored with AI assistance (Claude, via Metamate).
A header-only, backend-neutral builder for PairTree DFlash2: from one session's DFlash2 candidate table, it keeps the budget's best proposal prefixes, ranked by the retained unary candidate mass plus the selector's pairwise log-softmax, as the PairTree reference (dflash2_pairwise_k16) does. The greedy walk follows the children the target predicts and returns the target's next token. Tables the reference refuses return no tree, and so do non-finite ones. The unit test checks trees and walks against fixtures produced by the original PairTree code on synthetic tables and on tables recorded from the Muse Glimmer 30B DFlash2 draft. gen_pairtree_reference.py regenerates the fixture from a PairTree checkout (tests/README.md has the command). On a larger sample of 120 synthetic and 60 recorded tables at budgets up to 255, every tree matched except three in synthetic rounds with exact score ties, where float32 reductions accumulated in double order candidates differently within a fraction of an ulp. Authored with AI assistance (Claude, via Metamate).
A Muse Glimmer DFlash2 program exported with --dflash2-pairtree gets a second draft method, draft_forward_pairtree. It takes draft_forward's inputs and returns its candidate ids and scores plus what PairTree DFlash2 weighs each step by: the candidates' unary logits and the full-vocabulary logsumexp, [owners, N, K + 1] float32. draft_forward stays the exact program it is without the flag, so Serial DFlash2 runs the same programs on either export. The extras cannot come from a cheaper method next to an unchanged draft_forward, because they need the draft's full-vocabulary logits, which draft_forward does not return; the second method shares the draft's weights and cache, so the .ptd stores the weights once and only the .pte grows by one compiled draft. The shared draft code offers the method for every backend (DFlashPackedExportModel with pairtree, MuseGlimmerWithDFlash.draft_forward_pairtree); the CUDA exporter writes it. A draft without a candidate selector is refused before anything is traced. resolve_dflash_mode (runtime/dflash_mode.h) is the one place the mode is picked at startup, refusals included; each DFlash executor passes its backend kind and what its program offers. --dflash_serial_only (launcher --dflash-serial-only) runs Serial DFlash2 and refuses a nonzero budget. --dflash_tree_budget (launcher --dflash-tree-budget) sets the PairTree node budget per session and round, zero being Serial DFlash2, and is refused when the program or target cannot serve it. Unset, a program with the PairTree method runs PairTree at the backend's default budget, capped by the widest tree verify: on CUDA 31 for one decode sequence and 15 otherwise, so that up to four owners verify the 64 rows Serial DFlash2 with 15 proposals does (the MLX default, 15, takes effect once MLX supports the method). The decode sequences count logical sessions only, not prefix-cache ones. A program without the method runs Serial DFlash2 and says why. The backend factory refuses only what no backend offers and returns the executor's note: the chosen mode and why, or the resolver's refusal, which the batching runtime prints at startup and adds to its error. The launcher repeats the worker's flag checks to fail before starting it. MuseGlimmerBackendConfig carries the budget, the switch and the decode sequences, and the docs describe the export, the rule and the switch. Until the CUDA executor supports PairTree DFlash2 in a later commit, it accepts these settings and runs Serial DFlash2. Authored with AI assistance (Claude, via Metamate).
The CUDA cell cache derives a tree step's positions from its parents and uploads the tree mask the base cell cache builds. A RawTargetStep with parents runs as a tree step. It must fit one token forward, and its positions, which RoPE reads, must agree with its parents. The executor also reports its widest static forward, the most tokens one forward runs with a logit row for each. Authored with AI assistance (Claude, via Metamate).
In PairTree DFlash2 mode, the CUDA DFlash executor verifies greedy sessions' DFlash2 candidates as one PairTree per session instead of one chain. Their rounds draft with draft_forward_pairtree, which the executor loads only in that mode; its candidate table comes back to the host, the trees of every session in the round run in one target forward, and each session commits the longest path its target's greedy tokens follow plus the next token, keeping that path's KV and hidden rows. The output is the target's greedy continuation, as with Serial DFlash2. In Serial DFlash2 mode, chosen by --dflash_serial_only, a zero budget or a program without the method, the executor neither loads nor runs that method. A round's trees share the widest static target forward, at most 256 rows: each of S sessions gets at most widest / S - 1 nodes and its context's room. Before it resolves the mode, the executor checks what the program offers: draft_forward_pairtree with draft_forward's inputs and outputs plus the candidate logits, tree steps on the target cache, and the row argmax method; a method that does not match counts as missing, so the default falls back to Serial DFlash2 and an explicit budget is refused. The executor returns the mode and why, or the resolver's refusal, as the factory's note, and reports the budget in CudaDFlashStats. Each batch drafts its greedy sessions in tree rounds first and its sampled sessions in Serial DFlash2 rounds with draft_forward after them (logged once). A round in which the builder refuses a table runs Serial DFlash2 as a whole. CudaDFlashStats counts tree and fallback cycles. The CUDA CI job also builds and runs the CPU-only PairTree builder and mode-resolution tests. The tiny test fixtures keep their shapes; the PairTree fixtures are exported in a wider one (static forwards of 1, 4 and 32 tokens, 40-token steps, 1024 cells), each with a plain twin in the same process, so each pair shares its kernel picks; the exporter fails unless every common method is the same compiled library. Serial-only and a zero budget on a PairTree export must be bit-identical to Serial DFlash2 on its twin, on a random and a controlled pair, at 1, 4 and 16 sessions with sampled sessions, a second turn, a rewind and a replaced session: the same tokens, both caches' cells, frontiers and committed hidden rows after every execution, the same stats and target forwards, and the PairTree method never loaded; PairTree mode on the same script must differ. The compiled draft_forward_pairtree must return draft_forward's ids and scores bit for bit, and on a PairTree export of the controlled fixture with its NaN row, a refused table must fall back to Serial DFlash2 and fail only its batch. Packed greedy PairTree sessions decode as Serial DFlash2 and target-only decoding do, up to the random fixture's near-ties, and on the controlled fixture trees accept tokens Serial DFlash2 rejects. Hand-built trees check the committed path tokens, hidden rows and cells with the argmax split over several calls; other cases cover the default budgets and startup notes, one session per round near the context limit, a shared 8-row forward, interleaved greedy and sampled sessions, and refused artifacts and budgets. One target tree step matches each node's path run alone and continues its retained path like the linear sequence; with siblings visible through the cell cache's test hook, that comparison fails. Authored with AI assistance (Claude, via Metamate).
c30542f to
58c2e52
Compare
|
Thanks for the review. Every finding is addressed in the new head
Blocking
Non-blocking
Local tests at this head:
|
|
@claude /pr-review Please review the current head
|
|
Claude finished @Gasoonjia's task in 42m 45s —— View job Re-review of PR Review: #25901SummaryThis PR adds PairTree DFlash2 for Muse Glimmer on CUDA, which verifies bounded drafted trees on the cell KV cache. It brings tree steps in Code Quality
Testing
RecommendationApprove None of these blocks merging. The message fix and the export guard are each a line or two, and the three test gaps can be follow-ups. |
Summary
Partially addresses #23011. A follow-up PR will add PairTree DFlash2 on MLX and will be stacked on this one; the first three commits here are backend-neutral so it can build on them.
Serial DFlash2 proposes one chain of up to 15 draft tokens per round, and the target verifies the chain in one forward. When the target rejects early, most of the chain is wasted. PairTree DFlash2 instead proposes a small tree built from scores the DFlash2 drafter already computes: the selector's pairwise conditional scores, plus the draft's unary top-16 logits and full-vocabulary logsumexp. The target verifies every branch in one forward. The session commits the longest path its greedy tokens follow, plus the next token, and keeps that path's KV and hidden rows. On the RTX 5090, a 16- or 32-row target verify costs the same as the 16-row Serial DFlash2 verify. A tree of that size raises accepted tokens per round at almost constant round time.
Cell KV cache tree steps (backend-neutral).
BatchControlgainssupports_tree_steps,declare_tree_step(seq_ids, parents)andretain_tree(keep), all off by default. Each node sits at its parent's position plus one.retain_treekeeps root-to-node paths and frees every other branch cell.PairTree DFlash2 builder (backend-neutral).
runtime/dflash2_pairtree.his a header-only port of the original PairTree builder and greedy walk (Eliran-Turgeman/pairtree @ b62eb90), with no CUDA dependency. It matches the reference node for node, except that it also refuses non-finite tables. The checked-in fixture comes from the original code, andtests/gen_pairtree_reference.pyregenerates it byte for byte.Export: a separate PairTree draft method (backend-neutral).
--dflash2-pairtreeadds a second draft method,draft_forward_pairtree, next todraft_forward. It takesdraft_forward's inputs and returns its candidate ids and scores plus[owners, N, K + 1]float32: the candidates' unary logits, then the full-vocabulary logsumexp. The method's presence advertises PairTree; there is no extra metadata key.draft_forwardis the same program as in an export without the flag. Returning the extras as a thirddraft_forwardoutput instead changes the draft program's fusion on the 30B export (48 vs 43 kernels indraft_forward), so Serial DFlash2 on a PairTree export would no longer run the plain program.draft_forwarddoes not return, so a cheaper method would have to rerun the draft anyway..ptdis byte-for-byte the same with or without the flag. Only the.ptegrows, by one compiled draft: on the 30B export 106.9 → 115.0 MB (+8.13 MB: an 8.0 MB.soand its 82 KB payload), with the 19.6 GB.ptdbyte-identical and every shared method's.sobyte-identical; export wall time 37:52 → 41:11 and peak RSS 52.3 → 51.4 GB. On the tiny test fixture, 46.4 → 53.2 MB.DFlashPackedExportModel(..., pairtree=True)andMuseGlimmerWithDFlash.draft_forward_pairtree. The CUDA exporter writes the method; the MLX exporter follows in the stacked PR.--dflash2-pairtreewith a draft that has no candidate selector is refused from the draft's config, before anything is traced.draft_forward's, a backend may route every PairTree-mode draft through it; the stacked MLX PR does, because MLX loads each method's weights separately.Runtime switch and default budget (backend-neutral).
resolve_dflash_mode(runtime/dflash_mode.h) picks the mode once at startup, for every backend; each executor passes its backend kind and what the program offers.draft_forward_pairtree, the worker runs PairTree DFlash2 at a per-backend default budget B:--max_decode_sequencesor the logical--max_sessions≤ 1; prefix-cache sessions do not count), otherwise B = 15. A CUDA round holds at most four sessions (the export takes at most four draft owners), and B = 15 verifies the same 64 rows as Serial DFlash2 with N = 15 at four owners (4 × 16). B = 31 at four owners would verify 128 rows, which on the 30B export take the slower > 64-row dequantize path (0.31–0.34× of Serial DFlash2 in the multi-session study).--dflash_tree_budget B(worker) /--dflash-tree-budget B(launcher) sets the budget; 0 runs Serial DFlash2. A nonzero budget is refused at startup when the program lacksdraft_forward_pairtree, the target uses the sequence KV layout, or B + 1 exceeds the widest static forward.--dflash_serial_only/--dflash-serial-only, or a zero budget (the launcher's budget is unset unless given). The executor then never loadsdraft_forward_pairtreeand runs the same methods, copies, rounds and cache steps as on the plain export; its tokens are bit-identical to the plain export's when both were exported with the same kernel picks (see "Serial-only equivalence"). Serial-only with a nonzero budget is refused; with 0 it is accepted.draft_forward_pairtreethat does not have the documented signature counts as none, so the default falls back to Serial DFlash2 and an explicit budget is refused.resolve_dflash_modemakes every mode decision and refusal; the factory refuses only what no backend offers (a budget without CUDA DFlash, serial-only without DFlash) and returns the executor's note. The launcher repeats the worker's flag checks so a bad combination fails before the worker starts.CudaDFlashStats::tree_budgetreports the resolved budget (0 = Serial DFlash2).CUDA.
RawTargetStep.parentscarries the tree; the executor checks that it fits one forward and that RoPE positions agree with the parents.draft_forward_pairtree, loaded lazily and only in PairTree mode. Sampled rounds and drains keepdraft_forward.tree_cyclesandtree_fallback_cycles.draft_forward_pairtree. Its Serial DFlash2 path, shared code included (round grouping,draft(), the cell cache's step and mask, CUDA step positions), took exactly the steps the parent commit's executor takes on the same.ptein the cross-version checks below: the tiny fixtures (local) and the 30B export at 1, 4 and 16 sessions and multi-turn. The static draft methods of original DFlash are never chosen for a tree round.pos()reports its sequences as implicit resolution will leave them (root plus unbranched chain), so positions derived from it agree with the next step's.Prior art. Bounded trees on block drafters are published:
This PR ports the training-free PairTree scoring onto the DFlash2 drafter Muse Glimmer already exports. In the same benchmark harness, ports of DDTree and DForkTree (without its n-gram table) at 32 verify rows reached 1.09× and 1.15× over Serial DFlash2, compared with 1.29× for PairTree DFlash2.
Budgets. Large trees don't pay on this GPU. The Q4_K/Q5_K/Q6_K Triton GEMMs bucket M up to 64 rows:
Hence the defaults: B=31 for one decode sequence and B=15 for two or more.
Results
Setup: RTX 5090, 17G Muse Glimmer 30B Q4_K_M with the DFlash2 Q4_K_M draft. Decoding was greedy, in one process, with configurations interleaved request by request.
These numbers come from the research build this change was extracted from. It used the same cache tree step, CUDA tree verify, builder and walk. Its draft export also carried extra research outputs, which the Serial DFlash2 baseline paid for too. The 30B model was not re-exported with
--dflash2-pairtreeand benchmarked on this branch.Decode throughput per dataset, one session
Round time was 27.7 ms for Serial DFlash2 and 28.0 / 28.2 ms for PairTree DFlash2 B=15 / B=31. PairTree DFlash2 B=31 was faster on 159 of 160 prompts.
MT-Bench acceptance per category
Emitted tokens per round, 10 prompts per category:
The gain is largest where Serial DFlash2 accepts least (writing, stem, humanities) and smallest where it already accepts most (math, extraction).
Context length and concurrency
256 tokens, EOS ignored, paired decode tok/s ratio vs Serial DFlash2:
Host tree build and packing cost 0.05–0.15 ms per round, and commit cost 0.2–0.4 ms. The Serial DFlash2 chain verified through the tree path ran at 0.97–0.99× of Serial DFlash2.
In a prefill-heavy multi-session agent replay (agentx-mini trace shapes, 4–32 concurrent sessions, prefix cache off, up to 256 new tokens per turn), PairTree DFlash2 B = 15 matched Serial DFlash2's system throughput (0.98–1.06× with multi-second engine stalls excluded; all CIs include 1 with them) while accepting 6–8% more tokens per round, and B = 31 was 0.57–0.66× because its four-session rounds verify 101–117 rows. This is why the multi-session default is B = 15.
Serial-only equivalence
--dflash-serial-onlyon a--dflash2-pairtreeexport must be indistinguishable from Serial DFlash2 on the plain export.Within the branch, tiny fixtures (CI,
SerialOnlyRunsThePairTreeExportAsThePlainOne): a random and a controlled (high-acceptance) pair, each exported in one process. 1, 4 and 16 sessions, every third one sampled, then one session closed and replaced, every other one taking a second turn, and then one resubmitted from at least three tokens back. Serial-only and an explicit zero budget on the PairTree export both match Serial DFlash2 on the plain export: identical tokens; identical target and draft cell tables (every cell's position and owners), frontiers, pending tokens and committed hidden rows (BF16 bits) after every execution; identicalCudaDFlashStatsand target forward-method call counts;draft_forward_pairtreenever loaded. PairTree mode on the controlled pair verifies trees and leaves different states, so the comparison tells the modes apart. The controlled pair accepted 10 / 44 / 168 proposals at 1 / 4 / 16 sessions. The.ptdfiles of each pair are byte-identical.Against the parent commit, tiny fixtures (local, not CI): the parent commit's executor (be23a26, built in a separate worktree) and this branch's at its current head, with
--dflash_serial_only, with a zero budget and, on plain exports, by default, ran one script on the same.ptefiles: the plain root fixture at 1 and 4 sessions, and the wide random and controlled pairs, plain and PairTree, at 1, 4 and 16 sessions, with a closed and replaced session, second turns and a rewind. All 16 traces equal the parent's byte for byte: the tokens of every execution; after every execution, each session's frontier, pending token, target and draft positions and committed hidden rows (hash), and both caches' free cells and extents; everyCudaDFlashStatscounter the parent has; and the target forward calls. The parent loads the PairTree exports too and ignores the extra method.Against the parent commit, 30B: the parent's executor (M) and this branch's with
--dflash_serial_only(S) and--dflash_tree_budget 0(Z), on the same plain 30B export. S and Z ran on c30542f (two repeats) and again on 7db33f358d; the current head differs from 7db33f358d only in where a tree-only fallback counter is incremented. All 44 run pairs are bit-identical: tokens, everyCudaDFlashStatscounter, every committed verify logit row's hash, argmax and next token, and the full target and draft cell-cache trace (verb, sequences, positions, cells, free cells, used end). No tree verb ran anddraft_forward_pairtreewas never loaded.Pinning: the export picks kernel variants by timing them on the device: Triton autotune configs of the quantized GEMM and attention kernels, and the split-K launch parameters of
backends/cuda/autotune/launch_params.py. Both caches live only in the Python process (Inductor's own autotune is kept in its on-disk cache). The fixture exporter therefore writes each pair (pairtree/withpairtree/plain/,pairtree/controlled/withpairtree/controlled_plain/) in one process and fails with "pair not pinned" unless every common method is the same compiled library; it flags a PairTree fixture exported in a second process (draft_forwarddiffers). A second export process wrote a different.ptefor the same fixture (its results happened to match on the tiny models); on the 30B export, two export processes differed in 235forward_1kernel launches. Once picks match, the outputs are bit-identical (fixed reduce order, no atomics). Documented intests/README.md.Runtime memory (device memory above the pre-load baseline, MiB, after load / peak, 30B):
Serial-only never loads
draft_forward_pairtree; loading it costs about 262 MiB.30B: the regular export against the PairTree export run with
--dflash_serial_only, both built from this branch's export sources. For this proof only, split-K picks were pinned with a local, test-only record/replay tool that is not part of this PR (66 picks recorded and replayed, none timed), and Triton tile configs through a sharedTRITON_CACHE_AUTOTUNINGcache; the PairTree export recompiled every graph. "Identical" means the same cache-verb sequence with the same cells, positions and free-cell / used-end values after every verb, the same full-vocabulary fp32 hash and argmax of every committed verify logit row, and the same tokens:Serial-only issued no tree verbs. CI pins picks the in-process way
tests/README.mddocuments.Limitations
--max-draft-owners× (B + 1) fits. Each added forward size costs a CUDA-graph pool, and a 256-row forward returns about 200 MB of FP32 logits..pte; the weights are not duplicated.Test plan
Environment: CUDA 13.2, RTX 5090 (SM120), WSL Ubuntu 24.04. GPU runs were repeated until none overlapped another process on the GPU.
cmake --build <build> --target extension_llm_cache_test && ctest -R extension_llm_cache_test.CellCacheTestPeertest header) and must catch the leak in more than a quarter of its trials.muse_glimmer_dflash2_pairtree,muse_glimmer_dflash_mode).ctest -R 'muse_glimmer_dflash2_pairtree|muse_glimmer_dflash_mode|muse_glimmer_batching$|muse_glimmer_sampling'(4/4).python examples/models/muse-glimmer/tests/gen_pairtree_reference.py …reproduces the fixture byte for byte (see tests/README.md).dflash_mode_test(6 tests): the per-backend default (CUDA 31 for one decode sequence, 15 for more; MLX 15), the cap by the widest verify, explicit overrides and range checks, serial-only with an unset or zero budget and its refusal of a nonzero one, programs withoutdraft_forward_pairtree(Serial with the reason; a nonzero budget refused), and targets that cannot verify trees.export_cuda_dflash_tiny.py --dflash2.ET_MUSE_DFLASH_TINY_DIR=… ET_MUSE_DFLASH2_TINY_DIR=… muse_glimmer_cuda_dflash_test.SerialOnlyRunsThePairTreeExportAsThePlainOne): see "Serial-only equivalence" above. Sensitivity check: running the PairTree export in PairTree mode instead of serial-only makes the comparison fail.PairTreeIsTheDefaultOnItsExport): the PairTree export resolves to B = 15 (4 decode sequences) and B = 31 (1), and loadsdraft_forward_pairtree; serial-only and the plain export resolve to Serial DFlash2 and never load it;CudaDFlashStats::tree_budgetand the startup note report each choice; serial-only with B = 15 and B = 15 on the plain export are refused with their reasons in the note.--dflash2-pairtree, sliding window 3): tokens equal target-only exactly. PairTree DFlash2 accepted 30 tokens in 10 cycles; Serial DFlash2 accepted 25 in 15.draft_forward_pairtreereturnsdraft_forward's candidate ids and scores bit for bit (random and controlled fixtures).base + nodeinstead ofbase + 1 + nodemakes the hand-built-tree and controlled tests fail.test_serve_batching+test_export_dflash58 passed;test_cuda_dflash_packed+test_dflash231 passed, 7 skipped.test_cuda_dflash_packedchecks that the PairTree export'sdraft_forwardgraph is identical to the plain one's, thatdraft_forward_pairtreereturns the same ids and scores plus the extras, and that a draft without a selector is refused.test_cuda_dflash2_selection37 passed, 2 skipped.lintrunneron the changed files reports no issues.