-
Notifications
You must be signed in to change notification settings - Fork 702
feat: configure cudagraph capture batch sizes #4573
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
Open
CUHKSZzxy
wants to merge
6
commits into
InternLM:main
Choose a base branch
from
CUHKSZzxy:feat/cudagraph-capture-batch-sizes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cd23a52
feat: configure cudagraph capture batch sizes
CUHKSZzxy 6593d97
chore: simplify cudagraph capture sizes
CUHKSZzxy f540f50
fix: require cudagraph capture coverage
CUHKSZzxy 93496c5
fix: normalize cudagraph capture sizes
CUHKSZzxy 81c7872
Merge remote-tracking branch 'upstream/main' into feat/cudagraph-capt…
CUHKSZzxy 36e67a4
Merge branch 'main' into feat/cudagraph-capture-batch-sizes
CUHKSZzxy 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
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
55 changes: 55 additions & 0 deletions
55
tests/pytorch/engine/test_cudagraph_capture_batch_sizes.py
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 |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # Copyright (c) OpenMMLab. All rights reserved. | ||
| import pytest | ||
|
|
||
| from lmdeploy.messages import PytorchEngineConfig | ||
| from lmdeploy.pytorch.backends.cuda.graph_runner import CUDAGraphRunner | ||
| from lmdeploy.pytorch.config import CacheConfig | ||
| from lmdeploy.pytorch.engine.config_builder import ConfigBuilder | ||
|
|
||
|
|
||
| def _cache_config(max_batches=8, cudagraph_capture_batch_sizes=None): | ||
| return CacheConfig(max_batches=max_batches, | ||
| block_size=64, | ||
| num_cpu_blocks=0, | ||
| num_gpu_blocks=1, | ||
| cudagraph_capture_batch_sizes=cudagraph_capture_batch_sizes) | ||
|
|
||
|
|
||
| def test_custom_capture_batch_sizes_include_max_batch_size(): | ||
| engine_config = PytorchEngineConfig(max_batch_size=8, cudagraph_capture_batch_sizes=[4, 1, 4, 16]) | ||
|
|
||
| engine_config = ConfigBuilder.update_engine_config(engine_config) | ||
|
|
||
| assert engine_config.cudagraph_capture_batch_sizes == [1, 4, 8] | ||
|
|
||
|
|
||
| def test_cache_config_normalizes_capture_batch_sizes(): | ||
| cache_config = _cache_config(max_batches=8, cudagraph_capture_batch_sizes=[4, 1, 4, 16]) | ||
|
|
||
| assert cache_config.cudagraph_capture_batch_sizes == [1, 4, 8] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('sizes', [[], [0], [-1], [1.5], ['1'], [16]]) | ||
| def test_invalid_capture_batch_sizes_raise(sizes): | ||
| with pytest.raises(AssertionError): | ||
| _cache_config(max_batches=8, cudagraph_capture_batch_sizes=sizes) | ||
|
|
||
|
|
||
| def test_capture_batch_size_miss_raises(): | ||
| engine_config = PytorchEngineConfig(max_batch_size=8, cudagraph_capture_batch_sizes=[1, 4]) | ||
| engine_config = ConfigBuilder.update_engine_config(engine_config) | ||
| runner = object.__new__(CUDAGraphRunner) | ||
| runner.cache_config = ConfigBuilder.build_cache_config(engine_config) | ||
|
|
||
| assert runner._get_capture_tokens(5) == 8 | ||
| with pytest.raises(AssertionError): | ||
| runner._get_capture_tokens(9) | ||
|
|
||
|
|
||
| def test_graph_runner_defensively_normalizes_capture_batch_sizes(): | ||
| cache_config = _cache_config(max_batches=8, cudagraph_capture_batch_sizes=[1, 8]) | ||
| cache_config.cudagraph_capture_batch_sizes = [4, 1, 4, 16] | ||
| runner = object.__new__(CUDAGraphRunner) | ||
| runner.cache_config = cache_config | ||
|
|
||
| assert runner.get_capture_batch_sizes() == [1, 4, 8] |
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.