(self)
| 156 | |
| 157 | # patch trainer |
| 158 | def _get_train_sampler(self) -> Optional[torch.utils.data.Sampler]: |
| 159 | if self.train_dataset is None or not has_length(self.train_dataset): |
| 160 | return None |
| 161 | # Build the sampler. |
| 162 | if self.args.group_by_length: |
| 163 | lengths = [] |
| 164 | for dataset in self.train_dataset.datasets: |
| 165 | lengths = lengths + dataset.length |
| 166 | model_input_name = self.tokenizer.model_input_names[0] if self.tokenizer is not None else None |
| 167 | return LengthGroupedSampler( |
| 168 | self.args.train_batch_size, |
| 169 | world_size=self.args.world_size * self.args.gradient_accumulation_steps, |
| 170 | # self.args.train_batch_size * self.args.gradient_accumulation_steps, |
| 171 | dataset=self.train_dataset, |
| 172 | lengths=lengths, |
| 173 | model_input_name=model_input_name, |
| 174 | ) |
| 175 | else: |
| 176 | return RandomSampler(self.train_dataset) |
| 177 | |
| 178 | def replace_train_sampler(): |
| 179 | transformers.Trainer._get_train_sampler = _get_train_sampler |
nothing calls this directly
no test coverage detected