code: def assign_encoder_layer_ids(
      encoder_names: List[List[str]],
  ):
      """
      Assign ids to encoder layers. The encoder may contain several blocks e.g., block1 and block2.
      This function iterates through all the layers of each block from the input end towards the output end.
      It increases 1 on the layer id when the detected digit in a layer name changes.
  
      Parameters
      ----------
      encoder_names
          Encoder layer names.
  
      Returns
      -------
      name_to_id
          The encoder layer-to-id mapping.
      encoder_layer_num
          The encoder layer number.
      """
      name_to_id = {}
      cur_id = 0
      for i, group_names in enumerate(encoder_names):
          last_inferred_id = -1
          for n in group_names:
              detect_id = False
              n_splits = n.split(".")
  
              for split in n_splits:
                  # the first digit encountered is used to infer layer id
                  if split.isdigit():
                      inferred_id = int(split)
                      # increase at most 1 one time
                      if inferred_id != last_inferred_id:
                          cur_id += 1  # layer.0 -> layer_id 1
                          last_inferred_id = inferred_id
  
                      name_to_id[n] = cur_id
                      detect_id = True
                      break
  
              if detect_id is False:
                  raise ValueError(
                      f"parameter name: {n} not has no id inside"
                  )
  
      if len(name_to_id) > 0:
          encoder_layer_num = max(name_to_id.values())
      else:
          encoder_layer_num = 0
      return name_to_id, encoder_layer_num
  
imports: import logging
  import re
  import warnings
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch._dynamo
  import torch.nn.functional
  from torch import nn
  from torch.nn.modules.loss import _Loss
  from transformers import AutoConfig, AutoModel, AutoTokenizer, BertTokenizer, CLIPTokenizer, ElectraTokenizer
  from transformers.models.mask2former.modeling_mask2former import Mask2FormerLoss
  from ..constants import AUTOMM, CLASS_LOGITS, COLUMN_FEATURES, FEATURES, LOGITS, MASKS, OCR, PEFT_ADDITIVE_STRATEGIES, REGRESSION, SEMANTIC_MASK, SEMANTIC_SEGMENTATION
  from .adaptation_layers import IA3Linear, IA3LoRALinear, LoRALinear
label_desc: Use image node_id 2 for calling a global function with example usage: assign_encoder_layer_ids(encoder_names) and returns: name_to_id,  encoder_layer_num