class_docstr: ``Transformer`` is a special type of interpreter that produces a
  new ``Module``. It exposes a ``transform()`` method that returns
  the transformed ``Module``. ``Transformer`` does not require
  arguments to run, as ``Interpreter`` does. ``Transformer`` works
  entirely symbolically.
  
  Example:
  
      Suppose we want to swap all instances of ``torch.neg`` with
      ``torch.sigmoid`` and vice versa (including their ``Tensor``
      method equivalents). We could subclass ``Transformer`` like so::
  
          class NegSigmSwapXformer(Transformer):
              def call_function(self, target : 'Target', args : Tuple[Argument, ...], kwargs : Dict[str, Any]) -> Any:
                  if target == torch.sigmoid:
                      return torch.neg(*args, **kwargs)
                  return super().call_function(n)
  
              def call_method(self, target : 'Target', args : Tuple[Argument, ...], kwargs : Dict[str, Any]) -> Any:
                  if target == 'neg':
                      call_self, *args_tail = args
                      return call_self.sigmoid(*args_tail, **kwargs)
                  return super().call_method(n)
  
          def fn(x):
              return torch.sigmoid(x).neg()
  
          gm = torch.fx.symbolic_trace(fn)
  
          transformed : torch.nn.Module = NegSigmSwapXformer(gm).transform()
          input = torch.randn(3, 4)
          torch.testing.assert_close(transformed(input), torch.neg(input).sigmoid())
  
  Args:
      module (GraphModule): The ``Module`` to be transformed.
class_docstr_tok: ["``","Transformer","``","is","a","special","type","of","interpreter","that","produces","a","new","``","Module","``",".","It","exposes","a","``","transform","(",")","``","method","that","returns","the","transformed","``","Module","``",".","``","Transformer","``","does","not","require","arguments","to","run",",","as","``","Interpreter","``","does",".","``","Transformer","``","works","entirely","symbolically",".","Example",":","Suppose","we","want","to","swap","all","instances","of","``","torch.neg","``","with","``","torch.sigmoid","``","and","vice","versa","(","including","their","``","Tensor","``","method","equivalents",")",".","We","could","subclass","``","Transformer","``","like","so",":",":","class","NegSigmSwapXformer","(","Transformer",")",":","def","call_function","(","self",",","target",":","'Target","'",",","args",":","Tuple","[","Argument",",","...","]",",","kwargs",":","Dict","[","str",",","Any","]",")","-",">","Any",":","if","target","==","torch.sigmoid",":","return","torch.neg","(","*","args",",","*","*","kwargs",")","return","super","(",")",".call_function","(","n",")","def","call_method","(","self",",","target",":","'Target","'",",","args",":","Tuple","[","Argument",",","...","]",",","kwargs",":","Dict","[","str",",","Any","]",")","-",">","Any",":","if","target","==","'neg","'",":","call_self",",","*","args_tail","=","args","return","call_self.sigmoid","(","*","args_tail",",","*","*","kwargs",")","return","super","(",")",".call_method","(","n",")","def","fn","(","x",")",":","return","torch.sigmoid","(","x",")",".neg","(",")","gm","=","torch.fx.symbolic_trace","(","fn",")","transformed",":","torch.nn.Module","=","NegSigmSwapXformer","(","gm",")",".transform","(",")","input","=","torch.randn","(","3",",","4",")","torch.testing.assert_close","(","transformed","(","input",")",",","torch.neg","(","input",")",".sigmoid","(",")",")","Args",":","module","(","GraphModule",")",":","The","``","Module","``","to","be","transformed","."]
code: def __init__(self, module):
      super().__init__(module)
      self.new_graph = Graph()
      self.new_graph.set_codegen(module.graph._codegen)
  
      class TransformerTracer(Tracer):
          def __init__(self, graph: Graph):
              super().__init__()
              self.graph = graph
              self.tensor_attrs: Dict[torch.Tensor, str] = {}  # type: ignore[assignment]
  
          def is_leaf_module(self, _, __) -> bool:
              return True
  
      self.tracer = TransformerTracer(self.new_graph)
      self.tracer.root = module
  
imports: from .graph_module import GraphModule
  from .graph import Graph
  from .node import Argument, Node, Target, map_arg, map_aggregate
  from .proxy import Proxy
  from ._symbolic_trace import Tracer
  from ._compatibility import compatibility
  from .None import config
  import torch.fx.traceback
  import torch
  from typing import Any, Dict, Iterator, List, Optional, Tuple, Union
  import inspect
  from contextlib import contextmanager
  from torch.hub import tqdm
label_desc: Use image node_id 1 to create a new Transformer object from inherited base classes: Interpreter with example: obj = Transformer(module)