Skip to content

Add offline AR validation for DFlash drafts on dumped target hidden states - #2976

Draft
h-guo18 wants to merge 1 commit into
mainfrom
haoguo/dflash-offline-al
Draft

h-guo18 wants to merge 1 commit into
mainfrom
haoguo/dflash-offline-al

Conversation

@h-guo18

@h-guo18 h-guo18 commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: new example

Adds examples/speculative_decoding/offline_ar/ to measure a DFlash draft's acceptance length (AR) without running the target. scripts/ar_validate.py runs the target at every speculative step. Here the target's greedy replies and hidden states are dumped once with the existing server_generate.py and collect_hidden_states/ scripts, and offline_ar_validate.py replays greedy speculative decoding on the dump. Each draft checkpoint then takes minutes on one GPU, all of them scored on the same references, which suits large targets and checkpoint sweeps.

  • AR is vLLM's 1 + accepted / drafts, pooled over all steps.
  • It also reports the target greedy agreement, the share of reply tokens that are the target's own greedy pick (from the dumped final hidden states), and warns below 0.98. This catches references that are not the target's greedy outputs, e.g. replies generated with special tokens stripped, which re-tokenize into other tokens.
  • No existing code changes. The draft step mirrors the draft half of HFDFlashModel.pseudo_speculative_generate, and a test pins it to that method. Models that override it (DSpark) are refused.

Usage

cd examples/speculative_decoding
python scripts/server_generate.py --data_path prompts.jsonl --output_path replies.jsonl \
    --url http://localhost:8000/v1 --model <served-name> --temperature 0 \
    --extra_body '{"skip_special_tokens": false}'
python collect_hidden_states/compute_hidden_states_hf.py --model <target> \
    --input-data replies.jsonl --output-dir dumps/ --answer-only-loss \
    --aux-layers <draft target_layer_ids>
python offline_ar/offline_ar_validate.py --model_path <DFlash checkpoint> --dump_dir dumps/

Testing

Nemotron-3.5-Bolt-E4B and its DFlash draft (block 8), first turns of MT-Bench (80 prompts, thinking on, up to 1024 tokens), one RTX PRO 6000, peak GPU memory 3.7 GiB:

References AR Greedy agreement Time
vLLM engine, online 3.746
Exact greedy token ids 3.741 0.993 2 min
server_generate.py + compute_hidden_states_hf.py 3.718 0.994 2 min
Same, special tokens stripped 3.689 0.967 (warns) 2 min

Rows 2 and 3 replay different greedy replies (vLLM's greedy decoding depends on the batch), so their AR differs by the references, not the replay. The draft was trained with RoPE theta 1e6, while this checkout resolves a Gemma-4 draft's theta to 1e4, so these runs set 1e6 on the loaded model.

  • tests/examples/speculative_decoding/test_offline_ar.py checks that drafts fed from a dump equal pseudo_speculative_generate's on a tiny model with a sliding window (0.3 s). It fails when the anchor, the output slice or the attention mask drifts.
  • Not run: the vLLM and TensorRT-LLM dumpers, which write the same format.

Before your PR is "Ready for review"

  • Is this change backward compatible?: ✅ New files and a changelog line only.
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: ✅
  • Did you get Claude approval on this PR?: ❌ Draft.

Additional Information

A follow-up could move the draft step into HFDFlashModel, so this script and pseudo_speculative_generate share one implementation instead of a pinned copy.

🤖 Generated with Claude Code

…tates

examples/speculative_decoding/offline_ar/offline_ar_validate.py replays greedy
speculative decoding on conversations dumped by collect_hidden_states/, so a
DFlash draft's acceptance length is measured without running the target. It
reports vLLM's 1 + accepted / drafts and the share of reply tokens that are the
target's own greedy pick, warning when the references are not greedy outputs.

The draft step mirrors the draft half of HFDFlashModel.pseudo_speculative_generate;
tests/examples/speculative_decoding/test_offline_ar.py pins it to that method.

On Nemotron-3.5-Bolt-E4B with its DFlash draft (MT-Bench first turns, thinking
on) the replay gives AR 3.741 on the exact greedy tokens against 3.746 from the
vLLM engine, in 2 minutes on one RTX PRO 6000.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: h-guo18 <[email protected]>
@copy-pr-bot

copy-pr-bot Bot commented Oct 23, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.07%. Comparing base (ace9fd9) to head (0757a07).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2976      +/-   ##
==========================================
- Coverage   79.53%   79.07%   -0.46%     
==========================================
  Files         660      660              
  Lines       74720    75153     +433     
==========================================
  Hits        59430    59430              
- Misses      15290    15723     +433     
Flag Coverage Δ
unit 61.04% <ø> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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