Skip to content

vllm.compilation.cuda_graph

Classes:

CUDAGraphLogging

Aggregate and log cudagraph metrics.

CUDAGraphWrapper

Wraps a runnable to add CUDA graph capturing and replaying ability. And provide attribute access to the underlying runnable via __getattr__.

The workflow of this wrapper in the cudagraph dispatching is as follows: 1. At initialization, a runtime mode is assigned to the wrapper (FULL or PIECEWISE). 2. At runtime, the wrapper receives a runtime_mode and a batch_descriptor(key) from the forward context and blindly trust them for cudagraph dispatching. 3. If runtime_mode is NONE or runtime_mode does not match the mode of the wrapper, just call the runnable directly. 4. Otherwise, i.e., the runtime_mode matches the mode of the wrapper, the wrapper will perform cudagraph capture(if key does not exist, create a new entry and cache it) or replay (if key exists in the cache).

Note: CUDAGraphWrapper does not store persistent buffers or copy any runtime inputs into that buffers for replay. We assume implementing them is done outside of the wrapper. That is because we do not make any assumption on the dynamic shape (batch size) of the runtime inputs, as a trade-off for staying orthogonal to compilation logic. Nevertheless, tracing and checking the input addresses to be consistent during replay is guaranteed when vLLM debug logging is enabled.

Methods:

  • clear_all_graphs –

    Clear captured graphs from all CUDAGraphWrapper instances.

clear_all_graphs() classmethod

Clear captured graphs from all CUDAGraphWrapper instances.