Replace device-specific CUDA/XPU graph APIs with unified torch.accelerator.Graph#9
Draft
Copilot wants to merge 2 commits into
Draft
Replace device-specific CUDA/XPU graph APIs with unified torch.accelerator.Graph#9Copilot wants to merge 2 commits into
torch.accelerator.Graph#9Copilot wants to merge 2 commits into
Conversation
Replace torch.cuda.CUDAGraph/torch.cuda.graph and XPU monkey-patching with the unified torch.accelerator.Graph API: - vllm/compilation/cuda_graph.py: Use torch.accelerator.Graph with pool+capture_error_mode at construction, manual capture_begin/end - vllm/compilation/breakable_cudagraph.py: Same, simplify _begin_segment - vllm/v1/worker/gpu/cudagraph_utils.py: Same refactoring - vllm/v1/worker/encoder_cudagraph.py: Same refactoring - vllm/v1/worker/gpu_ubatch_wrapper.py: Same refactoring - vllm/v1/worker/xpu_model_runner.py: Remove graph monkey-patching - tests/v1/cudagraph/test_cudagraph_dispatch.py: Update mocks Co-authored-by: GitHub Copilot
Copilot
AI
changed the title
[WIP] Replace device-specific graph APIs with torch.accelerator.Graph
Replace device-specific CUDA/XPU graph APIs with unified Jun 21, 2026
torch.accelerator.Graph
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.
PyTorch now provides
torch.accelerator.Graphas a device-agnostic replacement fortorch.cuda.CUDAGraph/torch.xpu.XPUGraph. This PR migrates all graph capture/replay code to the new API, eliminating the XPU monkey-patching shim.Key API difference
Notable:
poolandcapture_error_modemove fromcapture_begin()/context-manager args to the constructor.capture_error_mode="global"is passed explicitly to preserve CUDA backward compatibility (old default was"global"; new default is"default").Changes
vllm/compilation/cuda_graph.py— replaceCUDAGraph()+torch.cuda.graph()CM withaccelerator.Graph; updateCUDAGraphEntry.cudagraphtype annotation toAnyvllm/compilation/breakable_cudagraph.py— replaceCUDAGraph()+ conditionalcapture_begin(pool=...)withaccelerator.Graph(pool=...)+ unconditionalcapture_begin(); update type annotationvllm/v1/worker/gpu/cudagraph_utils.py— same refactoring; updategraphsdict type annotationvllm/v1/worker/encoder_cudagraph.py— same refactoring; updateBudgetGraphMetadata.graphtype annotationvllm/v1/worker/gpu_ubatch_wrapper.py— same refactoring; updateCUDAGraphMetaData.cudagraphtype annotationvllm/v1/worker/xpu_model_runner.py— remove thetorch.cuda.graph/CUDAGraph/graph_pool_handlemonkey-patching lines from_torch_cuda_wrapper()(and the now-unusedsupports_xpu_graphimport)tests/v1/cudagraph/test_cudagraph_dispatch.py— update mock targets fromtorch.cuda.graphtotorch.accelerator.Graph