code: def layerwise_lr_decay(decay_rate, name_dict, n_layers, param):
      """
      Args:
          decay_rate (float):
              The layer-wise decay ratio.
          name_dict (dict):
              The keys of name_dict is dynamic name of model while the value
              of name_dict is static name.
              Use model.named_parameters() to get name_dict.
          n_layers (int):
              Total number of layers in the transformer encoder.
      """
      ratio = 1.0
      static_name = name_dict[param.name]
      if "blocks" in static_name:
          idx = static_name.find("blocks.")
          layer = int(static_name[idx:].split(".")[1])
          ratio = decay_rate ** (n_layers - layer)
      elif "embed" in static_name:
          ratio = decay_rate ** (n_layers + 1)
      param.optimize_attr["learning_rate"] *= ratio
  
file_path: PaddleSeg/paddleseg/optimizers/custom_optimizers.py
imports: import math
  import numpy
  from functools import partial
  import paddle
  from paddle.optimizer import AdamW
label_desc: Use image node_id 1 for calling a global function with example usage: layerwise_lr_decay(decay_rate, name_dict, n_layers, param) without return types