-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor RequestGenerator to use threading and update test suite
Refactored RequestGenerator class: - Replaced asyncio.Queue with Queue from the queue module for thread safety. - Utilized threading for background queue population to ensure non-blocking request generation. - Removed the start method as threading automatically starts the background task in async mode. - Ensured that the _populate_queue method runs in a background thread to keep the queue populated. - Implemented clean shutdown with the stop method joining the background thread. Updated unit tests: - Added test_request_generator_sync_constructor and test_request_generator_async_constructor to verify constructor behavior. - Added tests for __repr__ and __iter__ methods. - Added tests to ensure create_item raises NotImplementedError if not overridden. - Added tests to verify __iter__ calls create_item the expected number of times. Separated test files: - Created tests/unit/request/test_base.py for unit tests. - Created tests/integration/request/test_base.py for integration tests. Unit tests: - Verified the construction of the class with different input parameters. - Mocked AutoTokenizer for testing tokenizer initialization with both a class implementation and a string alias. - Ensured that the __iter__ method works correctly in both sync and async modes. - Verified that create_item is called the expected number of times. Integration tests: - Tested tokenizer construction with both a Hugging Face tokenizer and a string alias, ensuring the correct tokenizer is created.
- Loading branch information
Showing
4 changed files
with
138 additions
and
50 deletions.
There are no files selected for viewing
This file contains 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
File renamed without changes.
This file contains 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,23 @@ | ||
import pytest | ||
from transformers import AutoTokenizer, PreTrainedTokenizerBase | ||
from guidellm.core.request import TextGenerationRequest | ||
from guidellm.request.base import RequestGenerator | ||
|
||
|
||
class TestRequestGenerator(RequestGenerator): | ||
def create_item(self) -> TextGenerationRequest: | ||
return TextGenerationRequest(prompt="Test prompt") | ||
|
||
|
||
@pytest.mark.smoke | ||
def test_request_generator_with_hf_tokenizer(): | ||
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased") | ||
generator = TestRequestGenerator(tokenizer=tokenizer) | ||
assert generator.tokenizer == tokenizer | ||
|
||
|
||
@pytest.mark.smoke | ||
def test_request_generator_with_string_tokenizer(): | ||
generator = TestRequestGenerator(tokenizer="bert-base-uncased") | ||
assert isinstance(generator.tokenizer, PreTrainedTokenizerBase) | ||
assert generator.tokenizer.name_or_path == "bert-base-uncased" |
This file contains 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