Piecewise CUDA Graph Support & Torch Compile Backend (#10062)

Signed-off-by: Oasis-Git <ayw.sirius19@gmail.com>
This commit is contained in:
Yuwei An
2025-10-11 20:55:57 -07:00
committed by GitHub
parent 20a6c0a63d
commit 4ac8e09df0
21 changed files with 2706 additions and 19 deletions

View File

@@ -417,7 +417,10 @@ class ServerArgs:
enable_single_batch_overlap: bool = False
tbo_token_distribution_threshold: float = 0.48
enable_torch_compile: bool = False
enable_piecewise_cuda_graph: bool = False
torch_compile_max_bs: int = 32
piecewise_cuda_graph_max_tokens: int = 4096
piecewise_cuda_graph_tokens: Optional[List[int]] = None
torchao_config: str = ""
enable_nan_detection: bool = False
enable_p2p_check: bool = False
@@ -675,6 +678,11 @@ class ServerArgs:
else:
self.cuda_graph_max_bs = max(self.cuda_graph_bs)
if self.piecewise_cuda_graph_tokens is None:
self.piecewise_cuda_graph_tokens = (
self._generate_piecewise_cuda_graph_tokens()
)
if self.mem_fraction_static is None:
# Constant meta data (e.g., from attention backend)
reserved_mem = 512
@@ -753,6 +761,25 @@ class ServerArgs:
return capture_bs
def _generate_piecewise_cuda_graph_tokens(self):
"""
Generate the list of batch sizes for piecewise CUDA graph capture
based on piecewise_cuda_graph_max_tokens.
"""
capture_sizes = (
list(range(4, 33, 4))
+ list(range(48, 257, 16))
+ list(range(288, 513, 32))
+ list(range(640, 4096 + 1, 128))
+ list(range(4352, self.piecewise_cuda_graph_max_tokens + 1, 256))
)
capture_sizes = [
s for s in capture_sizes if s <= self.piecewise_cuda_graph_max_tokens
]
return capture_sizes
def _handle_hpu_backends(self):
if self.device == "hpu":
self.attention_backend = "torch_native"
@@ -2649,12 +2676,29 @@ class ServerArgs:
action="store_true",
help="Optimize the model with torch.compile. Experimental feature.",
)
parser.add_argument(
"--enable-piecewise-cuda-graph",
action="store_true",
help="Optimize the model with piecewise cuda graph for extend/prefill only. Experimental feature.",
)
parser.add_argument(
"--piecewise-cuda-graph-tokens",
type=json_list_type,
default=ServerArgs.piecewise_cuda_graph_tokens,
help="Set the list of tokens when using piecewise cuda graph.",
)
parser.add_argument(
"--torch-compile-max-bs",
type=int,
default=ServerArgs.torch_compile_max_bs,
help="Set the maximum batch size when using torch compile.",
)
parser.add_argument(
"--piecewise-cuda-graph-max-tokens",
type=int,
default=ServerArgs.piecewise_cuda_graph_max_tokens,
help="Set the maximum tokens when using piecewise cuda graph.",
)
parser.add_argument(
"--torchao-config",
type=str,