Repository navigation
fix: allocate calibration samples correctly when mixing datasets - #2526
Open
unknownhackerworld wants to merge 1 commit into
Open
unknownhackerworld wants to merge 1 commit into
unknownhackerworld wants to merge 1 commit into
Conversation
When several calibration datasets are combined, _get_dataset_impl sorts them by length so that leftover budget from small datasets flows to larger ones. Two problems broke that: - The datasets and their names were reordered but `lens` was not, so each dataset was capped by another dataset's length. A small dataset listed after a large one was asked for more rows than it has, and the total came out short of nsamples. - When any dataset used `num=`, the remaining budget was always divided by the total number of unspecified datasets instead of the number still to be filled, so later datasets got too few samples. Reorder `lens` together with the datasets and divide by the number of unspecified datasets that are still left. Add unit tests for both cases. Signed-off-by: Allen Joseph G <63872540+unknownhackerworld@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
All reviewed changes are covered by regression tests with no unresolved review issues.
No open issues 🎉
What changed in this PR
Fixes calibration sample allocation when mixing datasets, including :num= configurations.
Changes:
- Keeps dataset lengths aligned after sorting.
- Correctly distributes remaining samples.
- Adds regression tests for both allocation bugs.
| File | Description |
|---|---|
test/unit/common/utils/test_calib_dataset_helpers.py |
Adds allocation regression tests. |
auto_round/calib_dataset.py |
Fixes mixed-dataset sample allocation. |
Review effort: Lite
Collaborator
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
When several calibration datasets are combined (for example
--dataset "NeelNanda/pile-10k,BAAI/CCI3-HQ"or with:num=),_get_dataset_implinauto_round/calib_dataset.pycan produce fewer thannsamplessamples and split them unevenly. This PR fixes the two bugs behind that in the mixing block.Root cause
The mixing code sorts the datasets by length (smallest first) and then hands out the budget so that whatever a small dataset cannot provide flows to the larger ones after it. Two things break that:
lensis not reordered. Afterres = sorted(zip(indices, lens), ...),datasetsanddataset_namesare reordered, butlensis left in the original order.target_cnt = min(target_cnt, lens[i])then caps each dataset by another dataset's length. When a small dataset is listed after a large one, it is asked for more rows than it has:Dataset.selectraisesIndexError,select_datasetfalls back to the slow iterate-and-pandas path, which returns only the rows that exist, and the large dataset is capped at the small one's length. Example: withbig(100 rows) listed beforesmall(5 rows) andnsamples=20, tracing the code gives 10 samples (5 + 5) instead of 20 (15 + 5).Wrong divisor when
num=is used. With anynum=entry, the remaining budget is always divided bylen(datasets) - len(data_lens), the total number of unspecified datasets, even thoughcntalready includes what earlier datasets took. Later datasets therefore get too little. Example:a:num=4,b,c(100 rows each) withnsamples=20gives 4 + 8 + 4 = 16 instead of 4 + 8 + 8 = 20. Withoutnum=the code divides bylen(datasets) - i, which is the intended "datasets still left" count.Fix
lenstogether withdatasetsanddataset_names.num=this gives the same result as the oldlen(datasets) - i, so that path is unchanged.Alternatives considered
Type of Change
Bug fix
Related Issues
None found.
Checklist Before Submitting
Testing
TestMixedDatasetSampleAllocationtotest/unit/common/utils/test_calib_dataset_helpers.py. It registers small in-memory datasets inCALIB_DATASETSand calls_get_dataset_impldirectly:test_small_dataset_listed_last_does_not_shrink_total:big(100) +small(5),nsamples=20, expects 15 + 5.test_remaining_budget_is_shared_with_num_option:a:num=4,b,c,nsamples=20, expects 4 + 8 + 8.pytest test/unit/common/utils/test_calib_dataset_helpers.py: 40 passed (CPU, torch CPU wheel). With the fix stashed and only the tests applied, both new tests fail.black(line length 120) leaves both files unchanged.Disclosure: this change and description were prepared with the help of an AI coding assistant.