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,
          )
      onnx_model = onnx.load(export_onnx_path)
      onnx.checker.check_model(onnx_model)
      # split onnx model into init_net and predict_net
      (
          init_net,
          predict_net,
      ) = caffe2_backend.Caffe2Backend.onnx_graph_to_caffe2_net(
          onnx_model
      )
      return (init_net, predict_net)
  
file_path: pytext/pytext/utils/mobile_onnx.py
imports: import itertools
  import numpy
  import onnx
  import torch
  from caffe2.python import core, utils, workspace
  from caffe2.python.onnx import backend
  from pytext.utils.onnx import convert_caffe2_blob_name
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: init_net,  predict_net