(self)
| 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 |
no test coverage detected