class_docstr: Transformation that fuses `nn.BatchNorm2d` following `nn.Conv2d` into a single `nn.Conv2d`.
  The fusion will be done only if the convolution has the batch normalization as sole following node.
  
  For example, fusion will not be done in the case
  ```
       Conv2d
       /   \
      /     \
  ReLU   BatchNorm2d
  ```
  
  Example:
  ```python
  >>> from transformers.utils.fx import symbolic_trace
  >>> from transformers import AutoModelForImageClassification
  
  >>> from optimum.fx.optimization import FuseBatchNorm2dInConv2d
  
  >>> model = AutoModelForImageClassification.from_pretrained("microsoft/resnet-50")
  >>> model.eval()  # doctest: +IGNORE_RESULT
  
  >>> traced_model = symbolic_trace(
  ...     model,
  ...     input_names=["pixel_values"],
  ...     disable_check=True
  ... )
  
  >>> transformation = FuseBatchNorm2dInConv2d()
  >>> transformed_model = transformation(traced_model)
  ```
class_docstr_tok: ["Transformation","that","fuses","`","nn.BatchNorm2d","`","following","`","nn.Conv2d","`","into","a","single","`","nn.Conv2d","`",".","The","fusion","will","be","done","only","if","the","convolution","has","the","batch","normalization","as","sole","following","node",".","For","example",",","fusion","will","not","be","done","in","the","case","``","`","Conv2d","\/","\\","\/","\\","ReLU","BatchNorm2d","``","`","Example",":","``","`","python",">",">",">","from","transformers.utils.fx","import","symbolic_trace",">",">",">","from","transformers","import","AutoModelForImageClassification",">",">",">","from","optimum.fx.optimization","import","FuseBatchNorm2dInConv2d",">",">",">","model","=","AutoModelForImageClassification.from_pretrained","(","``","microsoft\/resnet-50","''",")",">",">",">","model.eval","(",")","#","doctest",":","+IGNORE_RESULT",">",">",">","traced_model","=","symbolic_trace","(","...","model",",","...","input_names=","[","``","pixel_values","''","]",",","...","disable_check=True","...",")",">",">",">","transformation","=","FuseBatchNorm2dInConv2d","(",")",">",">",">","transformed_model","=","transformation","(","traced_model",")","``","`"]
code: def transform(self, graph_module: "GraphModule") -> "GraphModule":
      for node in graph_module.graph.nodes:
          if (
              node.op == "call_module"
              and node.args[0].op == "call_module"
          ):
              if (
                  type(graph_module.get_submodule(node.target))
                  is torch.nn.BatchNorm2d
                  and type(
                      graph_module.get_submodule(node.args[0].target)
                  )
                  is torch.nn.Conv2d
              ):
                  if (
                      len(node.args[0].users) > 1
                  ):  # Output of conv is used by other nodes
                      continue
  
                  fused_conv = self.fuse(
                      conv2d=graph_module.get_submodule(
                          node.args[0].target
                      ),
                      bn2d=graph_module.get_submodule(node.target),
                  )
  
                  # replace the old nn.Conv2d by the fused one
                  parent_name, _, name = node.args[0].target.rpartition(
                      "."
                  )
                  parent_module = graph_module.get_submodule(
                      parent_name
                  )
                  setattr(parent_module, name, fused_conv)
  
                  # delete batchnorm from the modules
                  parent_name, _, name = node.target.rpartition(".")
                  parent_module = graph_module.get_submodule(
                      parent_name
                  )
                  delattr(parent_module, name)
  
                  node.replace_all_uses_with(node.args[0])
                  graph_module.graph.erase_node(node)
      return graph_module
  
imports: import collections
  import copy
  import functools
  import itertools
  import operator
  import warnings
  from abc import ABC, abstractmethod
  from typing import TYPE_CHECKING, List
  import torch
  from transformers.file_utils import add_end_docstrings
  from transformers.utils.fx import _gen_constructor_wrapper
label_desc: Use image node_id 1 for calling the FuseBatchNorm2dInConv2d obj's underlying member method code with example usage: obj.transform(graph_module) and returns: graph_module