class_docstr: Stateless class to process FX graph Nodes and translate them into their ONNX counterparts.
  
  All FX nodes described by [FX Graph](https://pytorch.org/docs/stable/fx.html#torch.fx.Graph) are supported.
  Similarly to [FX Interpreter pattern](https://pytorch.org/docs/stable/fx.html#torch.fx.Interpreter), each FX node
  must be implemented on its own method in this class.
  
  Each operator's implementation returns either an `onnxscript.OnnxFunction` or
  `onnxscript.TracedOnnxFunction` instance based on the dispatch algorithm. They can
  also raise RuntimeError: If there are no overloaded functions available for the given FX node.
  
  TODO: Convert methods to @staticmethod when the diagnostic system supports it
        DO NOT ADD NEW ATTRIBUTES TO THIS CLASS!
class_docstr_tok: ["Stateless","class","to","process","FX","graph","Nodes","and","translate","them","into","their","ONNX","counterparts",".","All","FX","nodes","described","by","[","FX","Graph","]","(","https",":","\/\/pytorch.org\/docs\/stable\/fx.html","#","torch.fx.Graph",")","are","supported",".","Similarly","to","[","FX","Interpreter","pattern","]","(","https",":","\/\/pytorch.org\/docs\/stable\/fx.html","#","torch.fx.Interpreter",")",",","each","FX","node","must","be","implemented","on","its","own","method","in","this","class",".","Each","operator","'s","implementation","returns","either","an","`","onnxscript.OnnxFunction","`","or","`","onnxscript.TracedOnnxFunction","`","instance","based","on","the","dispatch","algorithm",".","They","can","also","raise","RuntimeError",":","If","there","are","no","overloaded","functions","available","for","the","given","FX","node",".","TODO",":","Convert","methods","to","@","staticmethod","when","the","diagnostic","system","supports","it","DO","NOT","ADD","NEW","ATTRIBUTES","TO","THIS","CLASS","!"]
docstr: Analyze all FX nodes and trigger their ONNX translation.
  
  Args:
      fx_graph_module: FX graph module to be translated.
      onnxfunction_dispatcher: ONNX function dispatcher.
      op_level_debug: Whether to enable op-level debug.
      parent_onnxscript_graph: The parent TorchScript graph. Must be provided if
          `fx_graph_module` is a submodule. If not provided,
          `fx_graph_module` is assumed to be the root module.
docstr_tok: ["Analyze","all","FX","nodes","and","trigger","their","ONNX","translation",".","Args",":","fx_graph_module",":","FX","graph","module","to","be","translated",".","onnxfunction_dispatcher",":","ONNX","function","dispatcher",".","op_level_debug",":","Whether","to","enable","op-level","debug",".","parent_onnxscript_graph",":","The","parent","TorchScript","graph",".","Must","be","provided","if","`","fx_graph_module","`","is","a","submodule",".","If","not","provided",",","`","fx_graph_module","`","is","assumed","to","be","the","root","module","."]
code: def run(
      self,
      fx_graph_module: torch.fx.GraphModule,
      onnxfunction_dispatcher: onnxfunction_dispatcher.OnnxFunctionDispatcher,
      op_level_debug: bool,
      parent_onnxscript_graph: Optional[
          onnxscript_graph_building.TorchScriptGraph
      ] = None,
  ) -> onnxscript_graph_building.TorchScriptGraph:
      """Analyze all FX nodes and trigger their ONNX translation.
  
      Args:
          fx_graph_module: FX graph module to be translated.
          onnxfunction_dispatcher: ONNX function dispatcher.
          op_level_debug: Whether to enable op-level debug.
          parent_onnxscript_graph: The parent TorchScript graph. Must be provided if
              `fx_graph_module` is a submodule. If not provided,
              `fx_graph_module` is assumed to be the root module.
      """
      diagnostic = self.diagnostic_context.inflight_diagnostic()
      with diagnostic.log_section(logging.DEBUG, "FX Graph:"):
          diagnostic.debug(
              "```\n%s\n```",
              diagnostics.LazyString(
                  fx_graph_module.print_readable, False
              ),
          )
  
      if parent_onnxscript_graph is not None:
          # If parent_onnxscript_graph is provided, we assume fx_graph_module is a
          # submodule representing a forward call of an nn.Module.
          # Compose package and version where the nn.Module is defined as domain name
          # for the local function.
  
          onnx_meta: Optional[
              _pass.GraphModuleOnnxMeta
          ] = fx_graph_module.meta.get("onnx")
          if onnx_meta is None:
              raise RuntimeError(
                  f"ONNX meta is not found in submodule {fx_graph_module._get_name()}. "
                  f"Only submodules produced by `Modularize` pass is supported in ONNX export."
              )
  
          onnx_domain = onnx_meta.package_info.to_onnx_domain_string()
      else:
          # Leave as default domain name for the root module.
          onnx_domain = None
  
      onnxscript_graph = onnxscript_graph_building.TorchScriptGraph(
          parent_onnxscript_graph, domain_name=onnx_domain
      )
      onnxscript_tracer = (
          onnxscript_graph_building.TorchScriptTracingEvaluator(
              onnxscript_graph
          )
      )
      # In the following loop, a TorchScript graph is created to
      # represent the input FX graph with ONNX symbols (e.g., onnx::add).
      # To connect the values to nodes in the TorchScript graph, we maintain
      # fx_name_to_onnxscript_value. Basically, we want to translate
      #   fx_tensor_x (type: torch.fx.Node) -> fx_node_1 -> fx_tensor_y (type: torch.fx.Node)
      # to
      #   fx_name_to_onnxscript_value[fx_tensor_x.name] -> onnx_node_1 -> fx_name_to_onnxscript_value[fx_tensor_y.name]
      fx_name_to_onnxscript_value: Dict[
          str,
          Union[
              onnxscript_graph_building.TorchScriptTensor,
              Tuple[onnxscript_graph_building.TorchScriptTensor, ...],
          ],
      ] = {}
  
      # TODO: Fix FakeTensorMode limitation asap
      # We want to pass list of ints and floats to TorchScript graph correctly
      # in _export_fx_to_ts, so we must disable FakeTensorMode. Otherwise, graph may
      # receive FakeTensor and results runtime error. In addition, TorchScript-based
      # ONNX exporter used in _ts_graph_to_onnx_model_in_protobuf is not compatible
      # with FakeTensorMode.
      with torch.utils._mode_utils.no_dispatch():
          # node_fixed_shape is only used on op_level_debug purpose.
          for node in fx_graph_module.graph.nodes:
              self.run_node(
                  node,
                  fx_graph_module,
                  onnxfunction_dispatcher,
                  op_level_debug,
                  onnxscript_graph,
                  onnxscript_tracer,
                  fx_name_to_onnxscript_value,
              )
  
      with diagnostic.log_section(logging.DEBUG, "ONNX Graph:"):
          diagnostic.debug("```\n%s\n```", onnxscript_graph.torch_graph)
  
      return onnxscript_graph
  
imports: from __future__ import annotations
  import inspect
  import logging
  import operator
  import re
  import types
  from typing import Callable, Dict, List, Optional, Sequence, Tuple, Union
  import onnxscript
  from onnxscript.function_libs.torch_lib import graph_building
  import torch
  import torch.fx
  from torch.onnx import _type_utils
  from torch.onnx._internal import _beartype
  from torch.onnx._internal.fx import _pass, diagnostics, onnxfunction_dispatcher, op_validation, type_utils
  from torch.utils import _pytree
label_desc: Use image node_id 3 for calling the FxOnnxInterpreter obj's underlying member method code with example usage: obj.run(fx_graph_module, onnxfunction_dispatcher, op_level_debug, parent_onnxscript_graph) and returns: onnxscript_graph