-
-
Couldn't load subscription status.
- Fork 10.8k
[torch.compile] CUDAGraph Inductor partition integration #24281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
4f6e1b4
init
BoyuanFeng 1c1b600
nit
BoyuanFeng 50d1dda
nit
BoyuanFeng 7218e2b
nit
BoyuanFeng 71209e2
cleanup
BoyuanFeng 202b6f3
add doc
BoyuanFeng 0b1e18a
improve warn/error msg
BoyuanFeng b66568b
match new torch api
BoyuanFeng 87c74dd
skip cudagraph for get_input_embedding
BoyuanFeng c0bd3fb
Update vllm/compilation/backends.py
BoyuanFeng e16e23a
Apply suggestions from code review
BoyuanFeng 892ab46
more docs
BoyuanFeng eabb1b6
nit
BoyuanFeng 04e9801
Update vllm/v1/cudagraph_dispatcher.py
BoyuanFeng 6cf5bd5
add piecewise test
BoyuanFeng 70f45da
lint
BoyuanFeng 7eb5d57
Merge branch 'main' into bf/cg-partition
BoyuanFeng 3a6abd8
Merge branch 'main' into bf/cg-partition
BoyuanFeng 4cce30c
add custom compile config test
BoyuanFeng d3809fb
more tests for splitting_ops
BoyuanFeng d7a73db
add tests for attention_quant_pattern
BoyuanFeng 289a60e
rearch is_attention_compiled_piecewise
BoyuanFeng 29ae5f0
Merge branch 'main' into bf/cg-partition
BoyuanFeng b5972fa
move set/unset wrapper to support_torch_compile for frame-specific
BoyuanFeng 7570f4b
update test_attention_quant_pattern
BoyuanFeng c7ff7c4
Update vllm/config/compilation.py
BoyuanFeng 4a38b36
more tests
BoyuanFeng d4269d9
move wrapper set/unset to context manager
BoyuanFeng 20b9ef1
nit
BoyuanFeng e055458
update test
BoyuanFeng 45b7588
Merge branch 'main' into bf/cg-partition
BoyuanFeng 91c03a4
move maybe_use_cudagraph_partition_wrapper to decorators.py
BoyuanFeng 19787d3
test inductor graph partition only when >= torch2.9
BoyuanFeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,16 +3,21 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| import tempfile | ||
| from typing import Any, Optional, Union | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from tests.quantization.utils import is_quant_method_supported | ||
| from tests.v1.attention.utils import _Backend | ||
| from vllm import LLM, SamplingParams | ||
| from vllm.config import CompilationConfig, CompilationLevel, PassConfig | ||
| from vllm.attention.selector import global_force_attn_backend_context_manager | ||
| from vllm.config import (CompilationConfig, CompilationLevel, CUDAGraphMode, | ||
| PassConfig) | ||
| from vllm.platforms import current_platform | ||
| from vllm.utils import is_torch_equal_or_newer | ||
|
|
||
| from ..utils import create_new_process_for_each_test | ||
|
|
||
|
|
@@ -107,18 +112,70 @@ def test_full_graph( | |
| (CompilationConfig(level=CompilationLevel.PIECEWISE, | ||
| debug_dump_path=tempfile.gettempdir()), | ||
| ("facebook/opt-125m", {})), | ||
| ] + [ | ||
| # graph inductor partition | ||
| ( | ||
| CompilationConfig( | ||
| level=CompilationLevel.PIECEWISE, | ||
| # inductor graph partition uses | ||
| # torch._C.Tag.cudagraph_unsafe to specify splitting ops | ||
| use_inductor_graph_partition=True, | ||
| cudagraph_mode=CUDAGraphMode.PIECEWISE, | ||
| compile_sizes=[1, 2]), | ||
| model) for model in models_list(all=False) | ||
| if is_torch_equal_or_newer("2.9.0.dev") | ||
BoyuanFeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ]) | ||
| # only test some of the models | ||
| @create_new_process_for_each_test() | ||
| def test_custom_compile_config( | ||
| compilation_config: CompilationConfig, | ||
| model_info: tuple[str, dict[str, Any]], | ||
| ): | ||
| if (compilation_config.use_inductor_graph_partition | ||
| and not is_torch_equal_or_newer("2.9.0.dev")): | ||
| pytest.skip("inductor graph partition is only available " | ||
| "in PyTorch 2.9+") | ||
|
|
||
| model, model_kwargs = model_info | ||
| print(f"MODEL={model}") | ||
| run_model(compilation_config, model, model_kwargs) | ||
|
|
||
|
|
||
| def test_inductor_graph_partition_attn_fusion(caplog_vllm): | ||
| if not is_torch_equal_or_newer("2.9.0.dev"): | ||
| pytest.skip("inductor graph partition is only available " | ||
| "in PyTorch 2.9+") | ||
|
|
||
| model = "nvidia/Llama-4-Scout-17B-16E-Instruct-FP8" | ||
| compilation_config = CompilationConfig( | ||
| level=CompilationLevel.PIECEWISE, | ||
| use_inductor_graph_partition=True, | ||
| cudagraph_mode=CUDAGraphMode.PIECEWISE, | ||
| custom_ops=["+quant_fp8"], | ||
| pass_config=PassConfig(enable_attn_fusion=True, enable_noop=True), | ||
| ) | ||
| model_kwargs = { | ||
| "kv_cache_dtype": "fp8", | ||
| "max_model_len": 1024, | ||
| } | ||
| with caplog_vllm.at_level( | ||
| logging.DEBUG), global_force_attn_backend_context_manager( | ||
| _Backend.FLASHINFER): | ||
| run_model(compilation_config, model, model_kwargs) | ||
|
|
||
| try: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just disable the cache here instead? |
||
| assert ("Fused quantization onto 48 attention nodes" | ||
| in caplog_vllm.text), caplog_vllm.text | ||
| except AssertionError: | ||
| # Note: this message is only triggered when the compilation goes | ||
| # through the custom pass. Due to multiple layers of cache on | ||
| # PyTorch side, the compilation of a graph may be cached such | ||
| # that custom pass directly goes through cache. In this case, | ||
| # we go through this branch and assert that the pass is not | ||
| # triggered. | ||
| assert "Fused quantization" not in caplog_vllm.text | ||
|
|
||
|
|
||
| def run_model(compile_config: Union[int, CompilationConfig], model: str, | ||
| model_kwargs: dict[str, Any]): | ||
| prompts = [ | ||
|
|
||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.