class_docstr: Helper class uses for constructing Python bytecode
class_docstr_tok: ["Helper","class","uses","for","constructing","Python","bytecode"]
docstr: Generate code such that top-of-stack (TOS) is set to value
docstr_tok: ["Generate","code","such","that","top-of-stack","(","TOS",")","is","set","to","value"]
code: def __call__(self, value, allow_cache=True):
      """Generate code such that top-of-stack (TOS) is set to value"""
      if isinstance(value, Source):
          self._output.extend(value.reconstruct(self))
          self.clear_tos()
          return
  
      assert isinstance(value, VariableTracker)
      output = self._output
      graph_outputs = self.graph_outputs
  
      if self.top_of_stack is value and allow_cache:
          output.append(create_dup_top())
          return
  
      if self.mutable_side_effects_from_source:
          # this is needed to get aliasing relationships right
          # value.mutable_local.source will get mutated to hold `value`
          # mutable_side_effects_from_source=False is used to codegen the mutation
          # mutable_side_effects_from_source=True is used to codegen a reference
          from .side_effects import MutableSideEffects
  
          if isinstance(value.mutable_local, MutableSideEffects):
              self(value.mutable_local.source)
              return
  
      if allow_cache:
          if (
              value.mutable_local
              and value.mutable_local in self.tempvars
          ):
              output.append(
                  self.create_load(self.tempvars[value.mutable_local])
              )
              self.top_of_stack = value
              return
          if self.tempvars.get(value) is not None:
              output.append(self.create_load(self.tempvars[value]))
              self.top_of_stack = value
              return
  
      if (
          value.source is not None
          and allow_cache
          and self.value_from_source
      ):
          output.extend(value.source.reconstruct(self))
      elif value.is_python_constant() and is_safe_constant(
          value.as_python_constant()
      ):
          output.append(
              self.create_load_const(value.as_python_constant())
          )
      elif isinstance(value, TensorWithTFOverrideVariable):
          graph_outputs_key = self.add_graph_output(value)
  
          self.load_import_from(utils.__name__, "to_subclass")
          self.load_graph_output(graph_outputs[graph_outputs_key].index)
          output.append(
              self.create_load_global(
                  value.global_mangled_class_name(), False, add=True
              )
          )
          output.extend(create_call_function(2, True))
      elif isinstance(
          value,
          (
              TensorVariable,
              SymNodeVariable,
              UnspecializedPythonVariable,
              NumpyNdarrayVariable,
          ),
      ):
          graph_outputs_key = self.add_graph_output(value)
  
          if isinstance(value, NumpyNdarrayVariable):
              self.load_import_from(utils.__name__, "to_numpy_helper")
  
          self.load_graph_output(graph_outputs[graph_outputs_key].index)
  
          if isinstance(value, NumpyNdarrayVariable):
              output.extend(create_call_function(1, True))
          elif (
              isinstance(value, UnspecializedPythonVariable)
              and value.need_unwrap
          ):
              output.extend(
                  [self.create_load_attr("item")]
                  + create_call_function(0, True)
              )
      elif isinstance(value, NNModuleVariable):
          parts = value.module_key.split(".")
          if parts[0] in self.code_options["co_varnames"]:
              output.append(self.create_load(parts[0]))
              parts = parts[1:]
          else:
              assert self.root is not None
              output.append(self.create_load_output(self.root))
          for part in parts:
              output.append(self.create_load_attr(part))
      else:
          self.uses[value] += 1
          try:
              output.extend(value.reconstruct(self))
          except NotImplementedError:
              unimplemented(f"reconstruct: {value}")
          if allow_cache and value in self.tempvars:
              self._output.append(create_dup_top())
              self.add_cache(value)
  
      self.top_of_stack = value
  
imports: import collections
  import dataclasses
  import re
  import sys
  import types
  from typing import Counter, Dict, List, Optional
  import torch.nn
  from .None import utils
  from .bytecode_transformation import create_call_function, create_dup_top, create_instruction, create_load_global, create_rot_n, Instruction
  from .exc import unimplemented
  from .source import AttrSource, Source
  from .utils import is_safe_constant, rot_n_helper
  from .variables.base import VariableTracker
  from .variables.nn_module import NNModuleVariable
  from .variables.tensor import NumpyNdarrayVariable, SymNodeVariable, TensorVariable, UnspecializedPythonVariable
  from .variables.torch_function import TensorWithTFOverrideVariable
label_desc: Use image node_id 4 for calling the PyCodegen obj's underlying member method code with example usage: obj.__call__(value, allow_cache) without return types