Base class for all data modules in LitGPT.
| 14 | |
| 15 | |
| 16 | class DataModule(LightningDataModule): |
| 17 | """Base class for all data modules in LitGPT.""" |
| 18 | |
| 19 | """Whether to mask the prompt section from the label (with ``ignore_index``).""" |
| 20 | mask_prompt: bool = True |
| 21 | """The style to apply to instruction prompts. See `litgpt.prompts` for a list of available styles.""" |
| 22 | prompt_style: Union[str, PromptStyle] = 'chatml' |
| 23 | """The index to use for elements to be ignored in the label.""" |
| 24 | ignore_index: int = -100 |
| 25 | """The random seed for shuffling the dataset.""" |
| 26 | seed: int = 42 |
| 27 | """How many DataLoader processes to use for loading.""" |
| 28 | num_workers = max(1, cpu_count() // 2) # Use half of available cores |
| 29 | """The directory in which the downloaded dataset gets saved.""" |
| 30 | include_multiturn_conversations: bool = True |
| 31 | """The repo from where the data is downloaded""" |
| 32 | repo_id: str = '' |
| 33 | |
| 34 | @abstractmethod |
| 35 | def connect( |
| 36 | self, |
| 37 | tokenizer: Optional[Tokenizer] = None, |
| 38 | batch_size: int = 1, |
| 39 | max_seq_length: Optional[int] = None, |
| 40 | ) -> None: |
| 41 | """All settings that can't be determined at the time of instantiation need to be passed through here |
| 42 | before any dataloaders can be accessed. |
| 43 | """ |
| 44 | |
| 45 | def setup(self, stage: str = '') -> PreparedDataset: |
| 46 | # Stub is to redefine the default signature, because the concept of 'stage' does not exist in LitGPT |
| 47 | pass |
| 48 | |
| 49 | def __repr__(self) -> str: |
| 50 | return f'{self.__class__.__name__}()' |
| 51 | |
| 52 | |
| 53 | def get_sft_collate_fn( |
nothing calls this directly
no outgoing calls
no test coverage detected