[Perf] Use breakable CUDA graphs (no torch.compile) by default under VLLM_BATCH_INVARIANT so the tuned matmul configs see the runtime M (#57586)
Signed-off-by: LioEinaudi <zhao3024667639@gmail.com>
This commit is contained in:
@@ -776,6 +776,45 @@ class VllmConfig:
|
||||
architectures = set(model_config.architectures)
|
||||
return bool(architectures & default_breakable_cudagraph_architectures())
|
||||
|
||||
def _uses_breakable_cudagraph_for_batch_invariance(self) -> bool:
|
||||
"""Avoid freezing runtime-M tile lookup in compiled forward (#54243).
|
||||
Breakable graphs look up tuned bf16, unquantized qkv/o/gate_up/down tiles
|
||||
at capture; lm_head runs outside compiled forward and does not benefit."""
|
||||
from vllm.model_executor.determinism import batch_invariant_configs as bi
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
model = self.model_config
|
||||
if (
|
||||
not envs.VLLM_BATCH_INVARIANT
|
||||
or model is None
|
||||
or model.enforce_eager
|
||||
or model.dtype != torch.bfloat16
|
||||
or model.quantization is not None
|
||||
or not current_platform.is_cuda()
|
||||
# Sequence parallelism / async TP are torch.compile passes.
|
||||
or self.compilation_config.pass_config.enable_sp
|
||||
or self.compilation_config.pass_config.fuse_gemm_comms
|
||||
):
|
||||
return False
|
||||
family = bi._get_tuned_matmul_arch_family(
|
||||
current_platform.get_device_capability()
|
||||
)
|
||||
if family is None or family not in bi._BATCH_INVARIANT_MATMUL_TUNED_CONFIGS:
|
||||
return False
|
||||
table = bi._BATCH_INVARIANT_MATMUL_TUNED_CONFIGS[family]
|
||||
parallel = self.parallel_config
|
||||
tp = parallel.tensor_parallel_size
|
||||
hidden = model.get_hidden_size()
|
||||
head = model.get_head_size()
|
||||
heads = model.get_num_attention_heads(parallel)
|
||||
kv_heads = model.get_num_kv_heads(parallel)
|
||||
shapes = [((heads + 2 * kv_heads) * head, hidden), (hidden, heads * head)]
|
||||
intermediate = getattr(model.hf_text_config, "intermediate_size", None)
|
||||
# Per-layer sizes (e.g. Gemma3n) are not modeled.
|
||||
if isinstance(intermediate, int):
|
||||
shapes += [(2 * intermediate // tp, hidden), (hidden, intermediate // tp)]
|
||||
return any(shape in table for shape in shapes)
|
||||
|
||||
def _maybe_enable_breakable_cudagraph(self) -> bool:
|
||||
if (
|
||||
"VLLM_USE_BREAKABLE_CUDAGRAPH" not in os.environ
|
||||
@@ -786,6 +825,16 @@ class VllmConfig:
|
||||
"Auto-enabling VLLM_USE_BREAKABLE_CUDAGRAPH=1. "
|
||||
"Set VLLM_USE_BREAKABLE_CUDAGRAPH=0 to opt out."
|
||||
)
|
||||
elif (
|
||||
"VLLM_USE_BREAKABLE_CUDAGRAPH" not in os.environ
|
||||
and envs.VLLM_BATCH_INVARIANT
|
||||
and self._uses_breakable_cudagraph_for_batch_invariance()
|
||||
):
|
||||
os.environ["VLLM_USE_BREAKABLE_CUDAGRAPH"] = "1"
|
||||
logger.info_once(
|
||||
"VLLM_BATCH_INVARIANT=1: auto-enabling VLLM_USE_BREAKABLE_CUDAGRAPH=1. "
|
||||
"Set VLLM_USE_BREAKABLE_CUDAGRAPH=0 to opt out."
|
||||
)
|
||||
|
||||
from vllm.compilation.breakable_cudagraph import (
|
||||
is_breakable_cudagraph_enabled,
|
||||
|
||||
Reference in New Issue
Block a user