code: def recursive_freeze(
      module: nn.Module,
      sample: Dict[str, Any],
      include_root: bool = True,
  ) -> Tuple[nn.Module, bool]:
      """Recursively freeze all the mutables in a module.
      The sample is a dictionary of parameters.
  
      If ``include_root`` is true, it will call ``module.freeze(sample)`` if module is a mutable by itself.
  
      Returns
      -------
      A tuple of (frozen_module, replaced).
      If replaced is true, the child module has been replaced.
      """
      if include_root and isinstance(module, Mutable):
          return module.freeze(sample), True
  
      # Examine all the children.
      replaced_dict = {}
      for name, child_module in module.named_children():
          if isinstance(child_module, Mutable):
              new_module, replaced = child_module.freeze(sample), True
          else:
              new_module, replaced = recursive_freeze(
                  child_module, sample
              )
          if replaced:
              replaced_dict[name] = new_module
  
      # If some children is replaced.
      if replaced_dict:
          module = copy.deepcopy(module)
          for name, new_module in replaced_dict.items():
              setattr(module, name, new_module)
          return module, True
      return module, False
  
imports: import copy
  import itertools
  import inspect
  import logging
  from typing import Any, Callable, Type, Iterable, Dict, Tuple, List, Optional, TypeVar
  import torch
  from torch import nn
  from nni.mutable import Mutable, LabeledMutable, Sample, SampleValidationError, ensure_frozen, frozen_context, label_scope, frozen
  from nni.nas.space import BaseModelSpace, current_model, model_context
  from nni.common.serializer import SerializableObject, _formulate_arguments, _copy_class_wrapper_attributes
label_desc: Use image node_id 1 for calling a global function with example usage: recursive_freeze(module, sample, include_root) and returns: module,  False, module,  True, module,  True