" Shuffles the data. Args: loader (loader): data loader to perform shuffle. cur_epoch (int): number of the current epoch.
(loader, cur_epoch)
| 171 | |
| 172 | |
| 173 | def shuffle_dataset(loader, cur_epoch): |
| 174 | """ " |
| 175 | Shuffles the data. |
| 176 | Args: |
| 177 | loader (loader): data loader to perform shuffle. |
| 178 | cur_epoch (int): number of the current epoch. |
| 179 | """ |
| 180 | if ( |
| 181 | loader._dataset_kind |
| 182 | == torch.utils.data.dataloader._DatasetKind.Iterable |
| 183 | ): |
| 184 | if hasattr(loader.dataset, "sampler"): |
| 185 | sampler = loader.dataset.sampler |
| 186 | else: |
| 187 | raise RuntimeError( |
| 188 | "Unknown sampler for IterableDataset when shuffling dataset" |
| 189 | ) |
| 190 | else: |
| 191 | sampler = ( |
| 192 | loader.batch_sampler.sampler |
| 193 | if isinstance(loader.batch_sampler, ShortCycleBatchSampler) |
| 194 | else loader.sampler |
| 195 | ) |
| 196 | assert isinstance( |
| 197 | sampler, (RandomSampler, DistributedSampler) |
| 198 | ), "Sampler type '{}' not supported".format(type(sampler)) |
| 199 | # RandomSampler handles shuffling automatically |
| 200 | if isinstance(sampler, DistributedSampler): |
| 201 | # DistributedSampler shuffles data based on epoch |
| 202 | sampler.set_epoch(cur_epoch) |
nothing calls this directly
no outgoing calls
no test coverage detected