add dflash2 selector metrics - #788
Open
curnane-lab wants to merge 1 commit into
Open
Conversation
Extend DFlash2 selector telemetry with three serving-aligned signals, all computed under no_grad inside the existing objective chunk pass: - unary_topk_probability_mass: draft softmax mass inside its own strict unary top-k, i.e. how much score mass a reranker can ever move as selector_top_k changes. - unary_topk_oracle_accepted_length: per-block accepted length crediting every slot whose gold token sits in the unary top-k; an upper-bound proxy for the serving accept length under perfect reranking. - selector_path_accepted_length / selector_path_accuracy: the realized greedy candidate path, re-scoring each slot with its own selected predecessor instead of the gold one, mirroring the serving walk. The new terms ride the SelectorTerms/DFlashObjectiveTerms NamedTuple contract and the (numerator, denominator) ratio_metrics contract, so they aggregate across chunks and ranks exactly like the current selector metrics. Loss terms are unchanged.
curnane-lab
force-pushed
the
dflash2-selector-metrics
branch
from
August 30, 2026 13:28
9d92436 to
ed7d0c8
Compare
curnane-lab
marked this pull request as ready for review
August 30, 2026 13:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Follow-up to #772 (DFlash2). The DFlash2 selector currently reports only
selector_loss/selector_accuracy/selector_coverage/selector_target_probability, which is not enough to answer the two questions that come up when tuning the selector:selector_top_ktoo small, or already wasteful?This PR ports the three validation signals that the merged DFlash2 implementation in vllm-project/speculators reports (
unary_candidate_target_mass_at_k,unary_top_k_oracle_accepted_length, and the realized greedy self-conditioned path), adapted to SpecForge's hard-target online pipeline. Since SpecForge captures hidden states only, the teacher-side soft "target mass" becomes the draft's own softmax mass on the same strict unary top-k candidate set.Modifications
specforge/algorithms/common/dflash_family_model.py:SelectorTerms/DFlashObjectiveTermsgain six additive telemetry fields (top-k mass, oracle/path accepted lengths, path accuracy, and their block/position denominators), preserving the flat tensor-only NamedTuple contract ofcheckpointed_chunk_reduce.no_gradblock of_selector_chunk_terms, the new metrics are computed:unary_topk_probability_mass- the draft's softmax mass inside its own strict unary top-k, via twologsumexpreductions (no extra full-vocab materialization);unary_topk_oracle_accepted_length- per-block accepted length under a perfect reranker: every supervised slot whose gold token sits in the unary top-k is credited. The verified anchor counts as one accepted token, and a block extends only while every earlier slot is supervised and covered;selector_path_accepted_length/selector_path_accuracy- the realized greedy candidate path: each slot is re-scored with its own selected predecessor (starting from the verified anchor) instead of the gold one, mirroring the serving walk; per-position accuracy is conditioned on the earlier path being correct.forwardexposes the four new metrics through the existingratio_metrics(numerator, denominator) contract under the same_selector_objective_enabledgate, so they chunk-reduce and all-reduce exactly like the current selector metrics (zero denominators are clamped by the consumer).tests/test_modeling/test_dflash2.py:test_candidate_mass_and_accepted_length_metrics: a two-block fixture with hand-computed mass, oracle, and realized-path values (rank-1 coverage vs. realized top-1 miss vs. uncovered slot).test_forward_reports_candidate_path_ratio_metrics: forward-level check that the four new ratio metrics are reported with the expected values.Related Issues
Accuracy Test
tests.test_modeling.test_dflash2: 23 passed (21 existing + 2 new).tests.test_utils.test_dflash_losses,tests.test_modeling.test_draft_registry,tests.test_algorithms.test_builtin_providersall pass.no_gradtelemetry.Benchmark & Profiling
No throughput impact by design. The metrics run under
no_gradinside the existing chunk pass; the realized path addsblock_size - 1small codebook-lookup/einsum scorings per chunk (vs. one full-vocablm_headprojection already there), and the mass metric avoids any full-vocab softmax materialization via twologsumexpreductions.Checklist
ruff checkclean; new test code mirrors the file's existing formatting.)