code: def fuse_fx(
      model: Union[PreTrainedModel, GraphModule],
      fuse_custom_config_dict: Optional[Dict[str, Any]] = None,
      input_names: Optional[List[str]] = None,
      check: bool = True,
  ) -> GraphModule:
      """
      Transformers models compatible version of torch.quantization.quantize_fx.fuse_fx, refer to the
      [PyTorch documentation](https://pytorch.org/docs/stable/generated/torch.quantization.quantize_fx.fuse_fx.html) for
      more details.
  
      Args:
          model (`PreTrainedModel` or `torch.fx.GraphModule`):
              The model to fuse.
          fuse_custom_config_dict (`Dict[str, Any]`, *optional*):
              Dictionary for custom configurations for fuse_fx, refer to the PyTorch documentation for more details.
          input_names (`List[str]`, *optional*):
              The input names of the model, only used to trace if model is a PreTrainedModel. This is not needed if model
              is already a GraphModule.
          check (`bool`, *optional*, defaults to `True`):
              If True, a check is done to verify that the model can be traced.
  
      Returns:
          `torch.fx.GraphModule`: A GraphModule with the fused modules.
  
      Example:
  
          ```python
          >>> from transformers import BertModel
          >>> from optimum.fx.quantization import fuse_fx
  
          >>> model = BertModel.from_pretrained("bert-base-uncased")
          >>> model = fuse_fx(model)
          ```
      """
      if not isinstance(model, GraphModule):
          if input_names is None:
              input_names = model.dummy_inputs.keys()
          input_names = list(input_names)
          model = symbolic_trace(
              model, input_names, disable_check=not check
          )
      orig_symbolic_trace = torch.fx.symbolic_trace
      torch.fx.symbolic_trace = lambda x: x
      graph_module = orig_fuse_fx(
          model, fuse_custom_config_dict=fuse_custom_config_dict
      )
      torch.fx.symbolic_trace = orig_symbolic_trace
      return graph_module
  
imports: from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Tuple, Type, Union
  import torch
  from torch.fx.node import Argument, Node, Target
  from torch.nn.intrinsic import _FusedModule
  from torch.quantization.fx.graph_module import GraphModule, ObservedGraphModule
  from torch.quantization.quantize_fx import Scope, ScopeContextManager
  from torch.quantization.quantize_fx import fuse_fx
  from torch.quantization.quantize_fx import prepare_fx
  from torch.quantization.quantize_fx import prepare_qat_fx
  from transformers import PreTrainedModel
  from transformers.utils.fx import HFTracer, check_if_model_is_supported, get_concrete_args, symbolic_trace
  from ..utils import check_if_available
label_desc: Use image node_id 2 for calling a global function with example usage: fuse_fx(model, fuse_custom_config_dict, input_names, check) and returns: graph_module