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: Initializes Inferencer from an AdaptiveModel and a Processor instance.
  
  :param model: AdaptiveModel to run in inference mode
  :type model: AdaptiveModel
  :param processor: A dataset specific Processor object which will turn input (file or dict) into a Pytorch Dataset.
  :type processor: Processor
  :param task_type: Type of task the model should be used for. Currently supporting:
                    "embeddings", "question_answering", "text_classification", "ner". More coming soon...
  :param task_type: str
  :param batch_size: Number of samples computed once per batch
  :type batch_size: int
  :param gpu: If GPU shall be used
  :type gpu: bool
  :param name: Name for the current Inferencer model, displayed in the REST API
  :type name: string
  :param return_class_probs: either return probability distribution over all labels or the prob of the associated label
  :type return_class_probs: bool
  :param extraction_strategy: Strategy to extract vectors. Choices: 'cls_token' (sentence vector), 'reduce_mean'
                         (sentence vector), reduce_max (sentence vector), 'per_token' (individual token vectors),
                         's3e' (sentence vector via S3E pooling, see https://arxiv.org/abs/2002.09620)
  :type extraction_strategy: str
  :param extraction_layer: number of layer from which the embeddings shall be extracted. Default: -1 (very last layer).
  :type extraction_layer: int
  :param s3e_stats: Stats of a fitted S3E model as returned by `fit_s3e_on_corpus()`
                    (only needed for task_type="embeddings" and extraction_strategy = "s3e")
  :type s3e_stats: dict
  :param num_processes: the number of processes for `multiprocessing.Pool`.
                        Set to value of 1 (or 0) to disable multiprocessing.
                        Set to None to let Inferencer use all CPU cores minus one.
                        If you want to debug the Language Model, you might need to disable multiprocessing!
                        **Warning!** If you use multiprocessing you have to close the
                        `multiprocessing.Pool` again! To do so call
                        :func:`~farm.infer.Inferencer.close_multiprocessing_pool` after you are
                        done using this class. The garbage collector will not do this for you!
  :type num_processes: int
  :param disable_tqdm: Whether to disable tqdm logging (can get very verbose in multiprocessing)
  :type disable_tqdm: bool
  :param dummy_ph: If True, methods of the prediction head will be replaced
               with a dummy method. This is used to isolate lm run time from ph run time.
  :type dummy_ph: bool
  :param benchmarking: If True, a benchmarking object will be initialised within the class and
                       certain parts of the code will be timed for benchmarking. Should be kept
                       False if not benchmarking since these timing checkpoints require synchronization
                       of the asynchronous Pytorch operations and may slow down the model.
  :type benchmarking: bool
  :return: An instance of the Inferencer.
docstr_tok: ["Initializes","Inferencer","from","an","AdaptiveModel","and","a","Processor","instance",".",":","param","model",":","AdaptiveModel","to","run","in","inference","mode",":","type","model",":","AdaptiveModel",":","param","processor",":","A","dataset","specific","Processor","object","which","will","turn","input","(","file","or","dict",")","into","a","Pytorch","Dataset",".",":","type","processor",":","Processor",":","param","task_type",":","Type","of","task","the","model","should","be","used","for",".","Currently","supporting",":","``","embeddings","''",",","``","question_answering","''",",","``","text_classification","''",",","``","ner","''",".","More","coming","soon","...",":","param","task_type",":","str",":","param","batch_size",":","Number","of","samples","computed","once","per","batch",":","type","batch_size",":","int",":","param","gpu",":","If","GPU","shall","be","used",":","type","gpu",":","bool",":","param","name",":","Name","for","the","current","Inferencer","model",",","displayed","in","the","REST","API",":","type","name",":","string",":","param","return_class_probs",":","either","return","probability","distribution","over","all","labels","or","the","prob","of","the","associated","label",":","type","return_class_probs",":","bool",":","param","extraction_strategy",":","Strategy","to","extract","vectors",".","Choices",":","'cls_token","'","(","sentence","vector",")",",","'reduce_mean'","(","sentence","vector",")",",","reduce_max","(","sentence","vector",")",",","'per_token","'","(","individual","token","vectors",")",",","'s3e","'","(","sentence","vector","via","S3E","pooling",",","see","https",":","\/\/arxiv.org\/abs\/2002.09620",")",":","type","extraction_strategy",":","str",":","param","extraction_layer",":","number","of","layer","from","which","the","embeddings","shall","be","extracted",".","Default",":","-1","(","very","last","layer",")",".",":","type","extraction_layer",":","int",":","param","s3e_stats",":","Stats","of","a","fitted","S3E","model","as","returned","by","`","fit_s3e_on_corpus","(",")","`","(","only","needed","for","task_type=","''","embeddings","''","and","extraction_strategy","=","``","s3e","''",")",":","type","s3e_stats",":","dict",":","param","num_processes",":","the","number","of","processes","for","`","multiprocessing.Pool","`",".","Set","to","value","of","1","(","or","0",")","to","disable","multiprocessing",".","Set","to","None","to","let","Inferencer","use","all","CPU","cores","minus","one",".","If","you","want","to","debug","the","Language","Model",",","you","might","need","to","disable","multiprocessing","!","*","*","Warning","!","*","*","If","you","use","multiprocessing","you","have","to","close","the","`","multiprocessing.Pool","`","again","!","To","do","so","call",":","func",":","`","~farm.infer.Inferencer.close_multiprocessing_pool","`","after","you","are","done","using","this","class",".","The","garbage","collector","will","not","do","this","for","you","!",":","type","num_processes",":","int",":","param","disable_tqdm",":","Whether","to","disable","tqdm","logging","(","can","get","very","verbose","in","multiprocessing",")",":","type","disable_tqdm",":","bool",":","param","dummy_ph",":","If","True",",","methods","of","the","prediction","head","will","be","replaced","with","a","dummy","method",".","This","is","used","to","isolate","lm","run","time","from","ph","run","time",".",":","type","dummy_ph",":","bool",":","param","benchmarking",":","If","True",",","a","benchmarking","object","will","be","initialised","within","the","class","and","certain","parts","of","the","code","will","be","timed","for","benchmarking",".","Should","be","kept","False","if","not","benchmarking","since","these","timing","checkpoints","require","synchronization","of","the","asynchronous","Pytorch","operations","and","may","slow","down","the","model",".",":","type","benchmarking",":","bool",":","return",":","An","instance","of","the","Inferencer","."]
code: def __init__(
      self,
      model,
      processor,
      task_type,
      batch_size=4,
      gpu=False,
      name=None,
      return_class_probs=False,
      extraction_strategy=None,
      extraction_layer=None,
      s3e_stats=None,
      num_processes=None,
      disable_tqdm=False,
      benchmarking=False,
      dummy_ph=False,
  ):
      """
      Initializes Inferencer from an AdaptiveModel and a Processor instance.
  
      :param model: AdaptiveModel to run in inference mode
      :type model: AdaptiveModel
      :param processor: A dataset specific Processor object which will turn input (file or dict) into a Pytorch Dataset.
      :type processor: Processor
      :param task_type: Type of task the model should be used for. Currently supporting:
                        "embeddings", "question_answering", "text_classification", "ner". More coming soon...
      :param task_type: str
      :param batch_size: Number of samples computed once per batch
      :type batch_size: int
      :param gpu: If GPU shall be used
      :type gpu: bool
      :param name: Name for the current Inferencer model, displayed in the REST API
      :type name: string
      :param return_class_probs: either return probability distribution over all labels or the prob of the associated label
      :type return_class_probs: bool
      :param extraction_strategy: Strategy to extract vectors. Choices: 'cls_token' (sentence vector), 'reduce_mean'
                             (sentence vector), reduce_max (sentence vector), 'per_token' (individual token vectors),
                             's3e' (sentence vector via S3E pooling, see https://arxiv.org/abs/2002.09620)
      :type extraction_strategy: str
      :param extraction_layer: number of layer from which the embeddings shall be extracted. Default: -1 (very last layer).
      :type extraction_layer: int
      :param s3e_stats: Stats of a fitted S3E model as returned by `fit_s3e_on_corpus()`
                        (only needed for task_type="embeddings" and extraction_strategy = "s3e")
      :type s3e_stats: dict
      :param num_processes: the number of processes for `multiprocessing.Pool`.
                            Set to value of 1 (or 0) to disable multiprocessing.
                            Set to None to let Inferencer use all CPU cores minus one.
                            If you want to debug the Language Model, you might need to disable multiprocessing!
                            **Warning!** If you use multiprocessing you have to close the
                            `multiprocessing.Pool` again! To do so call
                            :func:`~farm.infer.Inferencer.close_multiprocessing_pool` after you are
                            done using this class. The garbage collector will not do this for you!
      :type num_processes: int
      :param disable_tqdm: Whether to disable tqdm logging (can get very verbose in multiprocessing)
      :type disable_tqdm: bool
      :param dummy_ph: If True, methods of the prediction head will be replaced
                   with a dummy method. This is used to isolate lm run time from ph run time.
      :type dummy_ph: bool
      :param benchmarking: If True, a benchmarking object will be initialised within the class and
                           certain parts of the code will be timed for benchmarking. Should be kept
                           False if not benchmarking since these timing checkpoints require synchronization
                           of the asynchronous Pytorch operations and may slow down the model.
      :type benchmarking: bool
      :return: An instance of the Inferencer.
  
      """
      MLFlowLogger.disable()
  
      # For benchmarking
      if dummy_ph:
          model.bypass_ph()
  
      self.benchmarking = benchmarking
      if self.benchmarking:
          self.benchmarker = Benchmarker()
  
      # Init device and distributed settings
      device, n_gpu = initialize_device_settings(
          use_cuda=gpu, local_rank=-1, use_amp=None
      )
  
      self.processor = processor
      self.model = model
      self.model.eval()
      self.batch_size = batch_size
      self.device = device
      self.language = self.model.get_language()
      self.task_type = task_type
      self.disable_tqdm = disable_tqdm
      self.problematic_sample_ids = set()
  
      if task_type == "embeddings":
          if not extraction_layer or not extraction_strategy:
              logger.warning(
                  "Using task_type='embeddings', but couldn't find one of the args `extraction_layer` and `extraction_strategy`. "
                  "Since FARM 0.4.2, you set both when initializing the Inferencer and then call inferencer.inference_from_dicts() instead of inferencer.extract_vectors()"
              )
          self.model.prediction_heads = torch.nn.ModuleList([])
          self.model.language_model.extraction_layer = extraction_layer
          self.model.language_model.extraction_strategy = (
              extraction_strategy
          )
          self.model.language_model.s3e_stats = s3e_stats
  
      # TODO add support for multiple prediction heads
  
      self.name = (
          name if name != None else f"anonymous-{self.task_type}"
      )
      self.return_class_probs = return_class_probs
  
      model.connect_heads_with_processor(
          processor.tasks, require_labels=False
      )
      set_all_seeds(42)
  
      self._set_multiprocessing_pool(num_processes)
  
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 1 to create a new Inferencer object  with example: obj = Inferencer(model, processor, task_type, batch_size, gpu, name, return_class_probs, extraction_strategy, extraction_layer, s3e_stats, num_processes, disable_tqdm, benchmarking, dummy_ph)