class_docstr: Transformation that fuses `nn.BatchNorm1d` following or preceding `nn.Linear` into a single `nn.Linear`.
  The fusion will be done only if the linear layer has the batch normalization as sole following node, or the batch normalization
  has the linear layer as sole following node.
  
  For example, fusion will not be done in the case
  ```
       Linear
       /   \
      /     \
  ReLU   BatchNorm1d
  ```
  
  Example:
  ```python
  >>> from transformers.utils.fx import symbolic_trace
  >>> from transformers import AutoModel
  
  >>> from optimum.fx.optimization import FuseBatchNorm1dInLinear
  
  >>> model = AutoModel.from_pretrained("nvidia/groupvit-gcc-yfcc")
  >>> model.eval()  # doctest: +IGNORE_RESULT
  
  >>> traced_model = symbolic_trace(
  ...     model,
  ...     input_names=["input_ids", "attention_mask", "pixel_values"],
  ...     disable_check=True
  ... )
  
  >>> transformation = FuseBatchNorm1dInLinear()
  >>> transformed_model = transformation(traced_model)
  ```
class_docstr_tok: ["Transformation","that","fuses","`","nn.BatchNorm1d","`","following","or","preceding","`","nn.Linear","`","into","a","single","`","nn.Linear","`",".","The","fusion","will","be","done","only","if","the","linear","layer","has","the","batch","normalization","as","sole","following","node",",","or","the","batch","normalization","has","the","linear","layer","as","sole","following","node",".","For","example",",","fusion","will","not","be","done","in","the","case","``","`","Linear","\/","\\","\/","\\","ReLU","BatchNorm1d","``","`","Example",":","``","`","python",">",">",">","from","transformers.utils.fx","import","symbolic_trace",">",">",">","from","transformers","import","AutoModel",">",">",">","from","optimum.fx.optimization","import","FuseBatchNorm1dInLinear",">",">",">","model","=","AutoModel.from_pretrained","(","``","nvidia\/groupvit-gcc-yfcc","''",")",">",">",">","model.eval","(",")","#","doctest",":","+IGNORE_RESULT",">",">",">","traced_model","=","symbolic_trace","(","...","model",",","...","input_names=","[","``","input_ids","''",",","``","attention_mask","''",",","``","pixel_values","''","]",",","...","disable_check=True","...",")",">",">",">","transformation","=","FuseBatchNorm1dInLinear","(",")",">",">",">","transformed_model","=","transformation","(","traced_model",")","``","`"]
code: def fuse(
      self,
      linear: torch.nn.Linear,
      bn1d: torch.nn.BatchNorm1d,
      bn1d_before: bool,
  ):
      # handle the case where there is no bias in the conv or the batchnorm has no learnable parameters
      linear_b = (
          linear.bias
          if linear.bias is not None
          else torch.zeros_like(bn1d.running_mean)
      )
      bn_w = (
          bn1d.weight
          if bn1d.weight is not None
          else torch.ones_like(bn1d.running_mean)
      )
      bn_b = (
          bn1d.bias
          if bn1d.bias is not None
          else torch.ones_like(bn1d.running_mean)
      )
  
      bn_var_rsqrt = torch.rsqrt(bn1d.running_var + bn1d.eps)
  
      if bn1d_before:
          linear.bias = torch.nn.Parameter(
              linear.weight
              @ (-bn_w * bn1d.running_mean * bn_var_rsqrt + bn_b)
              + linear_b
          )
          linear.weight = torch.nn.Parameter(
              linear.weight * (bn_w * bn_var_rsqrt)[None, :]
          )
      else:
          linear.bias = torch.nn.Parameter(
              (linear_b - bn1d.running_mean) * bn_var_rsqrt * bn_w
              + bn_b
          )
          linear.weight = torch.nn.Parameter(
              linear.weight * (bn_w * bn_var_rsqrt)[:, None]
          )
  
      return linear
  
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 2 for calling the FuseBatchNorm1dInLinear obj's underlying member method code with example usage: obj.fuse(linear, bn1d, bn1d_before) and returns: linear