MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / _process_iterable

Function _process_iterable

python/ctranslate2/extensions.py:527–554  ·  view source on GitHub ↗
(process_func, iterables, max_batch_size, batch_type, **kwargs)

Source from the content-addressed store, hash-verified

525
526
527def _process_iterable(process_func, iterables, max_batch_size, batch_type, **kwargs):
528 if max_batch_size < 1:
529 raise ValueError("max_batch_size must be >= 1")
530
531 if len(iterables) == 1:
532 iterable = iterables[0]
533 else:
534 iterable = itertools.zip_longest(*iterables)
535
536 kwargs.update(
537 {
538 "max_batch_size": max_batch_size,
539 "batch_type": batch_type,
540 "asynchronous": True,
541 }
542 )
543
544 read_batch_size = max_batch_size * 16 if max_batch_size > 1 else max_batch_size
545 queue = collections.deque()
546
547 for streams in _batch_iterator(iterable, read_batch_size, batch_type):
548 queue.extend(process_func(*streams, **kwargs))
549
550 while queue and queue[0].done():
551 yield queue.popleft().result()
552
553 while queue:
554 yield queue.popleft().result()
555
556
557def _batch_iterator(iterable, batch_size, batch_type):

Callers 4

generator_score_iterableFunction · 0.85

Calls 2

_batch_iteratorFunction · 0.85
doneMethod · 0.80

Tested by

no test coverage detected