code: def _get_view_inverse_node_usages(
      later_node_usages: Set[Node], self_aliases: Set[Node]
  ) -> Set[Node]:
      def matching_view_metadata(a, b):
          return (
              a.size() == b.size()
              and a.stride() == b.stride()
              and a.storage_offset() == b.storage_offset()
          )
  
      view_inverse_nodes = set()
      # Go through them in node order, so we can see chains of view_scatter ops.
      for n in sorted(
          later_node_usages, key=lambda x: x.meta["node_idx"]
      ):
          if n.target not in _VIEW_INVERSE_MAP:
              continue
          base = n.args[0]
          mutated_view = n.args[1]
          assert isinstance(base, Node)
          assert isinstance(base.meta["fake_result"], FakeTensor)
          assert isinstance(mutated_view, Node)
          assert isinstance(
              mutated_view.meta["fake_result"], FakeTensor
          )
          # Check that this view_inverse op actually corresponds to taking doing the inverse
          # of one of our existing self_alias nodes.
          original_view = _VIEW_INVERSE_MAP[n.target]
          for self_alias in self_aliases:
              # We're looking for some alias of the self arg, "alias",
              # that was created from some op `alias = foo(base, args...)`
              # such that the current _scatter op "inverts" that foo call.
              # We can check that by running the original op again, and checking that the strides match.
              if "view_of" not in self_alias.meta:
                  continue
              self_alias_base = self_alias.meta["view_of"]
              try:
                  # The we're trying to re-use the args from the view_scatter call inside of the corresponding
                  # view op, which might throw. This just indicates that view_scatter op isn't a valid inverse
                  # of the current alias we're looking at.
                  view_replay_metadata = original_view(
                      self_alias_base.meta["fake_result"],
                      *n.args[2:],
                      **n.kwargs,
                  )
                  expected_metadata = self_alias.meta["fake_result"]
                  # If the alias and its base both have matching metadata, then this view_scatter op is valid to re-inplace.
                  if matching_view_metadata(
                      self_alias_base.meta["fake_result"],
                      base.meta["fake_result"],
                  ) and matching_view_metadata(
                      view_replay_metadata, expected_metadata
                  ):
                      view_inverse_nodes.add(n)
              except Exception:
                  continue
  
      return view_inverse_nodes
  
imports: import torch
  from torch.fx import Node
  from torch.fx._compatibility import compatibility
  from torch._subclasses.fake_tensor import FakeTensorMode, FakeTensor
  from torch.utils._pytree import tree_map_only
  from torch.utils import _pytree
  from torch.multiprocessing.reductions import StorageWeakRef
  import _operator
  from enum import Enum
  import itertools
  from typing import Set, Dict
  from collections import defaultdict
label_desc: Use image node_id 6 for calling a global function with example usage: _get_view_inverse_node_usages(later_node_usages, _aliases) and returns: view_inverse_nodes, unknown