code: def rewrite_scatter_to_gather(mod, num_scales):
      """Rewrite the input graph to replace a repeated scatter loop with
      a batched gather. The scatter loop is used in torchvision MultiScaleRoIAlign
      to merge roi_align results for all scales. The scatter is used to emulate
      inplace updates.
      """
      mod["main"] = rewrite(ScatterRewrite(num_scales), mod["main"])
      return mod
  
imports: from ..None import expr
  from ..None import op
  from ..dataflow_pattern import wildcard, is_constant, is_op, rewrite, is_tuple, is_tuple_get_item, is_if, DFPatternCallback
label_desc: Use image node_id 9 for calling a global function with example usage: rewrite_scatter_to_gather(mod, num_scales) and returns: mod