MCPcopy Create free account
hub / github.com/QWTforGithub/T2LDM / __init__

Method __init__

timm/data/distributed_sampler.py:65–99  ·  view source on GitHub ↗
(
            self,
            dataset,
            num_replicas=None,
            rank=None,
            shuffle=True,
            num_repeats=3,
            selected_round=256,
            selected_ratio=0,
    )

Source from the content-addressed store, hash-verified

63 """
64
65 def __init__(
66 self,
67 dataset,
68 num_replicas=None,
69 rank=None,
70 shuffle=True,
71 num_repeats=3,
72 selected_round=256,
73 selected_ratio=0,
74 ):
75 if num_replicas is None:
76 if not dist.is_available():
77 raise RuntimeError("Requires distributed package to be available")
78 num_replicas = dist.get_world_size()
79 if rank is None:
80 if not dist.is_available():
81 raise RuntimeError("Requires distributed package to be available")
82 rank = dist.get_rank()
83 self.dataset = dataset
84 self.num_replicas = num_replicas
85 self.rank = rank
86 self.shuffle = shuffle
87 self.num_repeats = num_repeats
88 self.epoch = 0
89 self.num_samples = int(math.ceil(len(self.dataset) * num_repeats / self.num_replicas))
90 self.total_size = self.num_samples * self.num_replicas
91 # Determine the number of samples to select per epoch for each rank.
92 # num_selected logic defaults to be the same as original RASampler impl, but this one can be tweaked
93 # via selected_ratio and selected_round args.
94 selected_ratio = selected_ratio or num_replicas # ratio to reduce selected samples by, num_replicas if 0
95 if selected_round:
96 self.num_selected_samples = int(math.floor(
97 len(self.dataset) // selected_round * selected_round / selected_ratio))
98 else:
99 self.num_selected_samples = int(math.ceil(len(self.dataset) / selected_ratio))
100
101 def __iter__(self):
102 # deterministically shuffle based on epoch

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected