class_docstr: Implementation of ONNX Runtime for Inference of ONNX Models.
  
  Existing PyTorch based FARM AdaptiveModel can be converted to ONNX format using AdaptiveModel.convert_to_onnx().
  The conversion is currently only implemented for Question Answering Models.
  
  For inference, this class is compatible with the FARM Inferencer.
class_docstr_tok: ["Implementation","of","ONNX","Runtime","for","Inference","of","ONNX","Models",".","Existing","PyTorch","based","FARM","AdaptiveModel","can","be","converted","to","ONNX","format","using","AdaptiveModel.convert_to_onnx","(",")",".","The","conversion","is","currently","only","implemented","for","Question","Answering","Models",".","For","inference",",","this","class","is","compatible","with","the","FARM","Inferencer","."]
code: def load(cls, load_dir, device, **kwargs):
      load_dir = Path(load_dir)
      import onnxruntime
  
      sess_options = onnxruntime.SessionOptions()
      # Set graph optimization level to ORT_ENABLE_EXTENDED to enable bert optimization.
      sess_options.graph_optimization_level = (
          onnxruntime.GraphOptimizationLevel.ORT_ENABLE_EXTENDED
      )
      # Use OpenMP optimizations. Only useful for CPU, has little impact for GPUs.
      sess_options.intra_op_num_threads = multiprocessing.cpu_count()
      onnx_session = onnxruntime.InferenceSession(
          str(load_dir / "model.onnx"), sess_options
      )
  
      # Prediction heads
      _, ph_config_files = cls._get_prediction_head_files(
          load_dir, strict=False
      )
      prediction_heads = []
      ph_output_type = []
      for config_file in ph_config_files:
          # ONNX Model doesn't need have a separate neural network for PredictionHead. It only uses the
          # instance methods of PredictionHead class, so, we load with the load_weights param as False.
          head = PredictionHead.load(config_file, load_weights=False)
          prediction_heads.append(head)
          ph_output_type.append(head.ph_output_type)
  
      with open(load_dir / "onnx_model_config.json") as f:
          model_config = json.load(f)
          language_model_class = model_config["language_model_class"]
          language = model_config["language"]
  
      return cls(
          onnx_session,
          language_model_class,
          language,
          prediction_heads,
          device,
      )
  
imports: import copy
  import json
  import logging
  import os
  from pathlib import Path
  import multiprocessing
  import numpy
  import torch
  from torch import nn
  from transformers import AutoConfig
  from transformers.convert_graph_to_onnx import convert, quantize
  from farm.data_handler.processor import Processor
  from farm.modeling.language_model import LanguageModel
  from farm.modeling.prediction_head import PredictionHead, pick_single_fn
  from farm.utils import MLFlowLogger, stack
  import farm.conversion.transformers
label_desc: Use image node_id 2 for calling the ONNXAdaptiveModel obj's underlying member method code with example usage: obj.load(cls, load_dir, device) and returns: cls