MCPcopy Create free account
hub / github.com/apple/ml-pointersect / BatchPreparer

Class BatchPreparer

cdslib/core/data/dataloader/batch_preparer.py:26–287  ·  view source on GitHub ↗

The batch preparer works as follows: - First adds datasets before iterator starts. - When creating the iterator (beginning of a epoch): 1. It determines the samples to used in the iteration based on dataset_ratios. 2. It groups samples of similar length into batch (usin

Source from the content-addressed store, hash-verified

24
25
26class BatchPreparer:
27 """
28 The batch preparer works as follows:
29
30 - First adds datasets before iterator starts.
31 - When creating the iterator (beginning of a epoch):
32 1. It determines the samples to used in the iteration based on dataset_ratios.
33 2. It groups samples of similar length into batch (using bucket_sampler or sort_sampler).
34 - Every iteration:
35 The samples are loaded in parallel using pytorch's dataloader.
36
37 Data flow:
38
39 - Each dataset is stored in a pytorch's Dataset (with an additional method 'get_seq_lens' implemented).
40
41 ex: seq_lens = dataset.get_seq_lens()
42
43 - seq_lens is a list of all samples stored in the dataset.
44 - seq_lens[i] = length of dataset[i]
45
46 - The datasets are concatenated to a single dataset by torch.utils.data.ConcatDataset for pytorch's dataloader.
47 """
48
49 def __init__(
50 self,
51 batch_size,
52 collate_fn,
53 drop_last=False,
54 num_workers=0,
55 batch_wrt_length=True,
56 shuffle=True,
57 max_total_samples_per_epoch=-1,
58 max_batch_combined_size=-1,
59 batch_sampler_type="sort",
60 ):
61 """
62 Args:
63 batch_size:
64 typical batch_size
65 collate_fn:
66 collate function used to combine samples from dataset
67 drop_last:
68 whether to drop the rest of the data that cannot form a batch
69 num_workers:
70 number of loading threads to use
71 batch_wrt_length:
72 whether to batch samples of similar sequence lengths
73 shuffle:
74 whether to shuffle data within each bucket
75 max_total_samples_per_epoch:
76 maximum total number of samples per epoch. -1: ignored
77 max_batch_combined_size:
78 limitation on batch_size * seq_len. -1: ignored
79 batch_sampler_type:
80 type of the batch sampler [bucket | sort]
81 """
82
83 self.batch_size = batch_size

Callers 1

_testMethod · 0.90

Calls

no outgoing calls

Tested by 1

_testMethod · 0.72