CUDA graphs, part 2: shrink them
Part two: making CUDA graphs smaller, one measured change at a time. Work on a copy, when nobody needs the server.
Chapters
- 0:00Introduction
- 0:09First: Write down the baseline
- 0:20Look: See what you use
- 0:28Shrink: One change at a time
- 0:43The form: A shorter list
- 0:53Troubleshooting only: Turning graphs off
- 1:05Wrap up
Read the transcript
Introduction
Part two: making CUDA graphs smaller, one measured change at a time. Work on a copy, when nobody needs the server.
First: Write down the baseline
Save the exact start command that works, and its versions. Note the time to ready, and the memory lines in the log. Time your own typical requests, quiet and busy.
Look: See what you use
This vLLM option reports which graphs your requests really use. Adding it restarts the server.
vllm serve MODEL --cudagraph-metricsShrink: One change at a time
First, allow only as many requests at once as you need. The cost: fewer run together. Next, capture fewer sizes. Bigger batches then run the normal way. Last, try a smaller graph mode. Decoding can be slower.
The form: A shorter list
In vLLM 0.34, a decode cap looks like this. In SGLang, this limits the largest decode batch.
vllm serve MODEL --compilation-config \
'{"max_decode_cudagraph_capture_requests": 8}'
python3 -m sglang.launch_server --model-path MODEL \
--cuda-graph-max-bs-decode 8Troubleshooting only: Turning graphs off
Turning graphs off only tests whether they're involved. It can cost speed. Never add enforce eager to a tuned recipe that works. Afterwards, go back to your saved command.
Wrap up
Keep a change only if your own numbers say it's worth it.
Sources
- docs.vllm.ai/en/stable/design/cuda_graphs
- docs.vllm.ai/en/stable/configuration/conserving_memory
- docs.vllm.ai/en/stable/configuration/optimization
- github.com/vllm-project/vllm/blob/v0.34.0/vllm/config/compilation.py
- github.com/vllm-project/vllm/blob/v0.34.0/vllm/v1/worker/gpu_worker.py
- docs.sglang.io/docs/advanced_features/server_arguments