code: def _replace_literals_with_existing_placeholders(
      gm: torch.fx.GraphModule,
      exclude_literals: Optional[List[Any]] = None,
      literal_to_ph_idx: Optional[
          Dict[Union[float, int, bool, torch.dtype], int]
      ] = None,
  ):
      """Replace the literals in the graph with **existing** placeholder nodes, so that the literal arguments
      in the graph can be matched and replaced
  
      To use this, all literal args in the graph should be unique and each of them should correspond
      to exactly one placeholder node
  
      # 1. Original Graph
      def pattern(self, x_i8, scale, zero_point, quant_min, quant_max):
          return torch.dequantize_per_tensor(x_i8, scale, zero_point, quant_min, quant_max)
  
      def replacement(x_i8, scale, zero_point, quant_min, quant_max):
          x_i8 = torch.clamp(x_i8, quant_min, quant_max)
          return ((x_i8.to(torch.float32) - zero_point) * scale).to(dtype=torch.float32)
  
      example_inputs = (
          torch.randn(1, 3, 3, 3),
          1.0,
          0,
          -128,
          127,
      )
      pattern_gm = get_aten_graph_module(pattern, example_inputs)
      replacement_gm = get_aten_graph_module(pattern, example_inptus)
  
      # 2. Before calling replace literals we'll see the following graph:
      def pattern(self, x_i8, scale, zero_point, quant_min, quant_max):
          # scale/zero_point/quant_min/quant_max are burnt in since they are scalar values
          return torch.dequantize_per_tensor(x_i8, 1.0, 0, -128, 127)
  
      def replacement(x_i8, scale, zero_point, quant_min, quant_max):
          # scale/zero_point/quant_min/quant_max are burnt in since they are scalar values
          x_i8 = torch.clamp(x_i8, -128, 127)
          return ((x_i8.to(torch.float32) - 0) * 1.0).to(dtype=torch.float32)
  
      # Note that literal args appear in different order in pattern and replacement graph, so
      # we can't use _replace_literals_with_new_placeholders
  
      literal_to_ph_idx = {1.0: 1, 0: 2, -128: 3, 127: 4}
      pattern_gm = _replace_literals_with_existing_placeholders(pattern_gm, literal_to_ph_idx)
      replacement_gm = _replace_literals_with_existing_placeholders(replacement_gm, literal_to_ph_idx)
  
      # 3. After replacing literals with existing placeholder nodes
  
      def pattern(self, x_i8, scale, zero_point, quant_min, quant_max):
          # scale/zero_point/quant_min/quant_max are burnt in since they are scalar values
          return torch.dequantize_per_tensor(x_i8, scale, zero_point, quant_min, quant_max)
  
      def replacement(x_i8, scale, zero_point, quant_min, quant_max):
          # scale/zero_point/quant_min/quant_max are burnt in since they are scalar values
          x_i8 = torch.clamp(x_i8, quant_min, quant_max)
          return ((x_i8.to(torch.float32) - zero_point) * scale).to(dtype=torch.float32)
      """
      if exclude_literals is None:
          exclude_literals = []
  
      if literal_to_ph_idx is None:
          literal_to_ph_idx = {}
  
      phs = [
          node for node in gm.graph.nodes if node.op == "placeholder"
      ]
  
      for node in gm.graph.nodes:
          if node.op != "call_function":
              continue
          new_args = []
          for arg in node.args:
              if (
                  _is_literal(arg)
                  and arg not in exclude_literals
                  and arg in literal_to_ph_idx
              ):
                  ph_idx = literal_to_ph_idx[arg]
                  ph_node = phs[ph_idx]
                  new_args.append(ph_node)
              else:
                  new_args.append(arg)
          new_args = tuple(new_args)
          node.args = new_args
      return gm
  
imports: import operator
  import types
  import torch
  from torch._export import capture_pre_autograd_graph
  from torch.fx import GraphModule, Node
  from torch.nn.utils.fusion import fuse_conv_bn_weights
  from typing import Any, Callable, Dict, Optional, Tuple, List, Union
  from torch.utils._pytree import LeafSpec
  from torch.ao.quantization.fx._decomposed import quantized_decomposed_lib
  from torch.ao.quantization.quantizer import QuantizationAnnotation
label_desc: Use image node_id 19 for calling a global function with example usage: _replace_literals_with_existing_placeholders(gm, exclude_literals, literal_to_ph_idx) and returns: gm