class_docstr: This Interface should be implemented by particular classes derived from nemo.core.NeuralModule or nemo.core.ModelPT.
  It gives these entities ability to be exported for deployment to formats such as ONNX.
  
  Usage:
      # exporting pre-trained model to ONNX file for deployment.
      model.eval()
      model.to('cuda')  # or to('cpu') if you don't have GPU
  
      model.export('mymodel.onnx', [options])  # all arguments apart from `output` are optional.
class_docstr_tok: ["This","Interface","should","be","implemented","by","particular","classes","derived","from","nemo.core.NeuralModule","or","nemo.core.ModelPT",".","It","gives","these","entities","ability","to","be","exported","for","deployment","to","formats","such","as","ONNX",".","Usage",":","#","exporting","pre-trained","model","to","ONNX","file","for","deployment",".","model.eval","(",")","model.to","(","'cuda","'",")","#","or","to","(","'cpu","'",")","if","you","do","n't","have","GPU","model.export","(","'mymodel.onnx","'",",","[","options","]",")","#","all","arguments","apart","from","`","output","`","are","optional","."]
code: def _export(
      self,
      output: str,
      input_example=None,
      verbose=False,
      do_constant_folding=True,
      onnx_opset_version=None,
      check_trace: Union[bool, List[torch.Tensor]] = False,
      dynamic_axes=None,
      check_tolerance=0.01,
      export_modules_as_functions=False,
      keep_initializers_as_inputs=None,
  ):
      my_args = locals().copy()
      my_args.pop("self")
  
      self.eval()
      for param in self.parameters():
          param.requires_grad = False
  
      exportables = []
      for m in self.modules():
          if isinstance(m, Exportable):
              exportables.append(m)
  
      qual_name = self.__module__ + "." + self.__class__.__qualname__
      format = get_export_format(output)
      output_descr = f"{qual_name} exported to {format}"
  
      # Pytorch's default opset version is too low, using reasonable latest one
      if onnx_opset_version is None:
          onnx_opset_version = 16
  
      try:
          # Disable typechecks
          typecheck.set_typecheck_enabled(enabled=False)
  
          # Allow user to completely override forward method to export
          forward_method, old_forward_method = wrap_forward_method(self)
  
          # Set module mode
          with torch.inference_mode(), torch.no_grad(), torch.jit.optimized_execution(
              True
          ), _jit_is_scripting():
              if input_example is None:
                  input_example = self.input_module.input_example()
  
              # Remove i/o examples from args we propagate to enclosed Exportables
              my_args.pop("output")
              my_args.pop("input_example")
  
              # Run (posibly overridden) prepare methods before calling forward()
              for ex in exportables:
                  ex._prepare_for_export(**my_args, noreplace=True)
              self._prepare_for_export(
                  output=output, input_example=input_example, **my_args
              )
  
              input_list, input_dict = parse_input_example(
                  input_example
              )
              input_names = self.input_names
              output_names = self.output_names
              output_example = tuple(
                  self.forward(*input_list, **input_dict)
              )
  
              if check_trace:
                  if isinstance(check_trace, bool):
                      check_trace_input = [input_example]
                  else:
                      check_trace_input = check_trace
              jitted_model = self
              if format == ExportFormat.TORCHSCRIPT:
                  jitted_model = torch.jit.trace_module(
                      self,
                      {
                          "forward": tuple(input_list)
                          + tuple(input_dict.values())
                      },
                      strict=True,
                      check_trace=check_trace,
                      check_tolerance=check_tolerance,
                  )
                  jitted_model = torch.jit.freeze(jitted_model)
                  if verbose:
                      logging.info(f"JIT code:\n{jitted_model.code}")
                  jitted_model.save(output)
                  jitted_model = torch.jit.load(output)
  
                  if check_trace:
                      verify_torchscript(
                          jitted_model,
                          output,
                          check_trace_input,
                          check_tolerance,
                      )
              elif format == ExportFormat.ONNX:
                  # dynamic axis is a mapping from input/output_name => list of "dynamic" indices
                  if dynamic_axes is None:
                      dynamic_axes = get_dynamic_axes(
                          self.input_module.input_types_for_export,
                          input_names,
                      )
                      dynamic_axes.update(
                          get_dynamic_axes(
                              self.output_module.output_types_for_export,
                              output_names,
                          )
                      )
                  torch.onnx.export(
                      jitted_model,
                      input_example,
                      output,
                      input_names=input_names,
                      output_names=output_names,
                      verbose=verbose,
                      do_constant_folding=do_constant_folding,
                      dynamic_axes=dynamic_axes,
                      opset_version=onnx_opset_version,
                      keep_initializers_as_inputs=keep_initializers_as_inputs,
                      export_modules_as_functions=export_modules_as_functions,
                  )
  
                  if check_trace:
                      verify_runtime(
                          self,
                          output,
                          check_trace_input,
                          input_names,
                          check_tolerance=check_tolerance,
                      )
              else:
                  raise ValueError(
                      f"Encountered unknown export format {format}."
                  )
      finally:
          typecheck.set_typecheck_enabled(enabled=True)
          if forward_method:
              type(self).forward = old_forward_method
          self._export_teardown()
      return (output, output_descr, output_example)
  
imports: from abc import ABC
  from typing import Dict, List, Optional, Union
  import torch
  from pytorch_lightning.core.module import _jit_is_scripting
  from nemo.core.classes import typecheck
  from nemo.core.neural_types import NeuralType
  from nemo.core.utils.neural_type_utils import get_dynamic_axes, get_io_names
  from nemo.utils import logging
  from nemo.utils.export_utils import ExportFormat, augment_filename, get_export_format, parse_input_example, replace_for_export, verify_runtime, verify_torchscript, wrap_forward_method
label_desc: Use image node_id 4 for calling the Exportable obj's underlying member method code with example usage: obj._export(output, input_example, verbose, do_constant_folding, onnx_opset_version, check_trace, dynamic_axes, check_tolerance, export_modules_as_functions, keep_initializers_as_inputs) and returns: output,  output_descr,  output_example