code: def convert_frame_assert(
      compiler_fn: CompilerFn,
      one_graph: bool = True,
      export: bool = False,
      export_constraints=None,
  ):
      """Fully convert a frame into an FX graph"""
      reset_graph_break_dup_checker()
  
      def _convert_frame_assert(
          frame: types.FrameType, cache_entry, hooks: Hooks, frame_state
      ):
          increment_frame()
  
          code = frame.f_code
  
          cache_size = compute_cache_size(frame, cache_entry)
          recompile_reasons = None
          if is_recompilation(cache_size):
              recompile_reasons = (
                  get_and_maybe_log_recompilation_reason(
                      cache_entry, frame
                  )
              )
  
          input_codes.add(code)
          if code in output_codes:
              return None
          if (
              os.environ.get("TORCHDYNAMO_DEBUG_FUNCTION")
              and os.environ.get("TORCHDYNAMO_DEBUG_FUNCTION")
              != code.co_name
          ):
              return None
          if code.co_name == "<genexpr>" and code.co_filename.endswith(
              (
                  "transformers/file_utils.py",
                  "transformers/utils/generic.py",
                  "diffusers/utils/outputs.py",
              )
          ):
              # not needed, but cleans up torchbench error stats
              return None
          if code.co_name == "__setattr__":
              # setattr could be tricky to handle generally,
              # but also not likely useful to compile- skip the whole frame
              return None
          if (
              code.co_name == "__init__"
              and code.co_filename.startswith(
                  os.path.dirname(torch.optim.__file__)
              )
          ):
              # optimizer support is still incomplete see
              # test_state_dict in test/dynamo/test_optimizers.py
              return None
  
          # Check if the frame is generated by an exec builtin call
          # TODO - Running exec generated frame seems propagates f_globals to the
          # next frames.
          if (
              code.co_name == "<module>"
              and code.co_filename == "<string>"
          ):
              return None
  
          if (
              code.co_name == "<lambda>"
              and code.co_filename == "<string>"
              and not bool(frame.f_builtins)
          ):
              # namedtuple subclass constructor. Empty builtins cause issue with
              # len keyword in LIST_LEN guard.
              return None
  
          if is_generator(code):
              unimplemented("generator")
          exceeded, limit_type = exceeds_cache_size_limit(cache_size)
          if exceeded:
  
              def format_func_info(code):
                  return f"'{code.co_name}' ({code.co_filename}:{code.co_firstlineno})"
  
              def format_guard_failures():
                  assert (
                      recompile_reasons
                  ), "TODO(whc) any other recompile reasons?"
                  return recompile_reasons[-1]
  
              log.warning(
                  "torch._dynamo hit config.%s (%s)\n"
                  "   function: %s\n"
                  "   last reason: %s\n"
                  'To log all recompilation reasons, use TORCH_LOGS="recompiles".\n'
                  "To diagnose recompilation issues, see %s.",
                  limit_type,
                  getattr(config, limit_type),
                  format_func_info(code),
                  format_guard_failures(),
                  troubleshooting_url,
              )
              unimplemented(f"{limit_type} reached")
  
          if not has_tensor_in_frame(frame):
              return None
  
          global initial_global_state
          initial_global_state = GlobalStateGuard()
  
          global FRAME_COUNTER
          if "_id" not in frame_state:
              frame_state["_id"] = FRAME_COUNTER
              FRAME_COUNTER += 1
          frame_id = frame_state["_id"]
  
          frame_compile_id = FRAME_COMPILE_COUNTER[frame_id]
          FRAME_COMPILE_COUNTER[frame_id] += 1
  
          compile_id = CompileId(frame_id, frame_compile_id)
  
          signpost_event(
              "dynamo",
              "_convert_frame_assert._compile",
              {
                  "co_name": code.co_name,
                  "co_filename": code.co_filename,
                  "co_firstlineno": code.co_firstlineno,
                  "cache_size": cache_size.num_cache_entries_with_same_id_matched_objs,
                  "accumulated_cache_size": cache_size.num_cache_entries,
              },
          )
  
          return _compile(
              frame.f_code,
              frame.f_globals,
              frame.f_locals,
              frame.f_builtins,
              compiler_fn,
              one_graph,
              export,
              export_constraints,
              hooks,
              cache_size,
              frame,
              frame_state=frame_state,
              compile_id=compile_id,
          )
  
      _convert_frame_assert._torchdynamo_orig_callable = compiler_fn  # type: ignore[attr-defined]
  
      def _clone_with_backend(backend):
          return convert_frame_assert(
              backend, one_graph, export, export_constraints
          )
  
      _convert_frame_assert._clone_with_backend = _clone_with_backend  # type: ignore[attr-defined]
      return _convert_frame_assert
  
imports: import collections
  import functools
  import itertools
  import logging
  import os
  import random
  import types
  import typing
  import weakref
  from typing import Any, Callable, Dict, List, Optional, Set
  import torch
  import torch._logging
  from torch._guards import compile_context, CompileContext, CompileId, tracing
  from torch._utils_internal import signpost_event
  from torch.fx.experimental.symbolic_shapes import ConstraintViolationError, GuardOnDataDependentSymNode
  from torch.fx.graph_module import _forward_from_src
  from torch.utils._traceback import format_traceback_short
  from .None import config, exc
  from .backends.registry import CompilerFn
  from .bytecode_analysis import remove_dead_code, remove_pointless_jumps
  from .bytecode_transformation import check_inst_exn_tab_entries_valid, Instruction, is_generator, propagate_inst_exn_table_entries, transform_code_object
  from .cache_size import CacheSizeRelevantForFrame, compute_cache_size, exceeds_cache_size_limit, is_recompilation
  from .eval_frame import always_optimize_code_objects, skip_code, TorchPatcher
  from .exc import augment_exc_message, BackendCompilerFailed, format_error_msg, InternalTorchDynamoError, TorchRuntimeError, UncapturedHigherOrderOpError, unimplemented, Unsupported
  from .guards import CheckFunctionManager, get_and_maybe_log_recompilation_reason, GuardedCode
  from .hooks import Hooks
  from .output_graph import OutputGraph
  from .replay_record import ExecutionRecord
  from .symbolic_convert import InstructionTranslator, SpeculationLog
  from .trace_rules import is_numpy
  from .types import BytecodeHook
  from .utils import CleanupManager, CompilationMetrics, counters, cprofile_wrapper, dynamo_timed, format_bytecode, frame_phase_timing, gen_record_file_name, increment_frame, is_namedtuple, istype, LazyString, orig_code_map, record_compilation_metrics, reset_graph_break_dup_checker, setup_compile_debug, troubleshooting_url, write_record_to_file
  from collections import OrderedDict
  from torch.utils.hooks import RemovableHandle
label_desc: Use image node_id 5 for calling a global function with example usage: convert_frame_assert(compiler_fn, one_graph, export, export_constraints) and returns: _convert_frame_assert, _compile, convert_frame_assert, None, None, None, None, None, None, None, None, str, code, str, code, str, code, str, recompile_reasons