code: def freeze_up_to(
      model: Module,
      freeze_until_layer: Optional[str] = None,
      set_eval_mode: bool = True,
      set_requires_grad_false: bool = True,
      layer_filter: Optional[
          Callable[[LayerAndParameter], bool]
      ] = None,
      module_prefix: str = "",
  ):
      """
      A simple utility that can be used to freeze a model.
  
      :param model: The model.
      :param freeze_until_layer: If not None, the freezing algorithm will continue
          (proceeding from the input towards the output) until the specified layer
          is encountered. The given layer is excluded from the freezing procedure.
      :param set_eval_mode: If True, the frozen layers will be set in eval mode.
          Defaults to True.
      :param set_requires_grad_false: If True, the autograd engine will be
          disabled for frozen parameters. Defaults to True.
      :param layer_filter: A function that, given a :class:`LayerParameter`,
          returns `True` if the parameter must be frozen. If all parameters of
          a layer are frozen, then the layer will be set in eval mode (according
          to the `set_eval_mode` parameter. Defaults to None, which means that all
          parameters will be frozen.
      :param module_prefix: The model prefix. Do not use if non strictly
          necessary.
      :return:
      """
  
      frozen_layers = set()
      frozen_parameters = set()
  
      to_freeze_layers = dict()
      for param_def in get_layers_and_params(
          model, prefix=module_prefix
      ):
          if (
              freeze_until_layer is not None
              and freeze_until_layer == param_def.layer_name
          ):
              break
  
          freeze_param = layer_filter is None or layer_filter(param_def)
          if freeze_param:
              if set_requires_grad_false:
                  param_def.parameter.requires_grad = False
                  frozen_parameters.add(param_def.parameter_name)
  
              if param_def.layer_name not in to_freeze_layers:
                  to_freeze_layers[param_def.layer_name] = (
                      True,
                      param_def.layer,
                  )
          else:
              # Don't freeze this parameter -> do not set eval on the layer
              to_freeze_layers[param_def.layer_name] = (False, None)
  
      if set_eval_mode:
          for layer_name, layer_result in to_freeze_layers.items():
              if layer_result[0]:
                  layer_result[1].eval()
                  frozen_layers.add(layer_name)
  
      return frozen_layers, frozen_parameters
  
imports: from collections import defaultdict
  from typing import Callable, Dict, List, NamedTuple, Optional, Tuple, Union
  import torch
  from torch import Tensor
  from torch.nn import Linear, Module
  from torch.utils.data import DataLoader, Dataset
  from avalanche.benchmarks import OnlineCLExperience
  from avalanche.models.batch_renorm import BatchRenorm2D
label_desc: Use image node_id 16 for calling a global function with example usage: freeze_up_to(model, freeze_until_layer, set_eval_mode, set_requires_grad_false, layer_filter, module_prefix) and returns: frozen_layers,  frozen_parameters