-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NeMo UX] Support generating datasets using different train/valid/tes…
…t distributions (#9771) (#9841) * support building train/valid/test datasets from separate distributions * add minimal test * Apply isort and black reformatting * set limit_val_batches for nemo 2 example * improve assert statement * Apply isort and black reformatting --------- Signed-off-by: ashors1 <[email protected]> Signed-off-by: ashors1 <[email protected]> Co-authored-by: Anna Shors <[email protected]> Co-authored-by: ashors1 <[email protected]>
- Loading branch information
1 parent
7ce4393
commit 8ecb8c8
Showing
3 changed files
with
103 additions
and
12 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
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
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,66 @@ | ||
import pytest | ||
|
||
import nemo.lightning as nl | ||
from nemo.collections.llm.gpt.data.pre_training import PreTrainingDataModule | ||
from nemo.collections.nlp.modules.common.tokenizer_utils import get_nmt_tokenizer | ||
|
||
DATA_PATH = "/home/TestData/nlp/megatron_gpt/data/gpt/simple_wiki_gpt_preproc_text_document" | ||
VOCAB_PATH = "/home/TestData/nlp/megatron_gpt/data/gpt/vocab.json" | ||
MERGES_PATH = "/home/TestData/nlp/megatron_gpt/data/gpt/merges.txt" | ||
|
||
|
||
@pytest.fixture | ||
def tokenizer(): | ||
return get_nmt_tokenizer( | ||
"megatron", | ||
"GPT2BPETokenizer", | ||
vocab_file=VOCAB_PATH, | ||
merges_file=MERGES_PATH, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def trainer(): | ||
return nl.Trainer( | ||
accelerator="cpu", | ||
max_steps=1, | ||
) | ||
|
||
|
||
def test_single_data_distribution(tokenizer, trainer): | ||
|
||
data = PreTrainingDataModule( | ||
paths=[DATA_PATH], | ||
seq_length=512, | ||
micro_batch_size=2, | ||
global_batch_size=2, | ||
tokenizer=tokenizer, | ||
) | ||
data.trainer = trainer | ||
|
||
## AssertioneError because we are trying to do eval on the whole | ||
## dataset with just a single distribution | ||
with pytest.raises(AssertionError): | ||
data.setup(stage="dummy") | ||
|
||
trainer.limit_val_batches = 5 | ||
## this should succeed | ||
data.setup(stage="dummy") | ||
|
||
|
||
def test_multiple_data_distributions(tokenizer, trainer): | ||
data = PreTrainingDataModule( | ||
paths={ | ||
"train": ['1', DATA_PATH], | ||
"validation": [DATA_PATH, DATA_PATH], | ||
"test": ['1', DATA_PATH], | ||
}, | ||
seq_length=512, | ||
micro_batch_size=2, | ||
global_batch_size=2, | ||
tokenizer=tokenizer, | ||
) | ||
data.trainer = trainer | ||
|
||
## this should succeed | ||
data.setup(stage="dummy") |