class_docstr: Model exporter exports a PyTorch model to Caffe2 model using ONNX
  
  Attributes:
      input_names (List[Str]): names of the input variables to model forward
          function, in a flattened way.
          e.g: forward(tokens, dict) where tokens is List[Tensor] and dict is
          a tuple of value and length: (List[Tensor], List[Tensor]) the
          input names should looks like ['token', 'dict_value', 'dict_length']
      dummy_model_input (Tuple[torch.Tensor]): dummy values to define the
          shape of input tensors, should exactly match the shape of the model
          forward function
      vocab_map (Dict[str, List[str]]): dict of input feature names
          to corresponding index_to_string array, e.g:
          ::
  
              {
                  "text": ["<UNK>", "W1", "W2", "W3", "W4", "W5", "W6", "W7", "W8"],
                  "dict": ["<UNK>", "D1", "D2", "D3", "D4", "D5", "D6", "D7", "D8"]
              }
      output_names (List[Str]): names of output variables
docstr: export pytorch model to caffe2 by first using ONNX to convert logic in forward
  function to a caffe2 net, and then prepend/append additional operators to
  the caffe2 net according to the model
  
  Args:
      model (Model): pytorch model to export
      export_path (str): path to save the exported caffe2 model
      export_onnx_path (str): path to save the exported onnx model
  
  Returns:
      final_output_names: list of caffe2 model output names
docstr_tok: ["export","pytorch","model","to","caffe2","by","first","using","ONNX","to","convert","logic","in","forward","function","to","a","caffe2","net",",","and","then","prepend\/append","additional","operators","to","the","caffe2","net","according","to","the","model","Args",":","model","(","Model",")",":","pytorch","model","to","export","export_path","(","str",")",":","path","to","save","the","exported","caffe2","model","export_onnx_path","(","str",")",":","path","to","save","the","exported","onnx","model","Returns",":","final_output_names",":","list","of","caffe2","model","output","names"]
code: def export_to_caffe2(
      self, model, export_path: str, export_onnx_path: str = None
  ) -> List[str]:
      """
      export pytorch model to caffe2 by first using ONNX to convert logic in forward
      function to a caffe2 net, and then prepend/append additional operators to
      the caffe2 net according to the model
  
      Args:
          model (Model): pytorch model to export
          export_path (str): path to save the exported caffe2 model
          export_onnx_path (str): path to save the exported onnx model
  
      Returns:
          final_output_names: list of caffe2 model output names
      """
  
      print(f"Saving caffe2 model to: {export_path}")
  
      # caffe2/onnx doesn't support internal uri(i.e. manifold)
      # workaround: save to a temp file and copy to model_path
      # this will be deprecated soon after caffe2 fully deprecated
      _, temp_path = tempfile.mkstemp(prefix="pytext")
  
      c2_prepared = onnx.pytorch_to_caffe2(
          model,
          self.dummy_model_input,
          self.input_names,
          self.output_names,
          temp_path,
          export_onnx_path,
      )
      c2_prepared, final_input_names = self.prepend_operators(
          c2_prepared, self.input_names
      )
  
      # Required because of https://github.com/pytorch/pytorch/pull/6456/files
      with c2_prepared.workspace._ctx:
          predict_net = core.Net(c2_prepared.predict_net)
          init_net = core.Net(c2_prepared.init_net)
  
          net_outputs, final_out_names = self.postprocess_output(
              init_net,
              predict_net,
              c2_prepared.workspace,
              self.output_names,
              model,
          )
          for output in net_outputs:
              predict_net.AddExternalOutput(output)
          c2_prepared.predict_net = predict_net.Proto()
          c2_prepared.init_net = init_net.Proto()
  
      # Save predictor net to file
      onnx.export_nets_to_predictor_file(
          c2_prepared,
          final_input_names,
          final_out_names,
          temp_path,
          self.get_extra_params(),
      )
      PathManager.copy_from_local(
          temp_path, export_path, overwrite=True
      )
      return final_out_names
  
imports: import tempfile
  from typing import Callable, Dict, List, Tuple, Union
  import torch
  from caffe2.python import core
  from caffe2.python.onnx.backend_rep import Caffe2Rep
  from pytext.config import ConfigBase
  from pytext.config.component import Component, ComponentType
  from pytext.config.field_config import FeatureConfig
  from pytext.data import CommonMetadata
  from pytext.fields import FieldMeta
  from pytext.utils import onnx
  from pytext.utils.file_io import PathManager
  from pytext.utils.usage import log_class_usage
label_desc: Use image node_id 7 for calling the ModelExporter obj's underlying member method code with example usage: obj.export_to_caffe2(model, export_path, export_onnx_path) and returns: final_out_names