Repository navigation
[rl] MTP speculative decoding in the vLLM generator - #6476
Draft
liangel-02 wants to merge 3 commits into
Draft
liangel-02 wants to merge 3 commits into
liangel-02 wants to merge 3 commits into
Conversation
VLLMEngine.Config.num_speculative_tokens turns on vLLM's MTP drafter for Qwen3.5-architecture checkpoints. The draft shares the target's embedding and lm_head storage, so weight syncs reach it. The stat logger exports vLLM's acceptance counters. speculative_config is now TorchTitan's key (extra_engine_args can't set it), so the GDN layer's refusal of speculative decoding goes. Refused: cuda_graph.mode="FULL" (FULL_DECODE_ONLY and NONE work), session_kv_holder, debug.batch_invariant, generator DP > 1, vision encoders, non-CUDA devices, and 1-token prompts (rejected per request). Under async scheduling, vLLM moves rows while the last step's accepted-count copy may still land, then gathers counts by last-step row: a new request or a reordered decode row could read another request's count. The runner waits for the copy before rows move and puts each row's count back by request; a request vLLM removes and adds again (a forced preemption) gets 1.
…ecode # Conflicts: # torchtitan/rl/generator/vllm/attention/gdn.py # torchtitan/rl/generator/vllm/worker.py
… read-back test The draft config_format and embedding/lm_head TODOs link their vLLM feature requests.
6 tasks
This branch has not been deployed
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.
Supersedes #6287 (originally by felipemello1).
Summary (human-written)
Agent details
Needs retesting on H100: every number below is from one GB300 (SM103). The GDN draft path and the draft's attention backend were not run on H100.
Stack, bottom to top:
The stack lands after the vLLM 0.33 PRs ("[rl] generator: vLLM 0.33 API fixes and TP padding in the model wrapper", "[rl] Install vLLM 0.33.0 on the torch nightly"). "[rl] generator: run on vLLM's model runner V2 (vLLM 0.34)" rebases on it.
TLDR:
VLLMEngine.Config.num_speculative_tokens = 3turns on vLLM's MTP drafting for Qwen3.5-architecture checkpoints that ship an MTP head (tested: Qwen3.8-27B). The draft guesses 3 tokens and the TorchTitan model checks them in one step. vLLM's rejection sampler keeps a draft token with probability min(1, p_target / p_draft) and resamples on a reject, so the output follows the TorchTitan model's distribution and the logprobs are its own. On one GB300 with Qwen3.8-27B, one request decodes 1.66x faster at a 27k-token context and 2.14x at 77k (144.7 vs 87.3 and 179.3 vs 84.0 tok/s), and the trainer agrees with MTP-3's logprobs as closely as with MTP off's (k3 2.61e-4 vs 2.65e-4).Problem
__init__.config_format("torchtitan"), and it looks up the target's embedding and lm_head by HF attribute names.Solution
num_speculative_tokens, maps to vLLM'sspeculative_configwith method "mtp".speculative_configbecomes a TorchTitan-owned engine arg, soextra_engine_argscan't set it. The draft's attention layer uses the target's backend: vLLM's own pick (FlashInfer) has no block size in common with CUSTOM's 128-token pages (FA4 on SM100).TorchTitanConfigParsersends the draft's config parse to vLLM's HF parser (registry.py).TorchTitanEagleProposer(worker.py) accepts only Qwen3.5-architecture drafts, gives the draft its own model config, and points itsembed_tokensandlm_headat the target's storage. It raises if shapes or dtypes differ. The CUDA worker installs it the way it already installsTorchTitanGPUModelRunner.max_num_seqs * (1 + k)tokens (config.py).vllm.spec_decode_num_drafts,vllm.spec_decode_num_draft_tokensandvllm.spec_decode_num_accepted_tokens. The metrics README gives the acceptance-rate query.cuda_graph.mode="FULL"(PR 6 lifts it),session_kv_holder(main's refusal stays),debug.batch_invariant, generator DP > 1, models with a vision encoder, non-CUDA devices.add_requestsrejects a prompt under 2 tokens: vLLM pads it with placeholder drafts, which GDN's verify kernels can't run. Only that request fails; the GDN builder's check (PR 1) is the backstop.worker.py). vLLM's V1 runner moves rows before it waits for the last step's count copy, then gathers each row's count by its last-step position. So a new request right after the last one ended, or a decode row that the decode/prefill reorder moved, can start from another request's count, and from the wrong GDN state.TorchTitanGPUModelRunner._update_stateswaits for the copy before any row moves and keeps the counts by request._prepare_inputsputs them back, with 1 for a row that has no last-step count or that vLLM removed and added again (a forced preemption). vLLM main has no V1 runner ("[Core] Remove Model Runner V1"), so this goes with the move to V2 (TODO).num_speculative_tokens = 0(the default), the engine takes main's path. vLLM builds a drafter only whenspeculative_configis set, and the 3 counters add only when vLLM reports drafts.Results
You may ask:
Qwen3_5MTP). A native drafter can follow: it would remove the parser routing, the draft model-config swap, the two private-method overrides and the.dataalias, and a trained head would sync like any other weight. It takes three pieces: a Qwen3.5 MTP block on main's sharedMTPDecoder(torchtitan/models/common/mtp.py, as DeepSeek-V3 and V4 use), a drafter wrapper that runs it in vLLM's draft loop with paged-KV attention, and training it (TODO inload_model_state_dict).engine=VLLMEngine.Config(num_speculative_tokens=3, cuda_graph=VLLMCudaGraphConfig(mode="FULL_DECODE_ONLY")), on a Qwen3.5-architecture checkpoint that shipsmtp.*weights. At this PR, it pays when requests mostly decode. PRs 5-7 make it pay on agent loads.GPUModelRunner.__init__with no factory. vLLM'smethod="custom_class"builds a proposer fromvllm_configalone, and it is not an EAGLE-style method (use_eagle()), so the runner would not hand it the target's hidden states. The worker already swaps the runner class the same way.NOTE:
27Bflavor with Qwen3.8-27B weights, and Qwen3.5-27B for the agent load. Theqwen3_6andqwen3_827B flavors build the vision encoder, and MTP refuses models with a vision encoder.Qwen3_5MoeMTP) is accepted but untested. Tested at TP1 only: at TP > 1, if the draft's vocabulary shard and the target's local shard differ in shape, the engine raises at start-up.VLLMEngine.load_model_state_dict.gpu_memory_limit0.9). vLLM also gives each running request one more GDN state block per draft token in each GDN group: +9 blocks per running request on Qwen3.8-27B (3 GDN groups).session_kv_holderstill refuses drafts. "[rl] Evict an ended rollout's KV from vLLM's prefix cache" replaces the holder with an evictor that runs with drafts (TODO at the refusal).stat_logger(the default), acceptance shows only in vLLM's console log ("SpecDecoding metrics").Follow up / TODO (each has a
# TODOin the code)MTPSpeculatorand register it withregister_speculative_method.config_format, and a target hook for the draft's embedding and lm_head (as SGLang'sget_embed_and_head). Both feature requests are drafted; the TODOs link them.Test plan
New tests:
test_a_row_copies_its_gdn_state_from_its_own_last_steps_offset(4 cases),test_a_row_moved_by_the_reorder_keeps_its_accepted_count(3 cases),test_speculative_draft_parse_is_told_apart_from_the_target_parse,test_cuda_graph_config_with_draft_tokens,test_eagle_proposer_hooks_match_vllm,test_admission_rejects_one_token_prompts_with_drafts.test_cuda_only_features_rejected_off_cudagets a case for drafts off CUDA. The stat logger tests cover the speculative-decoding counters.