code: def _build_map_helper(
      tensor,
      finished_nodes,
      nodes_in_progress,
      nodes_in_decreasing_depth,
      operation_indices,
  ):
      """Recursive helper for `_build_map`."""
      (
          operation,
          node_index,
          _,
      ) = tensor._keras_history
      if not operation:
          return
  
      node = operation._inbound_nodes[node_index]
  
      # Don't repeat work for shared subgraphs
      if node in finished_nodes:
          return
  
      # Prevent cycles.
      if node in nodes_in_progress:
          raise ValueError(
              f"Tensor {tensor} from operation '{operation.name}' is part of a "
              "cycle."
          )
  
      # Store the traversal order for operation sorting.
      if operation not in operation_indices:
          operation_indices[operation] = len(operation_indices)
  
      # Propagate to all previous tensors connected to this node.
      nodes_in_progress.add(node)
      if not node.is_input:
          for tensor in node.input_tensors:
              _build_map_helper(
                  tensor,
                  finished_nodes,
                  nodes_in_progress,
                  nodes_in_decreasing_depth,
                  operation_indices,
              )
  
      finished_nodes.add(node)
      nodes_in_progress.remove(node)
      nodes_in_decreasing_depth.append(node)
  
imports: import collections
  import tree
  from keras.api_export import keras_export
  from keras.backend import KerasTensor
  from keras.backend.config import backend
  from keras.ops.operation import Operation
  from keras.utils.nest import pack_sequence_as
label_desc: Use image node_id 4 for calling a global function with example usage: _build_map_helper(tensor, finished_nodes, nodes_in_progress, nodes_in_decreasing_depth, operation_indices) without return types