Skip to content

[CUDA] PairTree DFlash2: bounded-tree verification for Muse Glimmer - #25901

Draft
Gasoonjia wants to merge 5 commits into
mainfrom
gasoonjia/pairtree-dflash2-cuda
Draft

Gasoonjia wants to merge 5 commits into
mainfrom
gasoonjia/pairtree-dflash2-cuda

Conversation

@Gasoonjia

@Gasoonjia Gasoonjia commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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).

  • Declaring a tree: BatchControl gains supports_tree_steps, declare_tree_step(seq_ids, parents) and retain_tree(keep), all off by default. Each node sits at its parent's position plus one.
  • Masks: a node sees its sequence's committed history, with the sliding window applied, and its own in-step ancestors. It never sees siblings, cousins or another sequence's tree.
  • Retain: retain_tree keeps root-to-node paths and frees every other branch cell.
  • Rejected inputs: malformed parents and keep sets, including repeated indices; a refused keep set changes nothing.
  • Implicit resolution: a tree that is never retained is resolved by the next operation that changes the cache. That keeps only the root and the single path below it, up to the first branch, so siblings never become history.
  • Draft cache: the DFlash draft cache refuses tree steps.

PairTree DFlash2 builder (backend-neutral). runtime/dflash2_pairtree.h is 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, and tests/gen_pairtree_reference.py regenerates it byte for byte.

