Skip to content

[Spec] Resolve DFlash2 selector shard metadata once for both TP modes - #35581

Draft
Jiminator wants to merge 2 commits into
sgl-project:mainfrom
Jiminator:refactor/dflash2-selector-tp-shape
Draft

Jiminator wants to merge 2 commits into
sgl-project:mainfrom
Jiminator:refactor/dflash2-selector-tp-shape

Conversation

@Jiminator

@Jiminator Jiminator commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Depends on #35496 (its commit is included below; review only the second commit). Optional cleanup — no behavior change, no user-visible effect; opened separately so it does not ride along with a feature PR.

compute_candidates duplicates the projection call and the radix top-k across its TP=1 and sharded branches, although the branches differ only by the crop width and the global id offset. Every change to the projection so far has had to be applied to both call sites.

Modifications

  • models/dflash.py: resolve num_org / org_vocab_start once for both TP modes, then project and top-k once. The TP=1 early return moves after the top-k.

Accuracy Tests

test_dflash_logits.py: 6/6 pass unchanged — the TP test from #35496 pins the per-shard crop, the global id offset, and the fp32 cast before the all-gather, which is what this restructure moves.

Speed Tests and Profiling

None; identical kernels in identical order on both paths.

Checklist


CI States

Latest PR Test (Base): ❌ Run #32313662431
Latest PR Test (Extra): ❌ Run #32313662219

Jiminator and others added 2 commits August 19, 2026 23:31
DFlash2's candidate selector borrows the target lm_head and matmuls
draft hiddens against .weight directly, so a quantized target (ModelOpt
NVFP4 packed, compressed-tensors FP8 per-channel) fails the dense-head
screen and DFLASH refuses to serve such checkpoints.

Route an applicable quantized head through quant_method.apply — the
same gate (should_apply_lm_head_quant_method) and kernel the target's
own logits path uses. A packed weight cannot be row-sliced to the org
vocab like the dense path, so the padded tail is masked to -inf out of
the top-k instead: a crop view would either break the contiguity
flashinfer's radix top-k CHECK_INPUTs or copy the whole valid vocab to
restore it. Both TP paths project through one helper; their control
flow is unchanged.

The worker's pre-capture screen admits a gate-passing quantized head
into the graph-folded selector sampler rather than leaving it on the
eager per-round fallback, so quantized and dense heads take the same
code path; the kernel it captures is the one the target's own logits
path already runs under CUDA graphs. The dense-only screen still guards
the non-selector static-matmul sampler. Folded and eager measure equal
on the same cell (accept lengths bit-identical), so this is path
consistency, not the speedup itself.

Co-authored-by: LING ZHI <1747985437lz@gmail.com>
compute_candidates duplicates the projection and the radix top-k across
its TP=1 and sharded branches, which differ only by the crop width and
the global id offset. Resolve those two up front so the projection and
the top-k each have a single call site.

Behavior is unchanged on both paths; the existing TP unit test pins the
crop, the offset, and the fp32 cast before the all-gather.
@Jiminator
Jiminator force-pushed the refactor/dflash2-selector-tp-shape branch from 3ef310f to 4b1d1eb Compare August 19, 2026 23:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant