code: def test_aten_inplace(self):
      def test_not_new_alias(x):
          y = x[0]
          y.add_(2)
          return y
  
      fn = torch.jit.script(test_not_new_alias)
      graph = fn.graph
      self.run_pass("remove_mutation", graph)
      FileCheck().check("aten::add_").run(graph)
      self.assertEqual(
          fn(torch.ones([2, 2])), test_not_new_alias(torch.ones([2, 2]))
      )
  
      def test_no_lowering():
          x = torch.tensor([2, 2])
          x[0] = 3
          return x
  
      # there is no functional equivalent of x[0] = ...
      fn = torch.jit.script(test_no_lowering)
      graph = fn.graph
      self.run_pass("remove_mutation", graph)
      FileCheck().check("aten::copy_").run(graph)
      self.assertEqual(fn(), test_no_lowering())
  
      def test_move_before_not_valid():
          y = torch.tensor([2, 2])
          z = y + 2
          y.add_(2)
          return y, z
  
      fn = torch.jit.script(test_move_before_not_valid)
      graph = fn.graph
      self.run_pass("remove_mutation", graph)
      FileCheck().check("aten::add_").run(graph)
      self.assertEqual(fn(), test_move_before_not_valid())
  
      def test_successful():
          x = torch.tensor([2, 2])
          x.add_(1)
          x.add_(3)
          y = x + 4
          return x, y
  
      fn = torch.jit.script(test_successful)
      graph = fn.graph
      self.run_pass("remove_mutation", graph)
      FileCheck().check_not("aten::add_").run(graph)
      self.assertEqual(test_successful(), fn())
  
      def test_intermediary_use():
          x = torch.tensor([2, 2])
          x.add_(1)
          y = x + 4
          x.add_(3)
          return x, y
  
      fn = torch.jit.script(test_intermediary_use)
      graph = fn.graph
      FileCheck().check_count("aten::add_", 2).run(graph)
      self.run_pass("remove_mutation", graph)
      # Unable to remove the second add_ because of the y = x + 4 use
      # In the future we could duplicating the value of x as a temporary and replacing
      # its intermediary use (so long as aliasing is safe)
      FileCheck().check_count("aten::add_", 1).run(graph)
      self.assertEqual(test_intermediary_use(), fn())
  
file_path: pytorch/test/jit/test_remove_mutation.py
imports: import os
  import sys
  import torch
  from torch.testing import FileCheck
  from typing import List
  from torch.testing._internal.jit_utils import JitTestCase, freeze_rng_state
label_desc: Use image node_id 1 for calling the TestRemoveMutation obj's underlying member method code with example usage: obj.test_aten_inplace() and returns: y, x, y,  z, x,  y, x,  y