code: def test_subgraph_rewriter_replaces_referenced_submodules(self):
      class M(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.sigmoid = torch.nn.Sigmoid()
              self.submod = torch.nn.ReLU()
  
          def forward(self, x):
              x = x + 1
              return self.submod(self.sigmoid(x))
  
      class Pattern(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.sigmoid = torch.nn.Sigmoid()
              self.submod = torch.nn.ReLU()
  
          def forward(self, x):
              return self.submod(self.sigmoid(x))
  
      class Replacement(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.tanh = torch.nn.Tanh()
              self.submod = torch.nn.ReLU()
  
          def forward(self, x):
              return self.submod(self.tanh(x))
  
      class Comparison(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.tanh = torch.nn.Tanh()
              self.submod = torch.nn.ReLU()
  
          def forward(self, x):
              x = x + 1
              return self.submod(self.tanh(x))
  
      traced = symbolic_trace(M())
      comparison = Comparison()
  
      x = torch.randn(3, 4)
  
      subgraph_rewriter.replace_pattern(
          traced, Pattern(), Replacement()
      )
  
      traced.graph.lint()
  
      ref_outs = comparison(x)
      test_outs = traced.forward(x)
      self.assertEqual(ref_outs, test_outs)
  
      traced.get_submodule("tanh")
      with self.assertRaisesRegex(AttributeError, "has no attribute"):
          traced.get_submodule("sigmoid")
  
      submod = traced.get_submodule("submod")
      self.assertEqual(type(submod), torch.nn.ReLU)
  
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 13 for calling the TestSubgraphRewriter obj's underlying member method code with example usage: obj.test_subgraph_rewriter_replaces_referenced_submodules() and returns: self, self, self, self