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 or "layers." in static_name:
          idx_1 = static_name.find("blocks.")
          idx_2 = static_name.find("layers.")
          assert any([x >= 0 for x in [idx_1, idx_2]]), ""
          idx = idx_1 if idx_1 >= 0 else idx_2
          # idx = re.findall('[blocks|layers]\.(\d+)\.', static_name)[0]
  
          layer = int(static_name[idx:].split(".")[1])
          ratio = decay_rate ** (n_layers - layer)
  
      elif (
          "cls_token" in static_name
          or "patch_embed" in static_name
          or "pos_embed" in static_name
      ):
          ratio = decay_rate ** (n_layers + 1)
  
      if IS_PADDLE_LATER_2_4:
          return ratio
      else:
          param.optimize_attr["learning_rate"] *= ratio
  
file_path: PaddleDetection/ppdet/optimizer/adamw.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import paddle
  from paddle.optimizer import AdamW
  from functools import partial
  import re
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) and returns: ratio