code: def transform_inplace_ops(graph, name_remap_dict=None):
      # TODO: one recent 1P model has included the op `copy_`. This is another
      # in-place op that should be fixed by this pass.
      # See rdar://64267506
  
      # As we modify ops, we'll need to remap symbols.
      if name_remap_dict is None:
          name_remap_dict = {}
  
      for node in graph.nodes:
          for k, v in name_remap_dict.items():
              node.replace_name(k, v)
  
          if node.kind == "append":
              if isinstance(node.parent, InternalTorchIRGraph):
                  # If append appears in a graph (outer block), replace
                  # subsequent uses of its input symbol with its output symbol.
                  name_remap_dict[node.inputs[0]] = node.outputs[0]
              elif node.parent.parent.kind == "loop":
                  # If append appears in a loop block, add its inputs to the block
                  # inputs and loop inputs, and its outputs to the block outputs
                  # and loop outputs.
  
                  # This is the global input to append. We need to add it to the
                  # loop's input list, and replace any uses after the node with
                  # @global_output below.
                  global_input = node.inputs[0]
                  # This will be the name of the input to append within the
                  # block. We need to add it to the block inputs.
                  local_input = node.parent.parent.name + ".0"
                  # This is the output of append. We need to add it to the list
                  # of block outputs.
                  local_output = node.outputs[0]
                  # This is the name of the new output from the loop. It should
                  # replace any uses of @global_input after the loop op.
                  global_output = local_output + ".out"
                  name_remap_dict[global_input] = global_output
  
                  node.parent.parent.inputs.append(global_input)
                  node.parent.inputs.append(local_input)
                  node.replace_name(global_input, local_input)
                  node.parent.outputs.append(local_output)
                  node.parent.parent.outputs.append(global_output)
                  node.parent.parent.name = node.parent.parent.outputs[
                      0
                  ]
              elif node.parent.parent.kind == "if":
                  # If append appears in an if/else block, add its outputs to the
                  # block outputs and loop outputs.
                  # Note that we can't assume the append appears in both blocks.
                  raise NotImplementedError(
                      "inplace_ops pass doesn't yet support append op inside conditional"
                  )
  
          for block in node.blocks:
              transform_inplace_ops(block, name_remap_dict)
  
      # Replace names in graph outputs
      for k, v in name_remap_dict.items():
          try:
              idx = graph.outputs.index(k)
          except ValueError:
              pass
          else:
              graph.outputs[idx] = v
  
imports: from collections import OrderedDict
  import logging
  from .internal_graph import *
label_desc: Use image node_id 1 for calling a global function with example usage: transform_inplace_ops(graph, name_remap_dict) without return types