Allow piecewise CUDA graph with speculative decoding (#22128)

Co-authored-by: luhongyu.4869 <luhongyu.4869@bytedance.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
narutolhy
2026-04-17 13:39:30 +08:00
committed by GitHub
co-authored by luhongyu.4869 Claude Opus 4.6
parent 91679d935d
commit 5fa0c6a52e
4 changed files with 272 additions and 18 deletions
@@ -2600,6 +2600,10 @@ class ModelRunner(ModelRunnerKVCacheMixin):
)
return
# Draft models use decode CUDA graphs, not PCG
if self.is_draft_worker:
return
# Disable piecewise CUDA graph for non-language models
if not hasattr(self.model, "model"):
logger.warning(
@@ -422,6 +422,16 @@ class PiecewiseCudaGraphRunner:
# TODO(yuwei): fix it
if forward_batch.input_embeds is not None:
return False
# PCG graphs are captured with ForwardMode.EXTEND and spec_info=None.
# TARGET_VERIFY has different spec_info and capture_hidden_mode,
# so it must not use PCG-captured graphs.
if forward_batch.forward_mode.is_target_verify():
return False
# PCG graphs are captured with the runner's capture_hidden_mode.
# If the batch needs a different mode (e.g. FULL for speculative
# decoding), PCG replay would return wrong/missing hidden_states.
if forward_batch.capture_hidden_mode != self.capture_hidden_mode:
return False
# Disable for token embedding overrides (dynamic per-request)
if forward_batch.replace_embeds is not None:
return False
+15 -18
View File
@@ -1153,56 +1153,53 @@ class ServerArgs:
# 1. Disable Model Arch
if self.get_model_config().is_piecewise_cuda_graph_disabled_model:
self.disable_piecewise_cuda_graph = True
# 2. Speculative decoding
if self.speculative_algorithm is not None:
self.disable_piecewise_cuda_graph = True
# 3. DP attention
# 2. DP attention
if self.enable_dp_attention:
self.disable_piecewise_cuda_graph = True
# 4. Torch compile
# 3. Torch compile
if self.enable_torch_compile:
self.disable_piecewise_cuda_graph = True
# 5. Pipeline parallelism
# 4. Pipeline parallelism
if self.pp_size > 1:
self.disable_piecewise_cuda_graph = True
# 6. Non-CUDA hardware (AMD, NPU, CPU, MPS, XPU, etc.)
# 5. Non-CUDA hardware (AMD, NPU, CPU, MPS, XPU, etc.)
if is_hip() or is_npu() or is_cpu() or is_mps() or is_xpu():
self.disable_piecewise_cuda_graph = True
# 7. MoE A2A backend
# 6. MoE A2A backend
if self.moe_a2a_backend != "none":
self.disable_piecewise_cuda_graph = True
# 8. LoRA
# 7. LoRA
if self.lora_paths or self.enable_lora:
self.disable_piecewise_cuda_graph = True
# 9. Multimodal / VLM models
# 8. Multimodal / VLM models
if self.get_model_config().is_multimodal:
self.disable_piecewise_cuda_graph = True
# 10. GGUF quantized models (custom dequant ops unsupported by torch.compile)
# 9. GGUF quantized models (custom dequant ops unsupported by torch.compile)
if (
self.load_format == "gguf"
or self.quantization == "gguf"
or check_gguf_file(self.model_path)
):
self.disable_piecewise_cuda_graph = True
# 11. DLLM (diffusion LLM) models (context manager in forward breaks dynamo)
# 10. DLLM (diffusion LLM) models (context manager in forward breaks dynamo)
if self.dllm_algorithm is not None:
self.disable_piecewise_cuda_graph = True
# 12. CPU offload (breaks dynamo)
# 11. CPU offload (breaks dynamo)
if self.cpu_offload_gb > 0 or self.enable_hierarchical_cache:
self.disable_piecewise_cuda_graph = True
# 13. Deterministic inference
# 12. Deterministic inference
if self.enable_deterministic_inference:
self.disable_piecewise_cuda_graph = True
# 14. PD disaggregation
# 13. PD disaggregation
if self.disaggregation_mode != "null":
self.disable_piecewise_cuda_graph = True
# 15. Symmetric memory (torch.cuda.use_mem_pool is untraceable by dynamo)
# 14. Symmetric memory (torch.cuda.use_mem_pool is untraceable by dynamo)
if self.enable_symm_mem:
self.disable_piecewise_cuda_graph = True
# 16. Expert distribution recorder
# 15. Expert distribution recorder
if self.enable_eplb or self.expert_distribution_recorder_mode is not None:
self.disable_piecewise_cuda_graph = True
# 17. Context parallel
# 16. Context parallel
if self.attn_cp_size > 1:
self.disable_piecewise_cuda_graph = True
# 18. CUDA Graph debug mode