Export: a separate PairTree draft method (backend-neutral).

  • --dflash2-pairtree adds a second draft method, draft_forward_pairtree, next to draft_forward. It takes draft_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_forward is the same program as in an export without the flag. Returning the extras as a third draft_forward output instead changes the draft program's fusion on the 30B export (48 vs 43 kernels in draft_forward), so Serial DFlash2 on a PairTree export would no longer run the plain program.
  • Why a full method rather than an extras-only one: the extras need the draft's full-vocabulary logits, which draft_forward does not return, so a cheaper method would have to rerun the draft anyway.
  • Cost: both methods share the draft's weights and KV cache. The CUDA backend stores every weight once per program, so the .ptd is byte-for-byte the same with or without the flag. Only the .pte grows, by one compiled draft: on the 30B export 106.9 → 115.0 MB (+8.13 MB: an 8.0 MB .so and its 82 KB payload), with the 19.6 GB .ptd byte-identical and every shared method's .so byte-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.
  • Shared model code: DFlashPackedExportModel(..., pairtree=True) and MuseGlimmerWithDFlash.draft_forward_pairtree. The CUDA exporter writes the method; the MLX exporter follows in the stacked PR. --dflash2-pairtree with a draft that has no candidate selector is refused from the draft's config, before anything is traced.
  • Since the method's first two outputs are exactly 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.
  • Default: on a program with draft_forward_pairtree, the worker runs PairTree DFlash2 at a per-backend default budget B:
    • CUDA: B = 31 when the worker decodes at most one sequence at a time (--max_decode_sequences or 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).
    • MLX: the resolver's MLX default is B = 15; it takes effect in the stacked MLX PR.
    • The default is capped by the widest static target forward.
  • Override: --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 lacks draft_forward_pairtree, the target uses the sequence KV layout, or B + 1 exceeds the widest static forward.
  • Keeping Serial DFlash2 on a PairTree export: pass --dflash_serial_only / --dflash-serial-only, or a zero budget (the launcher's budget is unset unless given). The executor then never loads draft_forward_pairtree and 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.
  • Programs without the method run Serial DFlash2 and say why; a draft_forward_pairtree that does not have the documented signature counts as none, so the default falls back to Serial DFlash2 and an explicit budget is refused.
  • One owner of the policy: resolve_dflash_mode makes 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.
  • Reporting: the backend factory returns the chosen mode, budget and reason, or the refusal's reason, as a note; the batching runtime prints it to stderr at startup and appends it to its startup error, so release builds show it too. CudaDFlashStats::tree_budget reports the resolved budget (0 = Serial DFlash2).

CUDA.

  • Cache and executor: the CUDA cell cache takes positions from tree depth. RawTargetStep.parents carries the tree; the executor checks that it fits one forward and that RoPE positions agree with the parents.
  • Verify cap: 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, also capped by its remaining context.
  • Draft methods: tree rounds draft with draft_forward_pairtree, loaded lazily and only in PairTree mode. Sampled rounds and drains keep draft_forward.
  • Sampled sessions: PairTree DFlash2 is greedy-only. Each batch drafts its greedy sessions in tree rounds first, then runs its sampled sessions in Serial DFlash2 rounds; this is logged once.
  • Builder refusal: if the builder refuses a candidate table, that round falls back to Serial DFlash2.
  • Stats: both fallbacks are counted in tree_cycles and tree_fallback_cycles.
  • Serial DFlash2: in Serial mode the executor never loads or runs 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 .pte in 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.
  • Cache contract: while a tree is pending, 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:

  • DDTree (Ringel & Romano, arXiv 2604.12989);
  • PairTree (E. Turgeman, blog post 2026-11-16, https://github.com/Eliran-Turgeman/pairtree);
  • DForkTree (arXiv 2611.12356);
  • DominoTree (Lin & Jang, arXiv 2607.08642), the published form of path-dependent tree scoring. It scores a DDTree-style heap with a trained Domino drafter (GRU plus low-rank correction). No Domino drafter exists for Muse Glimmer.

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:

  • a 64-row verify costs 1.6–1.8× a 32-row one;
  • above 64 rows the GEMMs fall back to dequantize plus bf16 matmul, at about 7×;
  • PairTree DFlash2 at B=63 accepts the most tokens per round but loses 5–8% end to end.

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-pairtree and benchmarked on this branch.

Decode throughput per dataset, one session

  • Prompts: 160 in total: MT-Bench turn 1 (80), GSM8K test[:40] and HumanEval test[:40]. Formatting follows the z-lab/dflash benchmark @07ebd93 plus the Muse Glimmer chat template.
  • Stopping: at EOS or 512 tokens.
  • Throughput: decode tok/s = Σ(completion tokens − 1) / Σ speculation-round time.
  • Ratios: paired against Serial DFlash2 on the same prompts, with 95% bootstrap CIs over prompts.
dataset Serial DFlash2 tok/s PairTree DFlash2 B=15 tok/s (ratio) PairTree DFlash2 B=31 tok/s (ratio) tokens/round: Serial / B=15 / B=31
MT-Bench (80) 155 185 (1.194 [1.173, 1.213]) 204 (1.316 [1.290, 1.345]) 4.29 / 5.16 / 5.73
GSM8K (40) 233 264 (1.134 [1.107, 1.161]) 292 (1.256 [1.217, 1.297]) 6.46 / 7.39 / 8.24
HumanEval (40) 211 240 (1.134 [1.112, 1.157]) 263 (1.241 [1.209, 1.273]) 5.90 / 6.77 / 7.48
All 160 (time-weighted) 181 212 (1.170 [1.155, 1.185]) 233 (1.288 [1.267, 1.309]) 5.02 / 5.93 / 6.57

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:

category Serial DFlash2 PairTree DFlash2 B=15 PairTree DFlash2 B=31 B=31 decode tok/s ratio
writing 3.47 4.28 4.63 1.33
roleplay 3.87 4.65 5.26 1.33
reasoning 4.79 5.69 6.67 1.37
math 6.77 7.54 8.24 1.20
coding 4.72 5.61 6.22 1.30
extraction 6.76 8.02 8.86 1.30
stem 3.58 4.39 4.95 1.36
humanities 3.27 3.96 4.29 1.29

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:

setting best budget ratio [95% CI] tokens/round: Serial → PairTree
one session, short prompts B=31 1.246 [1.06, 1.49] 3.88 → 5.33
one session, ~3.6K-token prompts (past the 2048-token sliding window) B=31 1.239 [1.15, 1.37] 4.10 → 5.10
two sessions B=15 1.182 [1.12, 1.25] 3.98 → 4.81
four sessions B=15 1.108 [1.02, 1.18] 3.91 → 4.66

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-only on a --dflash2-pairtree export 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; identical CudaDFlashStats and target forward-method call counts; draft_forward_pairtree never 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 .ptd files 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 .pte files: 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; every CudaDFlashStats counter 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, every CudaDFlashStats counter, 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 and draft_forward_pairtree was never loaded.

    workload cache verbs / run rows hashed sequences cycles / proposed / accepted M vs S, M vs Z, S vs Z
    1 session 108 135 1 17 / 255 / 118 identical
    4 sessions 220 531 4 64 / 960 / 467 identical
    16 sessions 880 2,140 16 259 / 3,885 / 1,881 identical
    multi-turn (close / open, rewind + new suffix, resume) 195 411 6 47 / 705 / 364 identical
  • 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/ with pairtree/plain/, pairtree/controlled/ with pairtree/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_forward differs). A second export process wrote a different .pte for the same fixture (its results happened to match on the tiny models); on the 30B export, two export processes differed in 235 forward_1 kernel launches. Once picks match, the outputs are bit-identical (fixed reduce order, no atomics). Documented in tests/README.md.

  • Runtime memory (device memory above the pre-load baseline, MiB, after load / peak, 30B):

    regular PairTree, serial-only PairTree, default
    4 sessions 20,008 / 22,852 20,008 / 22,852 20,270 / 23,114 (B = 15)
    1 session 20,008 / 22,048–22,080 20,008 / 22,080 20,270 / 22,344 (B = 31)

    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 shared TRITON_CACHE_AUTOTUNING cache; 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:

    scenario cache verbs (target + draft) committed rows hashed sequences serial-only vs regular repeat vs repeat
    1 session 108 135 1 identical identical
    4 sessions 220 531 4 identical identical
    16 sessions 880 2,140 16 identical identical
    multi-turn (close / open, rewind + new suffix, resume, idle pause) 195 411 6 identical identical

    Serial-only issued no tree verbs. CI pins picks the in-process way tests/README.md documents.

Limitations

  • Greedy-only. Sampled sessions run Serial DFlash2. If the builder refuses one session's table, its whole round falls back to Serial DFlash2.
  • Tree size cap. Tree size is bounded by the widest exported static forward (at most 256 rows). Every session gets the full budget only if --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.
  • Throughput above 32–64 rows. On this GPU, throughput drops once a round verifies more than 32–64 rows, because of the quantized GEMM buckets.
  • PairTree is not bit-identical to Serial DFlash2. Outputs can diverge at bf16 near-ties, because rows are recomputed in forwards of different widths. Serial DFlash2 is not bit-identical to target-only greedy decoding either. (Serial-only is bit-identical to Serial DFlash2 with the same kernel picks; see above.)
    • On the 30B model, every examined first divergence had |Δlogit| ≤ 0.44, below the 16- vs 32-row recomputation noise.
    • On the 30B GPU mask test, a 32-row tree step matched every root-to-leaf chain within 0.27 logits, with 0/81 argmax mismatches. With siblings made visible, it differed by up to 21.5 logits.
  • Export size. A PairTree export carries one more compiled draft method in the .pte; the weights are not duplicated.
  • Candidate-table copies. The candidate table comes back to the host in three device-to-host copies per round.
  • HF card numbers. The HF card reports DFlash2 acceptance of 6.57 / 5.66 / 4.42 on GSM8K / HumanEval / MT-Bench. Those runs used temperature 1.0, an H200 with SGLang and 4096 tokens, so they are not comparable to these greedy, 512-token numbers.

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.

  • Cell cache, CPU. 73/73 passed, including 12 tree tests.
    • Command: cmake --build <build> --target extension_llm_cache_test && ctest -R extension_llm_cache_test.
    • Coverage: sibling and cousin isolation, multiple sessions with uneven history, the sliding-window crossing, retain and branch reclamation, malformed parents and keep sets (including repeated indices, which change nothing), stale and implicitly resolved trees, the DFlash draft cache refusal, and a mask fuzz test against a brute-force reference over thousands of random forests.
    • Negative control: the fuzz runs again with the test-only sibling-leak hook on (shared CellCacheTestPeer test header) and must catch the leak in more than a quarter of its trials.
  • PairTree builder and mode resolution. All tests passed; the CUDA CI job now builds and runs both (muse_glimmer_dflash2_pairtree, muse_glimmer_dflash_mode).
    • Command: ctest -R 'muse_glimmer_dflash2_pairtree|muse_glimmer_dflash_mode|muse_glimmer_batching$|muse_glimmer_sampling' (4/4).
    • Fixture parity: the checked-in fixture matches the original PairTree code node for node.
    • Wider sample: 60 real Muse Glimmer rounds and 160 synthetic tables, at budgets up to 255. All trees match except 3 synthetic rounds with exact score ties, which have the same node set in a different order.
    • Regeneration: 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 without draft_forward_pairtree (Serial with the reason; a nonzero budget refused), and targets that cannot verify trees.
  • Native CUDA DFlash. 41/41 passed, on fixtures exported from scratch with export_cuda_dflash_tiny.py --dflash2.
    • Command: ET_MUSE_DFLASH_TINY_DIR=… ET_MUSE_DFLASH2_TINY_DIR=… muse_glimmer_cuda_dflash_test.
    • Serial-only equivalence (SerialOnlyRunsThePairTreeExportAsThePlainOne): see "Serial-only equivalence" above. Sensitivity check: running the PairTree export in PairTree mode instead of serial-only makes the comparison fail.
    • Default mode (PairTreeIsTheDefaultOnItsExport): the PairTree export resolves to B = 15 (4 decode sequences) and B = 31 (1), and loads draft_forward_pairtree; serial-only and the plain export resolve to Serial DFlash2 and never load it; CudaDFlashStats::tree_budget and 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.
    • Tree vs serial: on the random tiny fixture, PairTree DFlash2 matches Serial DFlash2 and target-only greedy for two sessions at budgets 1, 4 and 15. Every emitted token is checked teacher-forced against a target-only forward: it must be the argmax or within 4 bf16 ulps of it. Only one near-tie occurred, about 3 ulps.
    • Controlled fixture (exported with --dflash2-pairtree, sliding window 3): tokens equal target-only exactly. PairTree DFlash2 accepted 30 tokens in 10 cycles; Serial DFlash2 accepted 25 in 15.
    • Hand-built trees: a decoy sibling and nephew at each depth. The test checks path tokens, hidden rows against a linear forward, cache positions and continuation, with the argmax forced into 3-row chunks.
    • Context room: one session at budget 31 hits the cap near the end of its context.
    • Shared forward: two sessions share an 8-row forward.
    • Mixed batches: greedy sessions get trees and sampled sessions fall back.
    • Startup refusals are covered.
    • Compiled methods: on the same inputs and draft cache, draft_forward_pairtree returns draft_forward's candidate ids and scores bit for bit (random and controlled fixtures).
    • Builder refusal: on a PairTree export of the controlled fixture with its NaN row, the round with the NaN falls back to Serial DFlash2 (2 fallback cycles, no tree cycle) and fails only its batch, exactly as Serial DFlash2 on the same export does; later sessions run normally.
    • Tree step vs path alone: one tree step matches each node's path run alone, with 0 logits beyond rounding. With siblings visible, 2,224,571 logits differ beyond rounding and there are 12 argmax mismatches.
    • Mutation check: reading hidden rows from base + node instead of base + 1 + node makes the hand-built-tree and controlled tests fail.
  • Python.
    • CPU: test_serve_batching + test_export_dflash 58 passed; test_cuda_dflash_packed + test_dflash2 31 passed, 7 skipped. test_cuda_dflash_packed checks that the PairTree export's draft_forward graph is identical to the plain one's, that draft_forward_pairtree returns the same ids and scores plus the extras, and that a draft without a selector is refused.
    • GPU: those suites plus test_cuda_dflash2_selection 37 passed, 2 skipped.
  • Lint. lintrunner on the changed files reports no issues.
  • 30B correctness (research build, same algorithm). Results are in the Limitations section above: the GPU mask test, near-tie divergence probes, and reference parity on 584 real rounds.
  • 30B serial-only equivalence. Identical at 1, 4 and 16 sessions and multi-turn; see "Serial-only equivalence".

@pytorch-bot

pytorch-bot Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🔗 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 Failures

As of commit 58c2e52 with merge base be23a26 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

@claude /pr-review

Please review the current head c30542f4db against main be23a26276. Five commits; the first three are backend-neutral (a stacked MLX PR builds on them):

  • 382516c2a8 Add tree steps to the cell KV cache
  • 249830cfc0 Add the PairTree DFlash2 tree builder for Muse Glimmer
  • 372c172d2b Plumb the PairTree DFlash2 option and export its draft method
  • 4ae617376b [CUDA] Run tree steps on the CUDA cell KV cache
  • c30542f4db [CUDA] Support PairTree DFlash2 for Muse Glimmer

Changes since the previous head 15e60eb8e3: PairTree is now switchable at runtime on one export. --dflash2-pairtree exports draft_forward unchanged plus a separate draft_forward_pairtree. --dflash-serial-only (worker --dflash_serial_only) runs exactly the plain Serial DFlash2 path and never loads the PairTree method. Without it, the default budget comes from one resolver (runtime/dflash_mode.h): CUDA B = 31 for at most one decode sequence, otherwise B = 15; MLX 15. A new native test checks serial-only against the plain export bit for bit on one-process fixture pairs. The PR body has the 30B equivalence results.

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

claude Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

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 --max_decode_sequences clamp contradicts the documented B = 31 default, the new resolver and builder tests never run in OSS CI, and the bit-for-bit equivalence test only compares this branch with itself.

Detailed review

PR Review: #25901

Summary

This PR adds PairTree DFlash2 bounded-tree verification for Muse Glimmer on CUDA, made of three pieces: a separate draft_forward_pairtree method on the same export, a runtime mode resolver, and tree steps in the shared cell KV cache. I found no defect in the serial-only path: method loading, round structure, temperature gating and the non-tree cache paths all checked out.

The problems found:

  • a flag mapping that contradicts the documented default budget;
  • two new test targets that no OSS CI job runs;
  • an equivalence test that cannot support the "same steps as before" claim;
  • an ABI-check ordering that turns a mismatched optional method into a startup failure;
  • a latent pos() hazard in the new BatchControl tree contract;
  • a test-only switch in the production CellCache.

Every changed file was reviewed. The binary tests/data/pairtree_reference.bin was checked only through its generator and its reader.

API Design

  • The --max_decode_sequences clamp counts physical slots, so --max_sessions 1 does not give the documented B = 31.

    • batching_bootstrap.cpp:153-154 sets backend.max_decode_sequences = std::min(FLAGS_max_decode_sequences, backend.max_sessions). But backend.max_sessions is physical (lines 122–124 and 141), which also counts --prefix_cache_entries and the resolved prefix captures.
    • Trigger: --max_sessions 1 --prefix_cache_entries 4 with the default --max_decode_sequences 4 gives min(4, 5) = 4, so the resolver picks B = 15.
    • This contradicts BATCHING_SERVING.md:138-139 ("B = 31 when it decodes one sequence at a time (--max_decode_sequences 1 or --max_sessions 1)") and README.md:331.
    • Prefix-cache entries never decode, so the bound should be FLAGS_max_sessions.
    • No test covers the flag-to-config mapping, because the native tests call executor.execute directly.

    Fix this →

  • A mismatched draft_forward_pairtree fails startup with InvalidProgram on the default path, instead of falling back to Serial.

    • The order is wrong. cuda_dflash_executor.cpp:704 sets capability.pairtree_method from the method name alone. resolve_dflash_mode (708–713) then picks a nonzero default budget. Only after that do the input/output, candidate-logits and argmax checks (739–773) run, and they return InvalidProgram.
    • The note written ahead of time at 734–737 and cleared at 774–776 exists only to work around this order.
    • Trigger: any .pte whose draft_forward_pairtree or argmax method fails those checks, launched without --dflash_tree_budget. The worker refuses to start. For a program that lacks the method entirely, the resolver's rule for an unrequested budget is "Serial with a reason".
    • Fix: fold these checks into capability.pairtree_method / tree_verify before resolving. An explicit budget still fails and the default falls back. If a present but mismatched method is meant to be fatal, document that instead.

    Fix this →

  • (Latent; shared BatchControl contract) While a tree is pending, pos() is not where the next step lands, and CudaExecutor validates against it.

    • cache.h:163-164 says positions are meaningful only once the tree is retained or resolved. But resolution is private (resolve_tree) and happens only as a side effect of the next verb.
    • CudaExecutor::execute_raw checks tree roots against ctl_->pos() (cuda_executor.cpp:710-720) before declare_tree_step (768–770) resolves the pending tree and moves pos(). CudaCellCache::prepare_step then derives positions from the post-resolution CellCache::pos (cuda_kv_cache.cpp:494-506), while RoPE uses the caller's step.positions.
    • Effect with an unretained tree: a root at the resolved position is refused. A root at the stale deepest-node position passes; the cache places it at the resolved position while RoPE rotates it for the stale one, with no error. Plain steps go the same way with no position check at all.
    • This PR's executor always retains or fails, so nothing reaches this today. The stacked MLX PR builds on the contract, though.
    • The contract text is also inaccurate:
      • cache.h:157-158 lists abandon_step, which is not a BatchControl method.
      • A declare_tree_step refused for malformed parents returns before resolving (cell_cache.cpp:97-114). One refused later has already resolved through CellCache::declare_step (line 58).
      • cell_cache.h:110-113 ("Does nothing without a placed step") is stale, since abandon_step now resolves a pending tree (cell_cache.cpp:336-339).
    • Fix, either way: make the pending tree explicit state (other verbs refuse until retain_tree), or check positions after declare_tree_step in CudaExecutor. Then correct the comments.

    Fix this →

Infrastructure

  • The new muse_glimmer_dflash2_pairtree and muse_glimmer_dflash_mode tests never run in OSS CI. CMakeLists.txt:368-395 registers them, but no OSS CI job builds or runs them:

    Where What it builds What it runs
    cuda.yml:704-707 muse_glimmer_batching_test muse_glimmer_cuda_dflash_test -R '^muse_glimmer_batching$'
    mlx.yml:385-390 muse_glimmer_batching_test muse_glimmer_mlx_dflash_test sampling_test `'^muse_glimmer_(batching
    build_muse_glimmer_batching_smoke.sh:14 the smoke binary only —

    As a result, the C++ builder is never compared against pairtree_reference.bin, and the resolver's unit tests run only through the BUCK targets.

    • Fix: both tests are CPU-only. Add both executables to the --target lists and widen the regex, e.g. '^muse_glimmer_(batching|dflash2_pairtree|dflash_mode)$'.

    Fix this →

Testing

  • The bit-for-bit check compares this branch with itself.

    • SerialOnlyRunsThePairTreeExportAsThePlainOne (cuda_dflash_native_test.cpp:1436-1506) runs the plain and the PairTree exports through this branch's executor, cell cache and exporter. That shows serial-only equals plain on this branch.
    • It does not back the PR body's claim that "in Serial mode the executor takes exactly the steps it took before this change (verified bit for bit)". This PR changes the shared Serial path (speculate_rounds(false), draft(…, nullptr), CellCache::declare_step / build_mask, CudaCellCache::prepare_step), and any such change moves both sides of the comparison together.
    • The 30B comparison has the same limit ("both built from this branch's export sources").
    • Fix: run be23a26276's worker and this branch's --dflash_serial_only worker on one .pte exported from main, and compare tokens and stats. Otherwise, narrow the claim to what the test shows.
  • The builder-refusal fallback is untested.

    • What the code does: when pairtree::build returns no nodes for an owner, the whole round falls back (cuda_dflash_executor.cpp:1419-1425, counted at 1599–1601). It then samples kDFlash2Sample from draft_forward_pairtree's outputs (1433–1434).
    • Why nothing reaches it: the tree_fallback_cycles assertions at cuda_dflash_native_test.cpp:1011/1018/1045 count only sampled sessions (line 1578), and the wide controlled fixture no longer sets the NaN (export_cuda_dflash_tiny.py, if not wide). That includes the mixed case the comment at 1420–1422 describes.
    • The fallback also assumes draft_forward_pairtree's outputs match draft_forward's. That is checked only in eager mode, at the default assert_close tolerance (test_cuda_dflash_packed.py), never on the compiled methods.
    • Possible coverage: a PairTree export of the NaN-carrying controlled fixture, with a session anchored at 9 next to a healthy one.
  • (Minor) The existing root --dflash2 fixture changed shape.

    • export_dflash2 now always exports forward_sizes=(1, 4, 32), max_step_tokens=40 and max_cells=1024, previously (1, 4) / 32 / 512. This applies to every export, not only pairtree/.
    • Consequence: through export_solo.py:541-565, the existing DFlash2 tests on that fixture now send 5–32-token steps to the padded static forward_32 instead of the dynamic forward_others, which loses coverage there.
    • The module docstring still attributes the 32-token static forward to pairtree/.
    • Fix: give export_dflash2 the same wide switch as export_controlled_dflash2.

    Fix this →

Code Quality

  • A test-only switch lives in the production CellCache.

    • cell_cache.h:197-199 adds tree_siblings_visible_, and line 178 adds friend struct CellCacheTestPeer. build_mask branches on the switch for every in-step cell of a tree step (cell_cache.cpp:504-507).
    • CellCacheTestPeer is defined twice, with different members: cell_cache_tree_test.cpp:17-23 and cuda_dflash_native_test.cpp:42-57. The second one also reads the private pos_ / owners_.
    • The PR body says the hook "makes the fuzz test fail", but MaskFuzzMatchesBruteForce (cell_cache_tree_test.cpp:341-440) never enables it. Only the single-bit VisibleSiblingsTestHookLeaks (327–336) does, so the fuzz test's negative control is a manual run.
    • Fix: inject the leaky rule from the test side if you can. If the switch stays, define the peer once in a shared test header, and add fuzz trials with the switch on that are expected to fail.
  • (Minor) The mode policy is split across three layers.

    • The launcher (serve_batching.py:161-163), the factory (backend_factory.cpp:31-34) and resolve_dflash_mode (dflash_mode.h:69) each refuse serial-only with a nonzero budget.
    • The factory runs first, so on the worker path the resolver's branch is never reached, and users get the factory's message rather than the resolver's reason. That conflicts with the "one resolver" design.
    • The launcher also re-implements the CUDA-only check and pairtree::kMaxRows (_MAX_TREE_ROWS, line 49).
    • DFlashModeRequest::max_decode_sequences defaults to 1 (dflash_mode.h:40), while MuseGlimmerBackendConfig defaults to 4 (backend_factory.h:36). A request built without the field therefore resolves to the single-sequence B = 31.
    • Fix: let the resolver own the refusals and have the factory forward its reason. Drop the request default, or match the config's.

Recommendation

Request Changes. Three things block approval:

  • Flag clamp: the max_decode_sequences clamp contradicts the documented default.
  • CI: the new resolver and builder tests never run in OSS CI.
  • Equivalence claim: "the same steps as before, bit for bit" needs a run against the previous version, or a narrower claim.

The ordering of the draft_forward_pairtree ABI checks, the test hook and the minor items need not block. The latent pos() hazard and the inaccurate BatchControl wording should be fixed before the stacked MLX PR relies on that contract.

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).
@Gasoonjia
Gasoonjia deployed to upload-benchmark-results December 3, 2026 06:32 — with GitHub Actions Active
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).
@Gasoonjia
Gasoonjia force-pushed the gasoonjia/pairtree-dflash2-cuda branch from c30542f to 58c2e52 Compare December 3, 2026 11:30
@Gasoonjia

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Every finding is addressed in the new head 58c2e5236b, rebased on the same main be23a26276. Commits:

  • 2870cb29bf Add tree steps to the cell KV cache
  • 3a3bcb4679 Add the PairTree DFlash2 tree builder for Muse Glimmer
  • 49d4482b07 Plumb the PairTree DFlash2 option and export its draft method
  • 5bbd1a2258 [CUDA] Run tree steps on the CUDA cell KV cache
  • 58c2e5236b [CUDA] Support PairTree DFlash2 for Muse Glimmer

Blocking

  1. --max_decode_sequences clamp: fixed. New dflash_decode_sequences(max_decode_sequences, logical_sessions) in runtime/dflash_mode.h. The bootstrap calls it with FLAGS_max_sessions, not the physical slot count, so prefix-cache entries and captures no longer count. --max_sessions 1 --prefix_cache_entries 4 now resolves to B = 31. Test: DecodeSequencesCountLogicalSessions.
  2. New tests not in OSS CI: fixed for CUDA. cuda.yml now builds muse_glimmer_dflash2_pairtree_test and muse_glimmer_dflash_mode_test, and its ctest regex is ^muse_glimmer_(batching|dflash2_pairtree|dflash_mode)$. The MLX job is wired in the stacked MLX PR [MLX] Support PairTree DFlash2 for Muse Glimmer #25942, so this PR doesn't touch mlx.yml. The fixture-backed muse_glimmer_cuda_dflash CI step already runs the serial-only equivalence test on the pinned pairs, because it exports --dflash2.
  3. Equivalence only compared the branch with itself: fixed in two ways.
    • The PR body now separates the within-branch CI test from two checks against the parent commit's executor (be23a26276) on the same .pte files. The "same steps as before" claim is scoped to those checks.
    • Tiny fixtures, local: main's executor vs this branch with --dflash_serial_only, with budget 0, and with the default on plain exports. Covers 1/4/16 sessions, close/replace, second turns and a rewind. All 16 traces match byte for byte: tokens, frontiers, positions, committed hidden-row hashes, free cells, every stats counter, and target forward calls.
    • 30B: main (M) vs serial-only (S) and budget 0 (Z) on one plain export, at 1/4/16 sessions and multi-turn. All 44 run pairs are bit-identical: tokens, every CudaDFlashStats counter, every committed verify-row logit hash and argmax, and the full target and draft cell-cache verb, cell and position trace.

Non-blocking

  1. ABI-check ordering: fixed. The draft_forward_pairtree input/output and extras checks, and the argmax check, now feed DFlashTreeCapability before resolve_dflash_mode runs. A mismatched method counts as missing: on the default path it falls back to Serial DFlash2 with the reason, and an explicit budget is refused. The pre-written note is gone.
  2. pos() while a tree is pending: fixed in the contract. A pending tree's pos() now reports the sequence as implicit resolution will leave it (root plus unbranched chain), so execute_raw's root check agrees with what declare_tree_step resolves. The cache.h and cell_cache.h text is corrected: abandon_step is no longer listed, a malformed declare_tree_step returns before resolving, and a tree placed on any layer stays pending until abandon_step rolls it back. New tests cover pending pos(), a tree placed on one layer only (resolve or abandon), and malformed declarations that leave the pending tree intact.
  3. Builder-refusal fallback untested: fixed. New controlled_nan fixture and test RefusedTreeTablesFallBackToSerialDFlash2. Writing the test showed tree_fallback_cycles wasn't counted when the fallback round then hit a non-finite score. It's now counted at the fallback point, and the stats comment says so. New test PairTreeDraftMethodExtendsDraftForward checks, on the compiled methods, that draft_forward_pairtree's ids and scores equal draft_forward's bit for bit.
  4. Root --dflash2 fixture shape: fixed. export_dflash2 gained a wide switch. The root fixture is back to forward sizes (1, 4), 32-token steps and 512 cells; only the PairTree pairs use the wide shape. Docstring and tests README updated.
  5. Test-only switch in CellCache: partly changed. Injecting the leaky rule from the test side would need a mask-rule hook in production code, which is no better. So the switch stays, behind one shared extension/llm/cache/test/cell_cache_test_peer.h (it was defined twice). MaskFuzzMatchesBruteForce now also runs with the hook on and requires more than a quarter of trials to leak, so the fuzz test's negative control is automated. The PR-body wording is fixed.
  6. Mode policy split: fixed. resolve_dflash_mode owns every mode refusal, including serial-only with a nonzero budget; the factory returns its reason in the startup note. The factory now only refuses what no backend offers. DFlashModeRequest::max_decode_sequences defaults to 4, like the config. The launcher keeps its early range and backend checks so a bad combination fails before the worker starts; a comment says they repeat the worker's checks.

Local tests at this head:

suite result
native CUDA (fresh fixtures, pin check passed) 43/43
cell cache 75/75
ctest 4/4
Python CPU 58 passed; 31 passed, 7 skipped
Python GPU 37 passed, 2 skipped
lintrunner clean

@Gasoonjia

Copy link
Copy Markdown
Contributor Author

@claude /pr-review

Please review the current head 58c2e5236b against main be23a26276. Changes since your last review of c30542f4db, per finding, are in the comment above:

  • the max_decode_sequences clamp now counts logical sessions;
  • cuda.yml wiring for the resolver and builder tests;
  • the equivalence claim is scoped, with cross-version checks against be23a26276's executor on the same .pte (tiny local, and 30B 44/44 bit-identical);
  • draft_forward_pairtree ABI checks fold into the capability before resolving;
  • a pending tree's pos() reports the resolved sequence, and the cache contract text is fixed;
  • a refused-table fallback test plus a compiled-method output check;
  • the root fixture shape is restored;
  • one shared CellCacheTestPeer and a fuzz negative control;
  • refusals are consolidated in the resolver.

@claude

claude Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Claude finished @Gasoonjia's task in 42m 45s —— View job


Re-review of 58c2e5236b: nothing blocks merging, five minor items remain (a misleading refusal message, a missing export guard, and three test gaps), and the recommendation is Approve.

PR Review: #25901

Summary

This PR adds PairTree DFlash2 for Muse Glimmer on CUDA, which verifies bounded drafted trees on the cell KV cache. It brings tree steps in CellCache, a header-only tree builder, one mode resolver, and the executor, export and CI wiring. I reviewed 58c2e5236b against be23a26276. Nothing blocks, and the five issues below are minor.

Code Quality

  • examples/models/muse-glimmer/runtime/cuda_dflash_executor.cpp:757-759: the refusal suffix is attached to every refusal, and its number can be wrong.
    • "(static target forwards take at most N rows)" is appended to every refusal from resolve_dflash_mode. That includes a negative budget, the serial-only conflict, a missing draft_forward_pairtree and a target that can't verify trees.
    • Only "the tree budget exceeds the widest tree verify" needs it.
    • N is std::min(pairtree::kMaxRows, target->widest_static_tokens()) (:743-744). If a static forward is wider than 256 tokens, the message blames the target forward for the builder's 256-row cap.
    • Fix: append the suffix only when the explicit budget exceeds capability.max_budget, and word it as the tree verify row limit. Fix this →
  • examples/models/muse-glimmer/export/export_dflash.py:228: --dflash2-pairtree is accepted with --kv-layout sequence.
    • Only CellCache overrides supports_tree_steps(), so that .pte ships a draft_forward_pairtree that can never run.
    • At runtime the default mode falls back to Serial ("the target cannot verify trees"), and an explicit --dflash_tree_budget is refused at startup.
    • Fix: add kv_layout == "cell" to the guard. Fix this →

Testing

  • examples/models/muse-glimmer/tests/cuda_dflash_native_test.cpp:1594: RefusedTreeTablesFallBackToSerialDFlash2 only uses a NaN table.
    • A NaN also fails Serial DFlash2's own path, so the test shows the batch failing, not the fallback succeeding.

    • The builder also refuses finite tables (dflash2_pairtree.h:133-149,189-191):

      • retained candidate mass above one;
      • a positive extension score;
      • two sibling nodes with the same token.
    • Those rounds take the fallback at cuda_dflash_executor.cpp:1416-1429, then verify and commit Serial tokens from draft_forward_pairtree's outputs. No test runs that path.

    • Fix: add a controlled-fixture variant with a finite refused table, and assert three things:

      • the tokens match the budget-0 run;
      • failed_batches == 0;
      • tree_fallback_cycles > 0.

      Fix this →

  • examples/models/muse-glimmer/tests/dflash_mode_test.cpp:59: DecodeSequencesCountLogicalSessions tests std::min, not the fix.
    • dflash_decode_sequences (dflash_mode.h:40-44) is only a std::min.
    • The fix it should guard is the argument at runtime/runners/batching_bootstrap.cpp:154-155, which now passes FLAGS_max_sessions instead of the physical backend.max_sessions. Nothing tests that argument, so reverting it keeps the suite green.
    • The helper is also a one-line, single-use helper, which CLAUDE.md discourages.
    • Fix: inline the std::min in the bootstrap. Then either test the bootstrap or drop this test. A useful bootstrap test: one logical session plus prefix-cache sessions should get the 31 default. Fix this →
  • extension/llm/cache/test/cell_cache_tree_test.cpp:387: the mask fuzz never reaches the executor's steady state.
    • run_mask_fuzz builds a fresh cache for each trial (:396) and runs a single forest on it.
    • Each sequence's history and tree nodes are contiguous (:413), and no sequence is forked. So step cells always sit after all history, and no history cell has two owners.
    • The executor's steady state is the opposite: after retain_tree frees siblings, the next round's nodes fill the freed cells between kept history.
    • DroppedBranchesFreeTheirCells checks that case only through pos() and free_cells(), never through masks.
    • The history check (:459) only counts visible cells. A row that sees another sequence's history in place of its own still passes.
    • Fix: run several rounds per cache and include a seq_clone fork. Check history visibility cell by cell against the owner, position and window rule. Fix this →

Recommendation

Approve

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.

This branch was successfully deployed

1 active (outdated) and 1 inactive (outdated) deployments
upload-benchmark-results — c30542f4 Deployed Dec 3, 2026 by Gasoonjia via upload-benchmark-results #23846
cadence — c30542f4 Deployed Dec 3, 2026 by Gasoonjia via hifi5s-op-test / hifi5s #42008
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant