main
py 57 lines 1.94 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 from collections.abc import Callable
5 from typing import Any, Protocol
6
7 from vllm.config import CUDAGraphMode, VllmConfig
8
9
10 class AbstractStaticGraphWrapper(Protocol):
11 """StaticGraphWrapper interface that allows platforms to wrap a callable
12 to be captured as a static graph.
13 """
14
15 def __init__(
16 self,
17 runnable: Callable[..., Any],
18 vllm_config: VllmConfig,
19 runtime_mode: CUDAGraphMode,
20 **kwargs: Any,
21 ) -> None:
22 """Initializes the StaticGraphWrapper class with graph capturing and
23 execution-related configurations.
24
25 Args:
26 runnable (Callable): The callable to be wrapped and captured.
27 vllm_config (VllmConfig): Global configuration for vLLM.
28 runtime_mode (CUDAGraphMode): The style of the static
29 graph runtime. See CUDAGraphMode in vllm/config.py.
30 Note that only the subset enum `NONE`, `PIECEWISE` and `FULL`
31 are used as concrete runtime mode for cudagraph dispatching.
32
33 Keyword Args:
34 kwargs: Additional keyword arguments for platform-specific
35 configurations.
36
37 """
38 raise NotImplementedError
39
40 def __call__(self, *args: Any, **kwargs: Any) -> Any:
41 """Executes the wrapped callable.
42
43 If the current runtime mode in the ForwardContext matches the runtime
44 mode of this instance, it replays the CUDAGraph or captures it using
45 the callable if it hasn't been captured yet. Otherwise, it calls the
46 original callable directly.
47
48 Args:
49 *args: Variable length input arguments to be passed into the
50 callable.
51 **kwargs: Keyword arguments to be passed into the callable.
52
53 Returns:
54 Any: Output of the executed callable.
55
56 """
57 raise NotImplementedError