-
Notifications
You must be signed in to change notification settings - Fork 96
Multiple request rates #2
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 11 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
652fd68
add ability to pass in multiple request rates
DaltheCow bfcc329
running tests command is added to the Makefile
parfeniukink 44f8e41
rename to fixed rate profile generator
DaltheCow d8469cb
increment rate index
DaltheCow eb03706
combine constanct and poisson Profile creation
DaltheCow 9a0c582
throw error if user passes in rate in synchronous mode
DaltheCow fb1ebcb
refactor to better handle creating profile generator
DaltheCow bf72422
test base ProfileGenerator class
DaltheCow 98f79c4
update fixed rate profile generator, add tests, set up initial execut…
DaltheCow c0284a3
test executor run method
DaltheCow d915515
test sweep profile generator
DaltheCow 993610a
merge main
DaltheCow ffc0e7b
fix test indentation
DaltheCow b41b74a
fix some improper imports
DaltheCow c78d2ba
Merge branch 'main' into multiple-request-rates
DaltheCow 98ff5e4
merge main, handle merge conflicts minus the tests
DaltheCow 21774cd
wip
DaltheCow 1d3a7cf
wip
DaltheCow 79c03ce
fix all broken tests
DaltheCow 8833ae3
run make style
DaltheCow 2ec371b
fix linting issues
DaltheCow 2361916
remove unused import
DaltheCow ca8e553
fix type issue
DaltheCow ce460de
pytest.init_options section is restored
3062fba
format pyproject.toml file
7524977
Merge branch 'main' into multiple-request-rates
markurtz 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import pytest | ||
| from unittest.mock import MagicMock, patch | ||
| from src.guidellm.backend.base import Backend | ||
| from src.guidellm.executor.executor import Executor | ||
| from src.guidellm.executor.profile_generator import Profile, ProfileGenerator | ||
| from src.guidellm.request.base import RequestGenerator | ||
| from src.guidellm.scheduler.load_generator import LoadGenerationModes | ||
|
|
||
| def test_executor_creation(): | ||
| mock_request_generator = MagicMock(spec=RequestGenerator) | ||
| mock_backend = MagicMock(spec=Backend) | ||
| rate_type = "sweep" | ||
| profile_args = None | ||
| max_requests = None, | ||
| max_duration = None, | ||
| executor = Executor(mock_request_generator, mock_backend, rate_type, profile_args, max_requests, max_duration); | ||
| assert executor.request_generator == mock_request_generator | ||
| assert executor.backend == mock_backend | ||
| assert executor.max_requests == max_requests | ||
| assert executor.max_duration == max_duration | ||
DaltheCow marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_request_generator(): | ||
| return MagicMock(spec=RequestGenerator) | ||
|
|
||
| @pytest.fixture | ||
| def mock_backend(): | ||
| return MagicMock(spec=Backend) | ||
|
|
||
| @pytest.fixture | ||
| def mock_scheduler(): | ||
| with patch('src.guidellm.executor.executor.Scheduler') as MockScheduler: | ||
| yield MockScheduler | ||
|
|
||
| def test_executor_run(mock_request_generator, mock_backend, mock_scheduler): | ||
|
|
||
| mock_profile_generator = MagicMock(spec=ProfileGenerator) | ||
| profiles = [ | ||
| Profile(load_gen_mode=LoadGenerationModes.CONSTANT, load_gen_rate=1.0), | ||
| Profile(load_gen_mode=LoadGenerationModes.CONSTANT, load_gen_rate=2.0), | ||
| None | ||
| ] | ||
| mock_profile_generator.next_profile.side_effect = profiles | ||
|
|
||
| with patch('src.guidellm.executor.executor.ProfileGenerator.create_generator', return_value=mock_profile_generator): | ||
| executor = Executor( | ||
| request_generator=mock_request_generator, | ||
| backend=mock_backend, | ||
| rate_type="constant", | ||
| profile_args={"rate_type": "constant", "rate": [1.0, 2.0]}, | ||
| max_requests=10, | ||
| max_duration=100 | ||
| ) | ||
|
|
||
| mock_benchmark = MagicMock() | ||
| mock_scheduler.return_value.run.return_value = mock_benchmark | ||
|
|
||
| report = executor.run() | ||
|
|
||
|
|
||
| assert mock_scheduler.call_count == 2 | ||
| assert len(report.benchmarks) == 2 | ||
| assert report.benchmarks[0] == mock_benchmark | ||
| assert report.benchmarks[1] == mock_benchmark | ||
| calls = mock_scheduler.call_args_list | ||
| assert calls[0][1]['load_gen_mode'] == LoadGenerationModes.CONSTANT | ||
| assert calls[0][1]['load_gen_rate'] == 1.0 | ||
| assert calls[1][1]['load_gen_mode'] == LoadGenerationModes.CONSTANT | ||
| assert calls[1][1]['load_gen_rate'] == 2.0 | ||
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,129 @@ | ||
| import numpy | ||
| import pytest | ||
| from unittest.mock import MagicMock | ||
| from guidellm.executor import (ProfileGenerator, FixedRateProfileGenerator, SweepProfileGenerator) | ||
| from src.guidellm.core.result import TextGenerationBenchmark, TextGenerationBenchmarkReport | ||
| from src.guidellm.executor import profile_generator | ||
| from src.guidellm.scheduler.load_generator import LoadGenerationModes | ||
|
|
||
| def test_invalid_profile_generation_mode_error(): | ||
| rate = [1] | ||
| rate_type = "constant" | ||
| profile_mode = "burst" | ||
| with pytest.raises(ValueError, match=f"Invalid profile generation mode: {profile_mode}"): | ||
| ProfileGenerator.create_generator(profile_mode, **({ "rate": rate, "rate_type": rate_type})) | ||
|
|
||
| # Fixed Rate Profile Generator | ||
|
|
||
| def test_fixed_rate_profile_generator_creation(): | ||
| rate = [1] | ||
| rate_type = "constant" | ||
| profile_generator = ProfileGenerator.create_generator("fixed_rate", **({ "rate": rate, "rate_type": rate_type})) | ||
| assert isinstance(profile_generator, FixedRateProfileGenerator) | ||
| assert profile_generator._rates == rate | ||
| assert profile_generator._rate_type == rate_type | ||
| assert profile_generator._rate_index == 0 | ||
| assert profile_generator._rate_index == 0 | ||
|
|
||
| def test_synchronous_mode_rate_list_error(): | ||
| rate = [1] | ||
| rate_type = "synchronous" | ||
| with pytest.raises(ValueError, match="custom rates are not supported in synchronous mode"): | ||
| ProfileGenerator.create_generator("fixed_rate", **({ "rate": rate, "rate_type": rate_type})) | ||
|
|
||
| def test_next_profile_with_multiple_rates(): | ||
| rates = [1, 2] | ||
| rate_type = "constant" | ||
| profile_generator = ProfileGenerator.create_generator("fixed_rate", **({ "rate": rates, "rate_type": rate_type})) | ||
| mock_report = MagicMock(spec=TextGenerationBenchmarkReport) | ||
| for rate in rates: | ||
| current_profile = profile_generator.next_profile(mock_report) | ||
| assert current_profile.load_gen_rate == rate | ||
| assert current_profile.load_gen_mode.name == LoadGenerationModes.CONSTANT.name | ||
| assert profile_generator.next_profile(mock_report) == None | ||
|
|
||
| def test_next_profile_with_sync_mode(): | ||
| rate_type = "synchronous" | ||
| profile_generator = ProfileGenerator.create_generator("fixed_rate", **({ "rate_type": rate_type})) | ||
| mock_report = MagicMock(spec=TextGenerationBenchmarkReport) | ||
| current_profile = profile_generator.next_profile(mock_report) | ||
| assert current_profile.load_gen_rate == None | ||
| assert current_profile.load_gen_mode.name == LoadGenerationModes.SYNCHRONOUS.name | ||
| assert profile_generator.next_profile(mock_report) == None | ||
|
|
||
| # Sweep Profile Generator | ||
|
|
||
| def test_sweep_profile_generator_creation(): | ||
| profile_generator = ProfileGenerator.create_generator("sweep", **({})) | ||
| assert isinstance(profile_generator, SweepProfileGenerator) | ||
| assert profile_generator._sync_run == False | ||
| assert profile_generator._max_found == False | ||
| assert profile_generator._pending_rates == None | ||
| assert profile_generator._pending_rates == None | ||
|
|
||
| def test_first_profile_is_synchronous(): | ||
| profile_generator = ProfileGenerator.create_generator("sweep") | ||
| mock_report = MagicMock(spec=TextGenerationBenchmarkReport) | ||
| profile = profile_generator.next_profile(mock_report) | ||
| assert profile.load_gen_rate == None | ||
| assert profile.load_gen_mode.name == LoadGenerationModes.SYNCHRONOUS.name | ||
|
|
||
| def test_rate_doubles(): | ||
| profile_generator = ProfileGenerator.create_generator("sweep") | ||
| mock_report = MagicMock(spec=TextGenerationBenchmarkReport) | ||
| mock_benchmark = MagicMock(spec=TextGenerationBenchmark) | ||
| mock_benchmark.overloaded = False | ||
| mock_benchmark.args_rate = 2.0 | ||
| mock_benchmark.request_rate = 2.0 | ||
| benchmarks = [ | ||
| mock_benchmark | ||
| ] | ||
| mock_report.benchmarks = benchmarks | ||
| profile = profile_generator.next_profile(mock_report) | ||
|
|
||
| profile = profile_generator.next_profile(mock_report) | ||
| assert profile.load_gen_rate == 4.0 | ||
|
|
||
| def test_max_found(): | ||
| profile_generator = ProfileGenerator.create_generator("sweep") | ||
| mock_report = MagicMock(spec=TextGenerationBenchmarkReport) | ||
| mock_benchmark = MagicMock(spec=TextGenerationBenchmark) | ||
| mock_benchmark.overloaded = False | ||
| mock_benchmark.args_rate = 2.0 | ||
| mock_benchmark.request_rate = 2.0 | ||
| mock_overloaded_benchmark = MagicMock(spec=TextGenerationBenchmark) | ||
| mock_overloaded_benchmark.overloaded = True | ||
| mock_overloaded_benchmark.args_rate = 4.0 | ||
| mock_overloaded_benchmark.request_rate = 4.0 | ||
| benchmarks = [ | ||
| mock_benchmark, | ||
| mock_overloaded_benchmark | ||
| ] | ||
| mock_report.benchmarks = benchmarks | ||
|
|
||
| profile_generator.next_profile(mock_report) | ||
| profile = profile_generator.next_profile(mock_report) | ||
|
|
||
| # if benchmark wasn't overloaded, rate would have doubled to 8 | ||
| assert profile.load_gen_rate == 2.0 | ||
|
|
||
| def test_pending_rates(): | ||
| profile_generator = ProfileGenerator.create_generator("sweep") | ||
| mock_report = MagicMock(spec=TextGenerationBenchmarkReport) | ||
| mock_benchmark = MagicMock(spec=TextGenerationBenchmark) | ||
| mock_benchmark.overloaded = False | ||
| mock_benchmark.args_rate = 2.0 | ||
| mock_benchmark.request_rate = 2.0 | ||
| mock_overloaded_benchmark = MagicMock(spec=TextGenerationBenchmark) | ||
| mock_overloaded_benchmark.overloaded = True | ||
| mock_overloaded_benchmark.args_rate = 8.0 | ||
| mock_overloaded_benchmark.request_rate = 8.0 | ||
| benchmarks = [ | ||
| mock_benchmark, | ||
| mock_overloaded_benchmark | ||
| ] | ||
| mock_report.benchmarks = benchmarks | ||
| profile = profile_generator.next_profile(mock_report) | ||
| for expected_rate in numpy.linspace(2.0, 8.0, 10): | ||
| profile = profile_generator.next_profile(mock_report) | ||
| assert profile.load_gen_rate == expected_rate |
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.