code: def flatten_graph_output_values(graph):
      """
      CoreML can't handle nested iterables of tensors, so we flatten the
      outputs of any graph that produces them.
      """
      node_names = [node.name for node in graph.nodes]
      new_graph_outputs = graph.outputs
      changed = True
      notified = False
  
      while changed:
          old_graph_outputs = new_graph_outputs
          new_graph_outputs = []
          changed = False
          for outp in old_graph_outputs:
              # Find the node that generates this output var.
              # It is possible to not find the output var in the list of node
              # names since nodes are named after their first output. In that
              # case, it means the output var comes from a node that returns
              # multiple outputs, which means that node cannot be a construct op.
              try:
                  node_idx = node_names.index(outp)
              except:
                  # @outp doesn't come from a construct op
                  new_graph_outputs.append(outp)
                  continue
              if graph.nodes[node_idx].kind in [
                  "tupleconstruct",
                  "listconstruct",
              ]:
                  # Since this output came from a construct op, we can replace it
                  # with the inputs to the op.
                  new_graph_outputs.extend(graph.nodes[node_idx].inputs)
                  changed = True
                  if not notified:
                      notified = True
                      logger.warning(
                          "Tuple detected at graph output. This will be flattened in the converted model."
                      )
              else:
                  new_graph_outputs.append(outp)
      # Note: if we flattened outputs, there are likely to be construct ops
      # that are no longer needed. These will be removed in a later DCE pass.
      graph.outputs = new_graph_outputs
  
file_path: coremltools/coremltools/converters/mil/frontend/torch/torchir_passes.py
imports: from collections import OrderedDict, defaultdict
  from coremltools import _logger
  from .internal_graph import InternalTorchIRGraph, InternalTorchIRNode
label_desc: Use image node_id 5 for calling a global function with example usage: flatten_graph_output_values(graph) without return types