code: def test_subgraph_rewriter_local_revert(self):
      # Following model will have 3 anchors as the matching candidate with the given pattern
      # Anchor 1 and 3 is a real match, but anchor 2 is not.
      # The subgraph rewriter should be able to revert the changes made while matching anchor 2.
      # Final match with anchor 3 should be successful.
  
      class M(torch.nn.Module):
          def __init__(self) -> None:
              super().__init__()
              self.w0 = torch.nn.Parameter(torch.empty([128, 128]))
              self.b0 = torch.nn.Parameter(torch.empty([128]))
              self.w1 = torch.nn.Parameter(torch.empty([128, 128]))
              self.b1 = torch.nn.Parameter(torch.empty([128]))
              self.w2 = torch.nn.Parameter(torch.empty([128, 128]))
              self.b2 = torch.nn.Parameter(torch.empty([128]))
              self.w3 = torch.nn.Parameter(torch.empty([128, 128]))
              self.b3 = torch.nn.Parameter(torch.empty([128]))
              self.w4 = torch.nn.Parameter(torch.empty([128, 128]))
              self.b4 = torch.nn.Parameter(torch.empty([128]))
  
          def forward(self, in0, in1):
              lin_res_1 = torch.nn.functional.linear(
                  in1, self.w0, bias=self.b0
              )
              lin_res_2 = torch.nn.functional.linear(
                  lin_res_1, self.w1, bias=self.b1
              )
              # potential match at anchor 1
              mul_res_1 = in1 * lin_res_2
              sum_res_1 = mul_res_1 + in1
              lin_res_3 = torch.nn.functional.linear(
                  sum_res_1, self.w2, bias=self.b2
              )
              sigmoid_res_1 = torch.sigmoid(lin_res_3)
              # potential match at anchor 2
              mul_res_2 = lin_res_3 * sigmoid_res_1
              lin_res_4 = torch.nn.functional.linear(
                  in0, self.w3, bias=self.b3
              )
              lin_res_5 = torch.nn.functional.linear(
                  lin_res_4, self.w4, bias=self.b4
              )
              # potential match at anchor 3
              mul_res_3 = in0 * lin_res_5
              sum_res_2 = mul_res_3 + in0
              cat_res = torch.cat(
                  [mul_res_2, sum_res_2],
                  dim=1,
              )
              return cat_res
  
      def gemm_bias_mul_pattern_with_c(a, b, bias, c):
          lin_res = torch.nn.functional.linear(a, b, bias=bias)
          mul_res = c * lin_res
          return lin_res, mul_res
  
      def gemm_bias_mul_replacement_with_c(a, b, bias, c):
          lin_res, mul_res = wrapped_gemm_bias_mul_with_c(a, b, bias, c)
          return lin_res, mul_res
  
      traced = symbolic_trace(M())
      matches = subgraph_rewriter.replace_pattern(
          traced,
          gemm_bias_mul_pattern_with_c,
          gemm_bias_mul_replacement_with_c,
      )
  
      self.assertEqual(len(matches), 2)
  
      repalcement_node_found = 0
      for node in traced.graph.nodes:
          if node.target == wrapped_gemm_bias_mul_with_c:
              repalcement_node_found += 1
  
      self.assertEqual(repalcement_node_found, 2)
  
imports: import os
  import sys
  import torch
  from torch.fx import symbolic_trace, subgraph_rewriter
  from torch.fx.annotate import annotate
  from torch.fx.experimental.rewriter import RewritingTracer
  from torch.testing._internal.jit_utils import JitTestCase
label_desc: Use image node_id 22 for calling the TestSubgraphRewriter obj's underlying member method code with example usage: obj.test_subgraph_rewriter_local_revert() and returns: lin_res,  mul_res, lin_res,  mul_res, cat_res