code: def freeze(
      dynamo_gm: torch.fx.GraphModule,
      aot_autograd_gm: torch.fx.GraphModule,
      example_inputs: List[torch._subclasses.FakeTensor],
  ) -> Tuple[torch.fx.GraphModule, List[int]]:
      """
      Inlines parameters that are not mutated into constants and optimizes the graph through constant propagation
      and other techniques. If enabled, the function also discards the original parameters of the module for memory efficiency.
  
      Assumes that this function is run in dynamo tracing post aot_autograd.
  
      Args:
          dynamo_gm (torch.fx.GraphModule): The Dynamo constructed GraphModule.
          aot_autograd_gm (torch.fx.GraphModule): The aot_autograd constructed GraphModule to be frozen.
          example_inputs (List[torch.Tensor]): A list of example input tensors to be used in the freezing process.
  
      Returns:
          Tuple[torch.fx.GraphModule, List[int]]: A tuple containing the frozen GraphModule and a list of indices
          of the inputs that were preserved (not turned into constants).
      """
      # We have convert conv's weight to channels last which may meet error for .view
      # when doing fake_tensor_prop. So we need to convert view to reshape first.
      # See the details in fx_codegen_and_compile of compile_fx.py.
      view_to_reshape(aot_autograd_gm)
  
      if tracing_context := torch._guards.TracingContext.try_get():
          fw_metadata = tracing_context.fw_metadata
          params_flat = tracing_context.params_flat
          assert fw_metadata is not None and params_flat is not None
  
          preserved_arg_indices = replace_params_with_constants(
              aot_autograd_gm, params_flat, fw_metadata
          )
      else:
          inputs = [
              node
              for node in aot_autograd_gm.graph.nodes
              if node.op == "placeholder"
          ]
          preserved_arg_indices = list(range(len(inputs)))
  
      # TODO - further restrict cse ? right now needed to dedup aliasing ops
      cse_graph = fx_graph_cse(aot_autograd_gm.graph)
      aot_autograd_gm.graph = cse_graph
      aot_autograd_gm.recompile()
  
      aot_example_inputs = [
          example_inputs[ind] for ind in preserved_arg_indices
      ]
      freezing_passes(aot_autograd_gm, aot_example_inputs)
  
      constant_fold(aot_autograd_gm)
      # invalidate nn Modules
      if config.freezing_discard_parameters:
          invalidate_eager_modules()
          discard_traced_gm_params(dynamo_gm)
  
      log.debug(
          "%s", lazy_format_graph_code("FROZEN GRAPH", aot_autograd_gm)
      )
  
      return aot_autograd_gm, preserved_arg_indices
  
imports: from __future__ import annotations
  import itertools
  import logging
  import weakref
  from typing import Any, List, Optional, Tuple
  import torch
  import torch.utils._pytree
  from torch._dynamo.utils import dynamo_timed, lazy_format_graph_code
  from torch._functorch.aot_autograd import MutationType
  from torch._functorch.compile_utils import fx_graph_cse
  from torch._inductor.constant_folding import constant_fold, replace_node_with_constant
  from torch._inductor.fx_passes.freezing_patterns import freezing_passes
  from torch._inductor.fx_passes.post_grad import view_to_reshape
  from .None import config
label_desc: Use image node_id 2 for calling a global function with example usage: freeze(dynamo_gm, aot_autograd_gm, example_inputs) and returns: aot_autograd_gm,  preserved_arg_indices