class_docstr: Loads a saved AdaptiveModel/ONNXAdaptiveModel from disk and runs it in inference mode. Can be used for a
  model with prediction head (down-stream predictions) and without (using LM as embedder).
  
  Example usage:
  
  .. code-block:: python
  
     # down-stream inference
     basic_texts = [
         {"text": "Schartau sagte dem Tagesspiegel, dass Fischer ein Idiot sei"},
         {"text": "Martin Müller spielt Handball in Berlin"},
     ]
     model = Inferencer.load(your_model_dir)
     model.inference_from_dicts(dicts=basic_texts)
     # LM embeddings
     model = Inferencer.load(your_model_dir, extraction_strategy="cls_token", extraction_layer=-1)
     model.inference_from_dicts(dicts=basic_texts)
docstr: Implementation of inference. This method is a generator that yields the results.
  
  :param dicts: Samples to run inference on provided as a list of dicts or a generator object that yield dicts.
  :type dicts: iter(dict)
  :param return_json: Whether the output should be in a json appropriate format. If False, it returns the prediction
                      object where applicable, else it returns PredObj.to_json()
  :type return_json: bool
  :param aggregate_preds: whether to aggregate predictions across different samples (e.g. for QA on long texts)
  :type aggregate_preds: bool
  :param multiprocessing_chunksize: number of dicts to put together in one chunk and feed to one process
  :type multiprocessing_chunksize: int
  :return: generator object that yield predictions
  :rtype: iter
docstr_tok: ["Implementation","of","inference",".","This","method","is","a","generator","that","yields","the","results",".",":","param","dicts",":","Samples","to","run","inference","on","provided","as","a","list","of","dicts","or","a","generator","object","that","yield","dicts",".",":","type","dicts",":","iter","(","dict",")",":","param","return_json",":","Whether","the","output","should","be","in","a","json","appropriate","format",".","If","False",",","it","returns","the","prediction","object","where","applicable",",","else","it","returns","PredObj.to_json","(",")",":","type","return_json",":","bool",":","param","aggregate_preds",":","whether","to","aggregate","predictions","across","different","samples","(","e.g",".","for","QA","on","long","texts",")",":","type","aggregate_preds",":","bool",":","param","multiprocessing_chunksize",":","number","of","dicts","to","put","together","in","one","chunk","and","feed","to","one","process",":","type","multiprocessing_chunksize",":","int",":","return",":","generator","object","that","yield","predictions",":","rtype",":","iter"]
code: def _inference_with_multiprocessing(
      self,
      dicts,
      return_json,
      aggregate_preds,
      multiprocessing_chunksize,
  ):
      """
      Implementation of inference. This method is a generator that yields the results.
  
      :param dicts: Samples to run inference on provided as a list of dicts or a generator object that yield dicts.
      :type dicts: iter(dict)
      :param return_json: Whether the output should be in a json appropriate format. If False, it returns the prediction
                          object where applicable, else it returns PredObj.to_json()
      :type return_json: bool
      :param aggregate_preds: whether to aggregate predictions across different samples (e.g. for QA on long texts)
      :type aggregate_preds: bool
      :param multiprocessing_chunksize: number of dicts to put together in one chunk and feed to one process
      :type multiprocessing_chunksize: int
      :return: generator object that yield predictions
      :rtype: iter
      """
  
      # We group the input dicts into chunks and feed each chunk to a different process
      # in the pool, where it gets converted to a pytorch dataset
      results = self.process_pool.imap(
          partial(
              self._create_datasets_chunkwise, processor=self.processor
          ),
          grouper(iterable=dicts, n=multiprocessing_chunksize),
          1,
      )
  
      # Once a process spits out a preprocessed chunk. we feed this dataset directly to the model.
      # So we don't need to wait until all preprocessing has finished before getting first predictions.
      for (
          dataset,
          tensor_names,
          problematic_sample_ids,
          baskets,
      ) in results:
          self.problematic_sample_ids.update(problematic_sample_ids)
          if dataset is None:
              logger.error(
                  f"Part of the dataset could not be converted! \n"
                  f"BE AWARE: The order of predictions will not conform with the input order!"
              )
          else:
              # TODO change format of formatted_preds in QA (list of dicts)
              if aggregate_preds:
                  predictions = self._get_predictions_and_aggregate(
                      dataset, tensor_names, baskets
                  )
              else:
                  predictions = self._get_predictions(
                      dataset, tensor_names, baskets
                  )
  
              if return_json:
                  # TODO this try catch should be removed when all tasks return prediction objects
                  try:
                      predictions = [x.to_json() for x in predictions]
                  except AttributeError:
                      pass
              yield from predictions
  
imports: import logging
  import multiprocessing
  import os
  from functools import partial
  import warnings
  import torch
  from torch.utils.data.sampler import SequentialSampler
  from tqdm import tqdm
  from typing import Generator, List, Union
  from farm.data_handler.dataloader import NamedDataLoader
  from farm.data_handler.processor import Processor, InferenceProcessor, NaturalQuestionsProcessor
  from farm.data_handler.utils import grouper
  from farm.data_handler.inputs import QAInput
  from farm.modeling.adaptive_model import AdaptiveModel, BaseAdaptiveModel, ONNXAdaptiveModel
  from farm.modeling.optimization import optimize_model
  from farm.utils import initialize_device_settings, MLFlowLogger
  from farm.utils import set_all_seeds, calc_chunksize, log_ascii_workers, Benchmarker
  from farm.modeling.predictions import QAPred
label_desc: Use image node_id 9 for calling the Inferencer obj's underlying member method code with example usage: obj._inference_with_multiprocessing(dicts, return_json, aggregate_preds, multiprocessing_chunksize) without return types