code: def fuse_conv_bn(
      gm: torch.fx.GraphModule, inplace=False
  ) -> torch.fx.GraphModule:
      """
      Fuses Convolution/BN layers for inference purposes.
      """
      modules_patterns = [
          (torch.nn.Conv1d, torch.nn.BatchNorm1d),
          (torch.nn.Conv2d, torch.nn.BatchNorm2d),
          (torch.nn.Conv3d, torch.nn.BatchNorm3d),
      ]
      module_function_patterns = [
          (torch.nn.Conv1d, F.batch_norm),
          (torch.nn.Conv2d, F.batch_norm),
          (torch.nn.Conv3d, F.batch_norm),
      ]
      modules = dict(gm.named_modules())
      for pattern in modules_patterns:
          for node in gm.graph.nodes:
              if matches_module_pattern(pattern, node, modules):
                  if (
                      len(node.args[0].users) > 1
                  ):  # Output of conv is used by other nodes
                      continue
                  conv = modules[node.args[0].target]
                  bn = modules[node.target]
                  eval_mode = all(not n.training for n in [conv, bn])
                  if not eval_mode:
                      continue
                  if not bn.track_running_stats:
                      continue
                  fused_conv = fuse_conv_bn_eval(conv, bn)
                  replace_node_module(node.args[0], modules, fused_conv)
                  node.replace_all_uses_with(node.args[0])
                  gm.graph.erase_node(node)
      gm.graph.lint()
      for pattern in module_function_patterns:
          for node in gm.graph.nodes:
              if matches_module_function_pattern(
                  pattern, node, modules
              ):
                  # TODO: support kwargs.
                  if len(node.args) != 8:
                      continue
                  conv = modules[node.args[0].target]
                  bn_training = node.args[5]
                  bn_eps = node.args[7]
                  if conv.training or bn_training:
                      continue
                  if type(bn_eps) is not float:
                      continue
                  bn_args_is_constant = all(
                      n.op == "get_attr" and len(n.users) == 1
                      for n in node.args[1:5]
                  )
                  if not bn_args_is_constant:
                      continue
                  bn_running_mean = fetch_attr(node.args[1].target, gm)
                  bn_running_var = fetch_attr(node.args[2].target, gm)
                  bn_weight = fetch_attr(node.args[3].target, gm)
                  bn_bias = fetch_attr(node.args[4].target, gm)
                  if bn_running_mean is None or bn_running_var is None:
                      continue
                  fused_conv = copy.deepcopy(conv)
                  (
                      fused_conv.weight,
                      fused_conv.bias,
                  ) = fuse_conv_bn_weights(
                      fused_conv.weight,
                      fused_conv.bias,
                      bn_running_mean,
                      bn_running_var,
                      bn_eps,
                      bn_weight,
                      bn_bias,
                  )
                  replace_node_module(node.args[0], modules, fused_conv)
                  node.replace_all_uses_with(node.args[0])
                  gm.graph.erase_node(node)
      gm.graph.lint()
      gm.recompile()
  
      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 6 for calling a global function with example usage: fuse_conv_bn(gm, inplace) and returns: gm