forked from Lightning-AI/litgpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: awaelchli <[email protected]>
- Loading branch information
Showing
4 changed files
with
63 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright Lightning AI. Licensed under the Apache License 2.0, see LICENSE file. | ||
|
||
|
||
from dataclasses import dataclass, field | ||
from pathlib import Path | ||
from lit_gpt.data.alpaca import Alpaca | ||
from lit_gpt.data import SFTDataset | ||
|
||
|
||
@dataclass | ||
class Alpaca2k(Alpaca): | ||
"""Alpaca2k data module for supervised finetuning.""" | ||
|
||
test_split_fraction: float = 0.05 # to get exactly 100 test samples, | ||
"""The fraction of the dataset to use for the test/validation dataset. The rest is used for training.""" | ||
download_dir: Path = Path("./data/alpaca2k") | ||
"""The directory in which the downloaded datasetgets saved.""" | ||
repo_id: str = field(repr=False, default="mhenrichsen/alpaca_2k_test") | ||
"""The URL from where to download the dataset.""" | ||
file_name: str = field(repr=False, default="alpaca2k_data_cleaned_archive.json") | ||
"""The name of the dataset file to download.""" | ||
|
||
def prepare_data(self) -> None: | ||
from datasets import load_dataset | ||
|
||
load_dataset(self.repo_id, cache_dir=self.download_dir) | ||
|
||
def setup(self, stage: str = "") -> None: | ||
from datasets import load_dataset | ||
|
||
dataset = load_dataset(self.repo_id, cache_dir=self.download_dir) | ||
|
||
train_validation_split = dataset["train"].train_test_split(test_size=self.test_split_fraction, seed=self.seed) | ||
train_data = train_validation_split["train"] | ||
test_data = train_validation_split["test"] | ||
|
||
self.train_dataset = SFTDataset( | ||
data=train_data, | ||
tokenizer=self.tokenizer, | ||
prompt_style=self.prompt_style, | ||
max_seq_length=self.max_seq_length, | ||
mask_prompt=self.mask_prompt, | ||
ignore_index=self.ignore_index, | ||
) | ||
self.test_dataset = SFTDataset( | ||
data=test_data, | ||
tokenizer=self.tokenizer, | ||
prompt_style=self.prompt_style, | ||
max_seq_length=self.max_seq_length, | ||
mask_prompt=self.mask_prompt, | ||
ignore_index=self.ignore_index, | ||
) | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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