-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Make HFDatasetDataModule a datasets.load_dataset wrapper #11500
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
29 commits
Select commit
Hold shift + click to select a range
a05a035
Make HfDatasetDataModule a datasets.load_dataset wrapper
akoumpa 8cacad8
add logging
akoumpa d863a58
fix
akoumpa 23ff850
Update HFDatasetDataModule
akoumpa ca25a96
refactor
akoumpa 635499e
refactor fixup
akoumpa b47c40d
refactor fixup #2
akoumpa 56c29ac
do not expand
akoumpa 8ce2ba7
fix
akoumpa e55dc2e
fix
akoumpa 1b711aa
fix
akoumpa 8047ecb
fix
akoumpa 1b5989d
fix
akoumpa cd446be
doc
akoumpa 2777d2f
doc
akoumpa 2478246
add synonym
akoumpa 957e788
fix
akoumpa 3272f0f
fix
akoumpa 024f668
fix
akoumpa cf24f5f
typo
akoumpa 2ea77e1
Apply isort and black reformatting
akoumpa 4053b91
Add train/val/test attributes
akoumpa 1749ee7
Add test for hf-datamodule
akoumpa eceee08
Import lazily to avoid breaking with older megatron versions
akoumpa 107d0a4
bot happy
akoumpa ab30735
Apply isort and black reformatting
akoumpa 19c4da4
bot happy2
akoumpa afaaf8a
add doc-strings and collate-fn arg
akoumpa 8843d9e
Apply isort and black reformatting
akoumpa 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # Copyright (c) 2024, NVIDIA CORPORATION. All rights reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| from nemo.collections import llm | ||
|
|
||
| DATA_PATH = "/home/TestData/lite/hf_cache/squad/" | ||
|
|
||
|
|
||
| def test_load_single_split(): | ||
| ds = llm.HFDatasetDataModule( | ||
| path=DATA_PATH, | ||
| split='train', | ||
| seq_length=512, | ||
| micro_batch_size=2, | ||
| global_batch_size=2, | ||
| ) | ||
| from datasets.arrow_dataset import Dataset | ||
|
|
||
| assert isinstance(ds.dataset_splits, dict) | ||
| assert len(ds.dataset_splits) == 3 | ||
| assert 'train' in ds.dataset_splits | ||
| assert ds.dataset_splits['train'] is not None | ||
| assert ds.train is not None | ||
| assert isinstance(ds.dataset_splits['train'], Dataset) | ||
| assert 'val' in ds.dataset_splits | ||
| assert ds.dataset_splits['val'] is None | ||
| assert ds.val is None | ||
| assert 'test' in ds.dataset_splits | ||
| assert ds.dataset_splits['test'] is None | ||
| assert ds.test is None | ||
|
|
||
|
|
||
| def test_load_nonexistent_split(): | ||
| exception_msg = '' | ||
| expected_msg = '''Unknown split "this_split_name_should_not_exist". Should be one of ['train', 'validation'].''' | ||
| try: | ||
| llm.HFDatasetDataModule( | ||
| path=DATA_PATH, | ||
| split='this_split_name_should_not_exist', | ||
| seq_length=512, | ||
| micro_batch_size=2, | ||
| global_batch_size=2, | ||
| ) | ||
| except ValueError as e: | ||
| exception_msg = str(e) | ||
| assert exception_msg == expected_msg, exception_msg | ||
|
|
||
|
|
||
| def test_load_multiple_split(): | ||
| ds = llm.HFDatasetDataModule( | ||
| path=DATA_PATH, | ||
| split=['train', 'validation'], | ||
| seq_length=512, | ||
| micro_batch_size=2, | ||
| global_batch_size=2, | ||
| ) | ||
| from datasets.arrow_dataset import Dataset | ||
|
|
||
| assert isinstance(ds.dataset_splits, dict) | ||
| assert len(ds.dataset_splits) == 3 | ||
| assert 'train' in ds.dataset_splits | ||
| assert ds.dataset_splits['train'] is not None | ||
| assert ds.train is not None | ||
| assert isinstance(ds.dataset_splits['train'], Dataset) | ||
| assert isinstance(ds.train, Dataset) | ||
| assert 'val' in ds.dataset_splits | ||
| assert ds.dataset_splits['val'] is not None | ||
| assert ds.val is not None | ||
| assert isinstance(ds.dataset_splits['val'], Dataset) | ||
| assert isinstance(ds.val, Dataset) | ||
| assert 'test' in ds.dataset_splits | ||
| assert ds.dataset_splits['test'] is None | ||
| assert ds.test is None | ||
|
|
||
|
|
||
| def test_validate_dataset_asset_accessibility_file_does_not_exist(): | ||
| raised_exception = False | ||
| try: | ||
| llm.HFDatasetDataModule( | ||
| path="/this/path/should/not/exist/", | ||
| seq_length=512, | ||
| micro_batch_size=2, | ||
| global_batch_size=2, | ||
| ) | ||
| except FileNotFoundError: | ||
| raised_exception = True | ||
|
|
||
| assert raised_exception == True, "Expected to raise a FileNotFoundError" | ||
|
|
||
|
|
||
| def test_validate_dataset_asset_accessibility_file_is_none(): # tokenizer, trainer): | ||
| raised_exception = False | ||
| try: | ||
| llm.HFDatasetDataModule( | ||
| path=None, | ||
| seq_length=512, | ||
| micro_batch_size=2, | ||
| global_batch_size=2, | ||
| ) | ||
| except TypeError: | ||
| raised_exception = True | ||
|
|
||
| assert raised_exception == True, "Expected to raise a ValueError" |
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.