-
Notifications
You must be signed in to change notification settings - Fork 453
Add batch token statistics logging to LengthAwareSampler
#2204
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
6 commits
Select commit
Hold shift + click to select a range
6202b20
feat(datasets): add batch token statistics logging to LengthAwareSampler
jwpark33 2786698
fix formatting
jwpark33 ed3a268
remove logging statement
jwpark33 985c54f
Merge branch 'main' into lengthawaresampler-log
kylesayrs 0690ff4
remove logging test
jwpark33 b7da8b5
Merge branch 'main' into lengthawaresampler-log
brian-dellabetta 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
Empty file.
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,42 @@ | ||
| from unittest.mock import patch | ||
|
|
||
| import pytest | ||
| from datasets import Dataset | ||
|
|
||
| from llmcompressor.datasets.utils import LengthAwareSampler | ||
|
|
||
|
|
||
| def _create_mock_dataset(lengths: list[int]) -> Dataset: | ||
| """Create a mock dataset with input_ids of specified lengths.""" | ||
| return Dataset.from_dict({"input_ids": [[0] * length for length in lengths]}) | ||
|
|
||
|
|
||
| class TestLengthAwareSampler: | ||
| """Tests for LengthAwareSampler batch statistics logging.""" | ||
|
|
||
| @pytest.mark.unit | ||
| def test_batch_size_parameter(self): | ||
| dataset = _create_mock_dataset([100, 200, 300]) | ||
| sampler = LengthAwareSampler(dataset, batch_size=4) | ||
| assert sampler.batch_size == 4 | ||
|
|
||
| @pytest.mark.unit | ||
| def test_logging_called_when_batch_size_greater_than_one(self): | ||
| dataset = _create_mock_dataset([100, 150, 200, 250]) | ||
|
|
||
| with patch("llmcompressor.datasets.utils.logger") as mock_logger: | ||
| LengthAwareSampler(dataset, batch_size=2) | ||
| debug_calls = [str(c) for c in mock_logger.debug.call_args_list] | ||
| assert any("Calculating batch statistics" in c for c in debug_calls) | ||
|
|
||
| @pytest.mark.unit | ||
| def test_tokens_added_calculation(self): | ||
| dataset = _create_mock_dataset([100, 200, 300, 150]) | ||
|
|
||
| with patch("llmcompressor.datasets.utils.logger") as mock_logger: | ||
| LengthAwareSampler(dataset, batch_size=2) | ||
|
|
||
| debug_calls = [str(c) for c in mock_logger.debug.call_args_list] | ||
| assert any( | ||
| "added (padding): 150" in c for c in debug_calls | ||
| ), f"Expected 'added (padding): 150' in {debug_calls}" |
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.