code: def pytorch_to_caffe2(
      model,
      export_input,
      external_input_names,
      output_names,
      export_path,
      export_onnx_path=None,
  ):
      num_tensors = 0
      for inp in export_input:
          num_tensors += (
              len(inp) if isinstance(inp, (tuple, list)) else 1
          )
      assert len(external_input_names) == num_tensors
      all_input_names = external_input_names[:]
      for name, _ in model.named_parameters():
          all_input_names.append(name)
      # export the pytorch model to ONNX
      if export_onnx_path:
          print(f"Saving onnx model to: {export_onnx_path}")
      else:
          export_onnx_path = export_path
      model.eval()
      with torch.no_grad():
          torch.onnx._export(
              model,
              export_input,
              export_onnx_path,
              input_names=all_input_names,
              output_names=output_names,
              export_params=True,
              operator_export_type=OperatorExportTypes.ONNX_ATEN_FALLBACK,
              opset_version=9,
              export_type=ExportTypes.ZIP_ARCHIVE,
          )
      # Convert the ONNX model to a caffe2 net
      c2_prepared = caffe2_backend.prepare_zip_archive(export_onnx_path)
      return c2_prepared
  
file_path: pytext/pytext/utils/onnx.py
imports: import caffe2.python.predictor.predictor_exporter
  import numpy
  import torch
  from caffe2.python import core, workspace
  from caffe2.python.onnx import backend
  from torch.onnx import ExportTypes, OperatorExportTypes
label_desc: Use image node_id 2 for calling a global function with example usage: pytorch_to_caffe2(model, export_input, external_input_names, output_names, export_path, export_onnx_path) and returns: c2_prepared