| 12 | |
| 13 | |
| 14 | class TrainerWithDatasetCheckpointing(Trainer): |
| 15 | |
| 16 | def _save_checkpoint(self, model, trial): |
| 17 | super()._save_checkpoint(model, trial) |
| 18 | |
| 19 | self.accelerator.wait_for_everyone() |
| 20 | |
| 21 | rank = torch.distributed.get_rank() |
| 22 | size = torch.distributed.get_world_size() |
| 23 | |
| 24 | model_ckpt_path = f"{PREFIX_CHECKPOINT_DIR}-{self.state.global_step}" |
| 25 | run_dir = self._get_output_dir(trial=trial) |
| 26 | model_ckpt_path = os.path.join(run_dir, model_ckpt_path) |
| 27 | |
| 28 | dataset_ckpt_path = f"{model_ckpt_path}/dataset_ckpt-{rank:{len(str(size))}d}-{size}.pt" |
| 29 | dataset_ckpt_path = os.path.join(model_ckpt_path, dataset_ckpt_path) |
| 30 | |
| 31 | if isinstance(self.train_dataset, StreamingTrainingParquet): |
| 32 | |
| 33 | dataset_ckpt = { |
| 34 | 'data_path': self.train_dataset.data_path, |
| 35 | 'label_name': self.train_dataset.label_name, |
| 36 | 'pivot': self.train_dataset.pivot, 'size': self.train_dataset.size, |
| 37 | 'table_idx': self.train_dataset.table_idx, |
| 38 | 'table_num': self.train_dataset.table_num, |
| 39 | 'table_buffer': self.train_dataset.table_buffer, |
| 40 | 'sample_idx': self.train_dataset.sample_idx, |
| 41 | 'sample_num': self.train_dataset.sample_num, |
| 42 | 'token_buffer': self.train_dataset.token_buffer, |
| 43 | } |
| 44 | |
| 45 | torch.save(dataset_ckpt, dataset_ckpt_path) |
| 46 | |
| 47 | elif isinstance(self.train_dataset, StreamingTrainingJsonlZSD) or isinstance(self.train_dataset, RepeatedTrainingJsonlZSD): |
| 48 | |
| 49 | dataset_ckpt = { |
| 50 | 'data_path': self.train_dataset.data_path, |
| 51 | 'label_name': self.train_dataset.label_name, |
| 52 | 'pivot': self.train_dataset.pivot, 'size': self.train_dataset.size, |
| 53 | 'sample_idx': self.train_dataset.sample_idx, |
| 54 | 'token_buffer': self.train_dataset.token_buffer, |
| 55 | } |
| 56 | |
| 57 | torch.save(dataset_ckpt, dataset_ckpt_path) |
no outgoing calls
no test coverage detected