code: def group_param_names(
      names: List[str],
      pre_encoder_patterns: Tuple[str, ...],
      post_encoder_patterns: Tuple[str, ...],
      model_prefix: Optional[str] = None,
  ):
      """
      Group layer names into three types: pre-encoder, encoder, and post-encoder.
      If "model_prefix" is provided, the selected layer names must start with it.
      In this case, the left names will be returned for the next-time processing.
      This function first extracts the first-level children modules' names and
      classify them into encoder and non-encoder layers. Note that an encoder may
      consist of several manually named children modules, e.g., block1 and block2.
      The non-encoder layers are further subdivided into pre-encoder and post-encoder.
  
      Parameters
      ----------
      names
          Model layer names
      pre_encoder_patterns
          Patterns to identify a layer as a pre-encoder layer. If a layer name contains one pattern,
          the layer will be grouped into pre-encoder layers.
      post_encoder_patterns
          Patterns to identify a layer as a post-encoder layer. If a layer name contains one pattern,
          the layer will be grouped into post-encoder layers.
      model_prefix
          A prefix to filter layer names. Only layer names starting with it will be selected.
      Returns
      -------
      left_names
          The layer names left for the next-time processing.
      encoder_names_grouped
          Encoder layer names.
      pre_encoder_names
          Names of layers before the encoder.
      post_encoder_names
          Names of layers after the encoder.
      """
      # two set of patterns can't have intersections
      assert all(
          pre_p not in post_encoder_patterns
          for pre_p in pre_encoder_patterns
      )
  
      left_names = []
      # in case model_prefix is provided, e.g., the clip model with image and text branches
      selected_names = []
      for n in names:
          if model_prefix is not None and not n.startswith(
              model_prefix
          ):
              left_names.append(n)
          else:
              selected_names.append(n)
  
      # split blocks at the first level
      children_prefix = []
      for n in selected_names:
          child_name = n[len(model_prefix) + 1 :].split(".")[0]
          child_prefix = f"{model_prefix}.{child_name}"
          if child_prefix not in children_prefix:
              children_prefix.append(child_prefix)
  
      encoder_names_grouped = []
      non_encoder_names = []
      for child_prefix in children_prefix:
          per_names_group = [
              n for n in selected_names if n.startswith(child_prefix)
          ]
          (
              per_encoder_names,
              per_non_encoder_names,
          ) = split_encoder_non_encoder(
              per_names_group, post_encoder_patterns
          )
          encoder_names_grouped.append(per_encoder_names)
          non_encoder_names.extend(per_non_encoder_names)
  
      pre_encoder_names = []
      post_encoder_names = []
      for n in non_encoder_names:
          if any(p in n for p in pre_encoder_patterns):
              pre_encoder_names.append(n)
          elif any(p in n for p in post_encoder_patterns):
              post_encoder_names.append(n)
          else:
              raise ValueError(
                  f"parameter name: {n} belong to neither pre or post encoder names"
              )
  
      # only process left names in next iteration
      return (
          left_names,
          encoder_names_grouped,
          pre_encoder_names,
          post_encoder_names,
      )
  
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 5 for calling a global function with example usage: group_param_names(names, pre_encoder_patterns, post_encoder_patterns, model_prefix) and returns: left_names,  encoder_names_grouped,  pre_encoder_names,  post_encoder_names