code: def batch_iterator(
      items: Iterable[T], max_batch_size: int
  ) -> Iterator[list[T]]:
      """Create batches from an input stream.
  
      Use this to create batches, e.g. to feed to a model.
      The output can be easily flattened again using itertools.chain.from_iterable.
  
      Args:
        items: stream of items
        max_batch_size: maximum size of resulting batches
  
      Yields:
        batches of size <= max_batch_size
      """
      minibatch = []
      for item in items:
          if len(minibatch) < max_batch_size:
              minibatch.append(item)
          if len(minibatch) >= max_batch_size:
              yield minibatch
              minibatch = []
      if len(minibatch) > 0:  # pylint: disable=g-explicit-length-test
          yield minibatch
  
imports: from collections.abc import Callable, Collection, Iterable, Iterator, Mapping, Sequence
  import itertools
  import queue
  import threading
  import time
  from typing import Any, Optional, TypeVar, Union
  import uuid
  from lit_nlp.api import types
  import numpy
label_desc: Use image node_id 10 for calling a global function with example usage: batch_iterator(items, max_batch_size) without return types