MCPcopy Create free account
hub / github.com/LargeWorldModel/LWM / parallel_example_iterator

Method parallel_example_iterator

lwm/data.py:408–432  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

406 yield batch
407
408 def parallel_example_iterator(self):
409 if self.config.tokenizer_processes == 1:
410 for example, loc, index in self.json_iterator():
411 self._file_loc = loc
412 self._index = index
413 yield self.text_processor((example, loc, index), has_aux=True)
414 else:
415 process_pool = Pool(self.config.tokenizer_processes)
416 batched_iterator = self.batched(
417 self.json_iterator(), self.config.tokenizer_parallel_batch_size
418 )
419 with process_pool as pool:
420 map_fn = partial(self.text_processor, has_aux=True)
421 next_batch = pool.map_async(
422 map_fn, next(batched_iterator),
423 chunksize=self.config.tokenizer_parallel_chunk_size
424 )
425 while True:
426 current_batch = next_batch
427 next_batch = pool.map_async(
428 map_fn, next(batched_iterator),
429 chunksize=self.config.tokenizer_parallel_chunk_size
430 )
431 for example in current_batch.get():
432 yield example
433
434 def __iter__(self):
435 global_chunk_size = self.config.batch_size * self.config.seq_length

Callers 1

__iter__Method · 0.95

Calls 3

json_iteratorMethod · 0.95
text_processorMethod · 0.95
batchedMethod · 0.95

Tested by

no test coverage detected