-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
[CUDA graphs] Implement simple cuda graph #20328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4040,6 +4040,9 @@ class CompilationConfig: | |
| splitting certain operations such as attention into subgraphs. Thus this | ||
| flag cannot be used together with splitting_ops. This may provide | ||
| performance benefits for smaller models.""" | ||
| simple_cuda_graph: bool = False | ||
| """Whether to use simple CUDA graph, which uses full CUDA graphs without | ||
| torch.compile. This can speed up the startup time of vLLM.""" | ||
|
|
||
| pass_config: PassConfig = field(default_factory=PassConfig) | ||
| """Custom inductor passes, see PassConfig for more details""" | ||
|
|
@@ -4164,6 +4167,13 @@ def __post_init__(self) -> None: | |
| if isinstance(self.pass_config, dict): | ||
| self.pass_config = PassConfig(**self.pass_config) | ||
|
|
||
| if self.simple_cuda_graph: | ||
| # When using simple CUDA graph, we skip torch.compile. | ||
| self.level = CompilationLevel.NO_COMPILATION | ||
| # Simple CUDA graph does not support piecewise CUDA graphs. | ||
| self.full_cuda_graph = True | ||
| self.use_cudagraph = True | ||
|
|
||
| def init_backend(self, vllm_config: "VllmConfig") -> Union[str, Callable]: | ||
| if self.level == CompilationLevel.NO_COMPILATION: | ||
| raise ValueError("No compilation level is set.") | ||
|
|
@@ -4518,9 +4528,14 @@ def __post_init__(self): | |
| not self.model_config.enforce_eager: | ||
| # By default, V1 uses piecewise CUDA graphs. If full_cuda_graph | ||
| # is set to True, full CUDA graphs will be used. | ||
| self.use_cudagraph = True | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| self.compilation_config.cudagraph_num_of_warmups = 1 | ||
| self.compilation_config.level = CompilationLevel.PIECEWISE | ||
| self.compilation_config.set_splitting_ops_for_v1() | ||
| if self.compilation_config.simple_cuda_graph: | ||
| self.compilation_config.full_cuda_graph = True | ||
| self.compilation_config.level = CompilationLevel.NO_COMPILATION | ||
| else: | ||
| self.compilation_config.level = CompilationLevel.PIECEWISE | ||
| self.compilation_config.set_splitting_ops_for_v1() | ||
|
|
||
| self._set_cudagraph_sizes() | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -214,11 +214,15 @@ def __init__( | |||||||||||||||||||||||||||
| block_sizes=[self.cache_config.block_size], | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| self.use_cuda_graph = ( | ||||||||||||||||||||||||||||
| self.vllm_config.compilation_config.level | ||||||||||||||||||||||||||||
| == CompilationLevel.PIECEWISE | ||||||||||||||||||||||||||||
| and self.vllm_config.compilation_config.use_cudagraph | ||||||||||||||||||||||||||||
| and not self.model_config.enforce_eager) | ||||||||||||||||||||||||||||
| self.use_cuda_graph = True | ||||||||||||||||||||||||||||
| if self.model_config.enforce_eager: | ||||||||||||||||||||||||||||
| self.use_cuda_graph = False | ||||||||||||||||||||||||||||
| if not self.compilation_config.use_cudagraph: | ||||||||||||||||||||||||||||
| self.use_cuda_graph = False | ||||||||||||||||||||||||||||
| if (self.compilation_config.level != CompilationLevel.PIECEWISE | ||||||||||||||||||||||||||||
| and not self.compilation_config.simple_cuda_graph): | ||||||||||||||||||||||||||||
| self.use_cuda_graph = False | ||||||||||||||||||||||||||||
|
Comment on lines
+217
to
+224
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for determining
Suggested change
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # TODO(woosuk): Provide an option to tune the max cudagraph batch size. | ||||||||||||||||||||||||||||
| # The convention is different. | ||||||||||||||||||||||||||||
| # self.cudagraph_batch_sizes sorts in ascending order. | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The checks for
TorchCompileWrapperWithCustomDispatcherandCudaGraphWrapperin the base classes are separate but have identical logic. This can be combined into a singleifstatement using anoroperator to improve readability and reduce code duplication.