(self, dataset: Dataset, num_workers: int = 0, **kwargs)
| 77 | """ |
| 78 | |
| 79 | def __init__(self, dataset: Dataset, num_workers: int = 0, **kwargs) -> None: |
| 80 | if num_workers == 0: |
| 81 | # when num_workers > 0, random states are determined by worker_init_fn |
| 82 | # this is to make the behavior consistent when num_workers == 0 |
| 83 | # torch.int64 doesn't work well on some versions of windows |
| 84 | _g = torch.random.default_generator if kwargs.get("generator") is None else kwargs["generator"] |
| 85 | init_seed = _g.initial_seed() |
| 86 | _seed = torch.empty((), dtype=torch.int64).random_(generator=_g).item() |
| 87 | set_rnd(dataset, int(_seed)) |
| 88 | _g.manual_seed(init_seed) |
| 89 | if "collate_fn" not in kwargs: |
| 90 | kwargs["collate_fn"] = list_data_collate |
| 91 | if "worker_init_fn" not in kwargs: |
| 92 | kwargs["worker_init_fn"] = worker_init_fn |
| 93 | |
| 94 | if ( |
| 95 | "multiprocessing_context" in kwargs |
| 96 | and kwargs["multiprocessing_context"] == "spawn" |
| 97 | and not get_track_meta() |
| 98 | ): |
| 99 | warnings.warn( |
| 100 | "Please be aware: Return type of the dataloader will not be a Tensor as expected but" |
| 101 | " a MetaTensor instead! This is because 'spawn' creates a new process where _TRACK_META" |
| 102 | " is initialized to True again. Context:_TRACK_META is set to False and" |
| 103 | " multiprocessing_context to spawn" |
| 104 | ) |
| 105 | |
| 106 | super().__init__(dataset=dataset, num_workers=num_workers, **kwargs) |
nothing calls this directly
no test coverage detected