code: def pre_grad_passes(gm: torch.fx.GraphModule, example_inputs):
      """
      Apply passes on the input FX graph using Torch IR.
  
      WARNING:
      The IR before grad is not functional or normalized, so it is harder
      to write passes on this IR.  Passes must be safe with respect to
      aliasing and mutation and need to handle all possible arg schemas.
  
      Consider adding a new pass to post_grad.py or joint_graph.py which
      are after functionalization and normalization.
      """
  
      if config.pattern_matcher:
          lazy_init()
          # explicitly run with predispatch atenIR based passes
          if config.is_predispatch:
              group_batch_fusion_passes(gm.graph, pre_grad=True)
              predispatch_pass.apply(gm.graph)
          else:
              gm = fuse_fx(gm, example_inputs)
              numpy_compat_normalization(gm.graph)
              print_graph(
                  gm.graph,
                  "Before group batch fusion in pre grad pass.",
              )
              group_batch_fusion_passes(gm.graph, pre_grad=True)
              print_graph(
                  gm.graph, "Before split cat in pre grad pass."
              )
              for pattern_matcher_pass in pattern_matcher_passes:
                  pattern_matcher_pass.apply(gm.graph)
                  print_graph(
                      gm.graph,
                      "Apply split cat pattern matcher PatternMatcherPass in pre grad.",
                  )
  
      if config.pre_grad_custom_pass is not None:
          config.pre_grad_custom_pass(gm.graph)
      stable_topological_sort(gm.graph)
      gm.graph.lint()
      gm.recompile()
  
      print_graph(gm.graph, "After recompile in pre grad pass.")
  
      return gm
  
imports: import copy
  import logging
  from typing import List, Optional
  import torch
  import torch.nn
  from torch._dynamo.utils import detect_fake_mode
  from torch._utils_internal import print_graph
  from torch.fx.experimental.optimization import matches_module_pattern, replace_node_module
  from torch.fx.passes.shape_prop import ShapeProp
  from torch.nn import functional
  from torch.nn.utils.fusion import fuse_conv_bn_eval, fuse_conv_bn_weights
  from ..None import config
  from ..fx_utils import matches_module_function_pattern
  from ..pattern_matcher import init_once_fakemode, PatternMatcherPass, stable_topological_sort
  from ..utils import is_cpu_device
  from .group_batch_fusion import group_batch_fusion_passes
  from .misc_patterns import numpy_compat_normalization
label_desc: Use image node_id 2 for calling a global function with example usage: pre_grad_passes(gm, example_inputs) and returns: gm