class_docstr: PyTorch implementation containing all the modelling needed for your NLP task. Combines a language
  model and a prediction head. Allows for gradient flow back to the language model component.
class_docstr_tok: ["PyTorch","implementation","containing","all","the","modelling","needed","for","your","NLP","task",".","Combines","a","language","model","and","a","prediction","head",".","Allows","for","gradient","flow","back","to","the","language","model","component","."]
docstr: Convert a PyTorch model from transformers hub to an ONNX Model.
  
  :param model_name: transformers model name
  :type model_name: str
  :param output_path: output Path to write the converted to
  :type output_path: Path
  :param task_type: Type of task for the model. Available options: "embeddings", "question_answering",
                    "text_classification", "ner".
  :param convert_to_float16: By default, the model use float32 precision. With half precision of flaot16, inference
                          should be faster on Nvidia GPUs with Tensor core like T4 or V100. On older GPUs, float32
                          might be more performant.
  :type convert_to_float16: bool
  :param quantize: convert floating point number to integers
  :type quantize: bool
  :param opset_version: ONNX opset version
  :type opset_version: int
  :return:
code: def convert_to_onnx(
      cls,
      model_name,
      output_path,
      task_type,
      convert_to_float16=False,
      quantize=False,
      opset_version=11,
  ):
      """
      Convert a PyTorch model from transformers hub to an ONNX Model.
  
      :param model_name: transformers model name
      :type model_name: str
      :param output_path: output Path to write the converted to
      :type output_path: Path
      :param task_type: Type of task for the model. Available options: "embeddings", "question_answering",
                        "text_classification", "ner".
      :param convert_to_float16: By default, the model use float32 precision. With half precision of flaot16, inference
                              should be faster on Nvidia GPUs with Tensor core like T4 or V100. On older GPUs, float32
                              might be more performant.
      :type convert_to_float16: bool
      :param quantize: convert floating point number to integers
      :type quantize: bool
      :param opset_version: ONNX opset version
      :type opset_version: int
      :return:
      """
      language_model_class = LanguageModel.get_language_model_class(
          model_name
      )
      if language_model_class not in ["Bert", "Roberta", "XLMRoberta"]:
          raise Exception(
              "The current ONNX conversion only support 'BERT', 'RoBERTa', and 'XLMRoberta' models."
          )
  
      task_type_to_pipeline_map = {
          "question_answering": "question-answering",
          "embeddings": "feature-extraction",
          "ner": "ner",
      }
  
      convert(
          pipeline_name=task_type_to_pipeline_map[task_type],
          framework="pt",
          model=model_name,
          output=output_path / "model.onnx",
          opset=opset_version,
          use_external_format=True
          if language_model_class == "XLMRoberta"
          else False,
      )
  
      # save processor & model config files that are needed when loading the model with the FARM Inferencer
      processor = Processor.convert_from_transformers(
          tokenizer_name_or_path=model_name,
          task_type=task_type,
          max_seq_len=256,
          doc_stride=128,
          use_fast=True,
      )
      processor.save(output_path)
      model = AdaptiveModel.convert_from_transformers(
          model_name, device="cpu", task_type=task_type
      )
      model.save(output_path)
      os.remove(
          output_path / "language_model.bin"
      )  # remove the actual PyTorch model(only configs are required)
  
      onnx_model_config = {
          "task_type": task_type,
          "onnx_opset_version": opset_version,
          "language_model_class": language_model_class,
          "language": model.language_model.language,
      }
      with open(output_path / "onnx_model_config.json", "w") as f:
          json.dump(onnx_model_config, f)
  
      if convert_to_float16:
          from onnxruntime_tools import optimizer
  
          config = AutoConfig.from_pretrained(model_name)
          optimized_model = optimizer.optimize_model(
              input=str(output_path / "model.onnx"),
              model_type="bert",
              num_heads=config.num_hidden_layers,
              hidden_size=config.hidden_size,
          )
          optimized_model.convert_model_float32_to_float16()
          optimized_model.save_model_to_file(
              str(output_path / "model.onnx")
          )
  
      if quantize:
          quantize_model(output_path / "model.onnx")
  
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 16 for calling the AdaptiveModel obj's underlying member method code with example usage: obj.convert_to_onnx(cls, model_name, output_path, task_type, convert_to_float16, quantize, opset_version) without return types