feat(vllm): instrument the V2 model runner for graph-capture traces - #952
Open
tkarttunen wants to merge 1 commit into
Open
feat(vllm): instrument the V2 model runner for graph-capture traces#952tkarttunen wants to merge 1 commit into
tkarttunen wants to merge 1 commit into
Conversation
The capture profiler is added to capture_model() in the legacy
GPUModelRunner only. Since vLLM 0.22, VllmConfig.use_v2_model_runner
selects the rewritten runner in vllm/v1/worker/gpu/ by default for many
configurations, and that runner contains no reference to
capture_torch_profiler at all.
The result is a silent no-op: the patch applies, the server starts and
serves, CUDA graphs are captured normally, capture_traces/ stays empty
and neither of the patch's own log lines is emitted. Nothing reports an
error, so the only way to notice is to go looking for traces that were
never written. The workaround until now has been to pin
VLLM_USE_V2_MODEL_RUNNER=0, which forces users onto a runner vLLM no
longer selects by default.
Instrument CudaGraphManager.capture() in
vllm/v1/worker/gpu/cudagraph_utils.py, which owns the per-shape capture
loop for both PIECEWISE and FULL modes. The manager already holds
vllm_config, so the profiler is built where it is used and nothing has
to be threaded through model_runner.py.
Behaviour matches the legacy path exactly: same rank-0 guard, same
trace directory (torch_profiler_dir/capture_traces), same worker_name,
and the same capture_{num_tokens}_{mode} annotation that
CaptureAnnotation's capture_(\d+)_(.*) pattern parses. Warmup passes
stay outside the profiled region, as they are in the legacy runner.
Verified on MI350X for 0.22 and 0.25, the two ends of the affected
range, with no VLLM_USE_V2_MODEL_RUNNER set anywhere:
INFO [gpu_worker.py] Using V2 Model Runner
INFO [cudagraph_utils.py] Rank 0: Torch profiler enabled for CUDA
graph capture, traces will be saved to: /tmp/traces/capture_traces
Both produced 102 capture shards, the same count the legacy runner
produces for the same model, carrying annotations such as
capture_512_PIECEWISE. All four patches apply to their base images with
strict git apply and every touched file byte-compiles.
Indenting the capture body under the profiler pushed two existing
comments past the 88-column limit, so they are rewrapped; no logic in
them changed.
Contributor
|
Thanks @tkarttunen for the PR! I am going through the patches, I think we need some additions to cover speculator and encoder models, and also annotations for that. I will try to build on top of this and merge both PRs after testing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The graph-capture profiler is wired into
capture_model()in the legacyGPUModelRunneronly. Since vLLM 0.22,VllmConfig.use_v2_model_runnerselects the rewritten runner undervllm/v1/worker/gpu/by default for many configurations, and that runner contains no reference tocapture_torch_profilerat all.The failure is silent. The patch applies, the server starts and serves, CUDA graphs are captured normally,
capture_traces/stays empty, and neither of the patch's own log lines is emitted. Nothing reports an error, so the only way to notice is to go looking for traces that were never written. The workaround has been to pinVLLM_USE_V2_MODEL_RUNNER=0, which forces users onto a runner vLLM no longer selects by default.This instruments
CudaGraphManager.capture()invllm/v1/worker/gpu/cudagraph_utils.py, which owns the per-shape capture loop for both PIECEWISE and FULL modes, for 0.22 through 0.25.What changed
CudaGraphManageralready holdsvllm_config, so the profiler is built where it is used. Nothing is threaded throughmodel_runner.pythe way the legacy patch threads aprofiler=kwarg down two call levels.torch_profiler_dir/capture_traces), sameworker_name, and the samecapture_{num_tokens}_{mode}annotation thatCaptureAnnotation'scapture_(\d+)_(.*)pattern parses.Evidence
Verified on MI350X for 0.22 and 0.25, the two ends of the affected range, with no
VLLM_USE_V2_MODEL_RUNNERset anywhere:capture_512_PIECEWISEcapture_512_PIECEWISE102 shards is the same count the legacy runner produces for the same model, so the V2 path now yields equivalent output rather than merely non-empty output.
Test plan
vllm/vllm-openai-rocm:v0.2{2,3,4,5}.0) with strictgit apply, as a single invocationCaptureAnnotationNotes for review
capture()bodies are byte-identical to 0.25's, so the same patch text applies unchanged.Made with Cursor