code: def sink_waits(
      snodes: List["scheduler.BaseSchedulerNode"],
  ) -> List["scheduler.BaseSchedulerNode"]:
      """
      Greedily moves waits as late as possible (i.e. until we reach a use). Optimal in terms of
      communication overlap.
      """
      new_order = []
      cur_waits = set()
      for snode in snodes:
          if isinstance(snode.node, ir.Wait):
              cur_waits.add(snode)
          else:
              for wait in tuple_sorted(cur_waits):
                  if snode in wait.node_users:
                      new_order.append(wait)
                      cur_waits.remove(wait)
              new_order.append(snode)
      new_order.extend(tuple_sorted(cur_waits))
      return new_order
  
file_path: pytorch/torch/_inductor/comms.py
imports: from typing import List
  import torch
  from .None import config, ir, scheduler
  from .dependencies import WeakDep
  from .utils import tuple_sorted
label_desc: Use image node_id 1 for calling a global function with example usage: sink_waits(snodes) and returns: new_order