Repository navigation
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/25942
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New Failures, 3 PendingAs of commit 1403383 with merge base be23a26 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
c30542f to
58c2e52
Compare
Run PairTree DFlash2 tree verification on the MLX backend with the same options and round semantics as CUDA: a `--dflash2-pairtree` export runs it at B=15 unless `--dflash_tree_budget` or `--dflash_serial_only` says otherwise, greedy sessions only, with Serial DFlash2 for sampled sessions and refused candidate tables. Serial-only and Serial DFlash2 never load `draft_forward_pairtree` and run bit-identically to a plain export; PairTree mode loads only `draft_forward_pairtree`, so the draft's constants are materialized once. The default MLX batched target cache now takes tree steps: a step's tokens are stored after each session's history, attend through an explicit mask (history within each layer's window by tree position, plus in-step ancestors), and `retain_tree` compacts the accepted path next to the history. Unretained trees are settled before other verbs as in the cell cache. The MLX export adds `draft_forward_pairtree` with `--dflash2-pairtree`, and the launcher, factory and export no longer restrict PairTree DFlash2 to CUDA. Review order: MLXSequenceCache.h, MLXBatchedCache.h, mlx_executor.cpp, tests, then the relaxed shared checks. On an Apple M5 Max, PairTree B=15 decodes 1.12x faster than Serial DFlash2 over the 160-prompt MT-Bench/GSM8K/HumanEval set; B=31 is slower there (0.91x) because a 32-row MLX verify costs about 1.4x a 16-row one. Hence the MLX default B=15; CUDA's single-session default is B=31. Authored with AI assistance (Metamate).
The Muse Glimmer MLX job now builds and runs muse_glimmer_dflash2_pairtree and muse_glimmer_dflash_mode with the other host-only batching tests; the MLX serial-only identity check runs inside muse_glimmer_mlx_dflash. Authored with AI assistance (Metamate).
48394d7 to
1403383
Compare
|
@claude /pr-review Please review the current head
|
|
Claude finished @Gasoonjia's task in 38m 22s —— View job PR Review: #25942
Needs Discussion: making PairTree DFlash2 the MLX default for Detailed reviewSummaryThe PR adds PairTree DFlash2 to the MLX backend: tree steps on the API Design
Testing
Performance
Code Quality
RecommendationNeeds Discussion The open question is whether PairTree should be the MLX default for Done: three independent reviews covering all 18 changed files in the two MLX commits, merged and fact-checked against the code. Not done: nothing was built or run, because MLX is not available on this Linux runner. The Performance estimate extrapolates the PR's single-session timings; it is not a measurement. |
Stacked on #25901 at 58c2e52 (base branch
gasoonjia/pairtree-dflash2-cuda), which adds the shared pieces:BatchControl::declare_tree_step/retain_tree);runtime/dflash2_pairtree.h;draft_forward_pairtreeexport method (--dflash2-pairtree);runtime/dflash_mode.h, with its--dflash_tree_budget/--dflash_serial_onlyoptions.What this PR does
PairTree DFlash2 verifies a bounded proposal tree per greedy session instead of Serial DFlash2's single chain of proposals. This PR runs it on the MLX backend with the same options and the same semantics as CUDA:
--dflash2-pairtreeexport runs PairTree DFlash2 by default, with B = 15 on MLX.--dflash_tree_budget Bsets the budget; 0 runs Serial DFlash2. The launcher flag is--dflash-tree-budget.--dflash_serial_onlyruns the export with Serial DFlash2's programs, rounds and cache steps; the launcher flag is--dflash-serial-only. In the checks below it matched main's MLX executor bit for bit. It refuses a nonzero budget.pairtree::round_budget).Changes:
MLXBatchedCache,MLXSequenceCache). These are the default batched MLX cache, with one history per session. They now support tree steps:[T, T]ancestor block is copied from the host. Every layer with the same window shares one mask.retain_treemoves the accepted path next to the history and drops the other branches. It stages every layer first, so a failure leaves the cache unchanged.pos()reports a pending tree's sequences as that resolution will leave them. MLX treats a tree as pending once its forward has run on every layer, and CellCache from its first placed layer; in both,pos()matches that cache's next action.batched-cell) uses the shared CellCache tree step unchanged.mlx_executor.{h,cpp}).resolve_dflash_mode, using the MLX default and the target cache's tree-step support. Adraft_forward_pairtreewhose metadata does not matchdraft_forward's ABI counts as absent, so the default path runs Serial DFlash2. The executor reports the mode and reason, or the refusal, through the factory's startup note, as CUDA does.draft_forwardand never touchdraft_forward_pairtree.draft_forward_pairtree, tree rounds and sampled sessions' Serial rounds alike, and never loadsdraft_forward.draft_forward_pairtreedrafts asdraft_forwarddoes; with only sampled sessions, PairTree mode matches Serial DFlash2 bit for bit in the tiny-fixture test. Each MLX method materializes its own constants (3.5 GB per draft method on the 30B export), so loading both cost +3.7 GB of RSS.draft_forward_pairtreewithdraft_forward's inputs.draft_forwardand the other methods lower byte for byte as without the flag, and the.ptestores their weights once.backend_factory.cpp,serve_batching.pyandexport_dflash.py. The factory also passes the startup note to the MLX executor.Review order:
MLXSequenceCache.hMLXBatchedCache.hmlx_executor.cppDefault budget per backend
The best budget depends on the target's verify cost per row. On these two machines the cost curves differ:
B = 15 verifies 16 rows, the same as Serial DFlash2 with 15 proposals. On the M5 Max its acceptance gain is therefore not spent on a wider verify. B = 31 accepts more per round, but its 32-row verify costs more than that gain on the M5 Max.
Results (MLX, Apple M5 Max 64 GB, macOS 27.2.1)
Setup:
--dflash_tree_budgetset explicitly, on an earlier revision of this PR whose singledraft_forwardreturned the PairTree outputs. That is the same graphdraft_forward_pairtreeis now.meta-models/Muse-Glimmer-30B-GGUF@b44f1072, sha256 4cc57c0f…) and DFlash2 Q4_K_M draft (incoai/Muse-Glimmer-30B-DFlash2-GGUF@5a384781, sha256 0f1e7959…). Export:--backend mlx --use-offgraph-kv-cache --dflash2-pairtree --activation-dtype bfloat16.How to read the table:
Highlights:
Round time:
Acceptance matches CUDA, because the checkpoints are the same. Tokens per round are 5.01 / 5.89 / 6.54 here, vs CUDA 5.02 / 5.93 / 6.57.
MT-Bench per category. Each cell is tokens/round / zero-accept % / full-accept %:
Why B=31 loses on MLX: the target verify cost grows with rows. Forward plus all-row logits plus argmax, median ms:
In situ, a round's verify takes 55.8 ms at 16 rows and 87.7 ms at 32 rows. The RTX 5090 costs the same at 16 and 32 rows.
The tree path costs 4–5 ms more per round than linear verification of the same rows (59.8 vs 55.8 ms at 16 rows). A control isolates this: the linear proposals verified through the tree path gave identical text on 40/40 prompts and the same acceptance, at 0.934x [0.927, 0.941] of linear. A width sweep that runs a chain through the tree API costs as much as the tree itself, so the overhead is MLX's masked attention, not the tree shape.
All of the B=15 numbers above already include this overhead. A tree-aware attention path that removed it would put B=15 at about 1.18x; that is a projection, not a measurement.
Serial-only runs as main's MLX executor does
What was measured: on the same inputs and the same
.pte, serial-only on this branch matched main's (be23a26) MLX executor bit for bit, in the scenarios below. This is evidence for those runs, not a proof for every input.Cross-version check. Research-only, not in this PR; driver and patch are in the results bundle.
.ptevs branch serial-only on it.ptevs branch serial-only on the PairTree.pteThe script scenario samples every third session, replaces one session, and gives every other session a second turn.
Further checks:
.pte(no serial-only flag needed) also matched main.Size and memory.
.pte, and its weights are stored once.draft_forward_pairtree.CI (tiny fixtures, same version).
check_serial_only_identity, the MLX counterpart of #25901'sSerialOnlyRunsThePairTreeExportAsThePlainOne:test_dflash2_pairtree_export_keeps_draft_forwardchecks every lowered method of the plain program and its named weights byte for byte. It also checks that the.ptestores the draft's weights once. The random fixture's.pteis 28.9 MB plain and +29 KB with PairTree.muse_glimmer_dflash2_pairtreeandmuse_glimmer_dflash_mode.muse_glimmer_mlx_dflashruns the identity check.Test plan
All runs are on the Apple M5 Max, from this branch on top of the CUDA PR branch.
Cache unit tests (MLX). Each tree test checks that every tree token matches the plain chain of its root-to-token path, run in a separate per-sequence cache. It also checks that
retain_treekeeps exactly that path for the following steps.The tree tests cover:
pos()of a pending tree: the root plus its unbranched chain, once the tree's forward has run on every layer;Every test runs on the
batched,batched-sequenceandbatched-cellkinds.Native tiny-fixture tests. These use the real exporter with
--dflash2-pairtree-equivalent fixtures:random_pairtree,quantized_pairtree(the production K=16 / block 16 / 202,048-vocabulary draft geometry) andreject_-1_pairtree.Checks:
draft_forward_pairtreelacks the extras, or returns them without the logsumexp column, run Serial DFlash2 by default. An explicit budget fails on them.draft_forward_pairtree;Python.
pytest examples/models/muse-glimmer/tests/test_serve_batching.py \ examples/models/muse-glimmer/tests/test_export_dflash.py \ examples/models/muse-glimmer/tests/test_dflash2.py \ examples/models/muse-glimmer/tests/test_mlx_offgraph.py # 87 passedReal model (30B, research tools not in this PR). The test runs one 32-row heap-shaped tree step: siblings and cousins share positions. Each root-to-leaf path is also verified as a plain chain padded to 32 rows. Chain16 vs chain32 gives the noise floor.
As a negative control, a test-only switch makes siblings visible. It gives 22.3 / 14.1 / 14.0 max |Δlogit| and 23 / 22 / 29 mismatches.
End to end:
Benchmark. The method and the tables are above.
Limitations
CudaDFlashStats.Authored with AI assistance (Metamate).