MCPcopy Create free account
hub / github.com/OpenMOSS/rope_pp / StreamingTrainingParquet

Class StreamingTrainingParquet

utils/dataset_utils.py:104–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102
103
104class StreamingTrainingParquet(torch.utils.data.Dataset):
105
106 def __init__(self, data_root, tokenizer, label_name, train_length=4096, min_length=512, num_data=-1, seed=42, dataset_ckpt_path=None, file_depth=1):
107
108 self.data_root = data_root
109
110 self.data_path = sorted([f'{data_root}/{path}' for path in os.listdir(data_root) if not (os.path.isdir(f'{data_root}/{path}') and 'git' in path)])
111
112 for _ in range(file_depth):
113 self.data_path = sorted(sum([[f'{data_root}/{path}' for path in os.listdir(data_root)] for data_root in self.data_path], []))
114
115 random.shuffle(self.data_path)
116
117 self.tokenizer = tokenizer
118 self.label_name = label_name
119
120 self.len = num_data
121 self.train_length = train_length
122 self.min_length = min_length
123
124 self.pivot = torch.distributed.get_rank()
125 self.size = torch.distributed.get_world_size()
126
127 self.token_buffer, self.file_buffer = [], None
128
129 self.file_buffer = pq.ParquetFile(self.data_path[self.pivot])
130 self.table_idx, self.table_num = 0, self.file_buffer.num_row_groups
131 self.table_buffer = self.file_buffer.read_row_group(self.table_idx)
132 self.sample_idx, self.sample_num = 0, len(self.table_buffer[self.label_name])
133
134 if dataset_ckpt_path is not None:
135 dataset_ckpt_path = f"{dataset_ckpt_path}/dataset_ckpt-{self.pivot:{len(str(self.size))}d}-{self.size}.pt"
136 dataset_ckpt = torch.load(dataset_ckpt_path, weights_only=False)
137 self.data_path = dataset_ckpt['data_path']
138 self.label_name = dataset_ckpt['label_name']
139 self.pivot = dataset_ckpt['pivot']
140 self.size = dataset_ckpt['size']
141 self.file_buffer = pq.ParquetFile(self.data_path[self.pivot])
142 self.table_idx = dataset_ckpt['table_idx']
143 self.table_num = dataset_ckpt['table_num']
144 self.table_buffer = dataset_ckpt['table_buffer']
145 self.sample_idx = dataset_ckpt['sample_idx']
146 self.sample_num = dataset_ckpt['sample_num']
147 self.token_buffer = dataset_ckpt['token_buffer']
148
149 def __len__(self):
150 return self.len
151
152 def __getitem__(self, _):
153
154 if len(self.token_buffer) > self.train_length:
155 input_ids = torch.tensor(self.token_buffer[:self.train_length]).long()
156 position_ids = torch.tensor(list(range(self.train_length))).long()
157 self.token_buffer = self.token_buffer[self.train_length:]
158
159 else:
160 input_ids = self.token_buffer
161 position_ids = list(range(self.train_length))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected