class_docstr: Support SAM for semantic segmentation.
  Refer to https://huggingface.co/docs/transformers/main/model_doc/sam
docstr: Assign an id to each layer. Layer ids will be used in layer-wise lr decay.
  Basically, id gradually increases when going from the output end to
  the input end. The layers defined in this class, e.g., head, have id 0.
  
  In the AutoModel scenario, this function may not always return the correct result.
  Thus, you can use "print(json.dumps(name_to_id, indent=2))" to manually check whether
  the layer ids are reasonable.
  
  Returns
  -------
  A dictionary mapping the layer names (keys) to their ids (values).
docstr_tok: ["Assign","an","id","to","each","layer",".","Layer","ids","will","be","used","in","layer-wise","lr","decay",".","Basically",",","id","gradually","increases","when","going","from","the","output","end","to","the","input","end",".","The","layers","defined","in","this","class",",","e.g.",",","head",",","have","id","0",".","In","the","AutoModel","scenario",",","this","function","may","not","always","return","the","correct","result",".","Thus",",","you","can","use","``","print","(","json.dumps","(","name_to_id",",","indent=2",")",")","''","to","manually","check","whether","the","layer","ids","are","reasonable",".","Returns","--","--","--","-","A","dictionary","mapping","the","layer","names","(","keys",")","to","their","ids","(","values",")","."]
code: def get_layer_ids(self):
      """
      Assign an id to each layer. Layer ids will be used in layer-wise lr decay.
      Basically, id gradually increases when going from the output end to
      the input end. The layers defined in this class, e.g., head, have id 0.
  
      In the AutoModel scenario, this function may not always return the correct result.
      Thus, you can use "print(json.dumps(name_to_id, indent=2))" to manually check whether
      the layer ids are reasonable.
  
      Returns
      -------
      A dictionary mapping the layer names (keys) to their ids (values).
      """
      model_prefix = "model"
      pre_encoder_patterns = (
          "vision_encoder",
          "prompt_encoder",
      )
      post_encoder_patterns = ("mask_decoder",)
  
      names = [n for n, _ in self.named_parameters()]
  
      name_to_id, names = assign_layer_ids(
          names=names,
          pre_encoder_patterns=pre_encoder_patterns,
          post_encoder_patterns=post_encoder_patterns,
          model_pre=model_prefix,
      )
      if len(names) > 0:
          logger.debug(f"outer layers are treated as head: {names}")
      for n in names:
          assert n not in name_to_id
          name_to_id[n] = 0
  
      return name_to_id
  
imports: import logging
  import os
  import time
  import warnings
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from omegaconf import DictConfig
  from torch import nn
  from transformers import SamConfig, SamModel
  from transformers.models.sam.modeling_sam import SamImageSegmentationOutput
  from ..constants import CLASS_LABEL, CLASS_LOGITS, COLUMN, IMAGE, IMAGE_VALID_NUM, LABEL, LOGITS, MASK_LABEL
  from .utils import assign_layer_ids, freeze_model_layers
label_desc: Use image node_id 12 for calling the SAMForSemanticSegmentation obj's underlying member method code with example usage: obj.get_layer_ids() and returns: name_to_id