MCPcopy Create free account
hub / github.com/BIT-DataLab/LakeBench / produce_data

Function produce_data

join/Deepjoin/all-mpnet-base-v2/train_script.py:168–220  ·  view source on GitHub ↗
(args, queue, filepaths, dataset_indices)

Source from the content-addressed store, hash-verified

166
167
168def produce_data(args, queue, filepaths, dataset_indices):
169 global_batch_size = args.batch_size*args.nprocs #Global batch size
170 size_per_dataset = int(global_batch_size / args.datasets_per_batch) #How many datasets per batch
171 num_same_dataset = int(size_per_dataset / args.batch_size)
172 print("producer", "global_batch_size", global_batch_size)
173 print("producer", "size_per_dataset", size_per_dataset)
174 print("producer", "num_same_dataset", num_same_dataset)
175
176 datasets = []
177 for filepath in filepaths:
178 if "reddit_" in filepath: #Special dataset class for Reddit files
179 data_obj = RedditDataset(filepath)
180 else:
181 data_obj = Dataset(filepath)
182 datasets.append(iter(data_obj))
183
184 # Store if dataset is in a 2 col or 3 col format
185 num_cols = {idx: len(next(dataset)) for idx, dataset in enumerate(datasets)}
186
187 while True:
188 texts_in_batch = set()
189 batch_format = None #2 vs 3 col format for this batch
190
191 #Add data from several sub datasets
192 for _ in range(args.datasets_per_batch):
193 valid_dataset = False #Check that datasets have the same 2/3 col format
194 while not valid_dataset:
195 data_idx = random.choice(dataset_indices)
196 if batch_format is None:
197 batch_format = num_cols[data_idx]
198 valid_dataset = True
199 else: #Check that this dataset has the same format
200 valid_dataset = (batch_format == num_cols[data_idx])
201
202 #Get data from this dataset
203 dataset = datasets[data_idx]
204 for _ in range(num_same_dataset):
205 for _ in range(args.nprocs):
206 batch_device = [] #A batch for one device
207 while len(batch_device) < args.batch_size:
208 sample = next(dataset)
209 in_batch = False
210 for text in sample:
211 if text in texts_in_batch:
212 in_batch = True
213 break
214
215 if not in_batch:
216 for text in sample:
217 texts_in_batch.add(text)
218 batch_device.append(sample)
219
220 queue.put(batch_device)
221
222
223class RedditDataset:

Callers

nothing calls this directly

Calls 3

RedditDatasetClass · 0.85
DatasetClass · 0.85
addMethod · 0.45

Tested by

no test coverage detected