class_docstr: Implementation of T-Few (https://arxiv.org/pdf/2205.05638.pdf).
  Refer to https://github.com/r-three/t-few
class_docstr_tok: ["Implementation","of","T-Few","(","https",":","\/\/arxiv.org\/pdf\/2205.05638.pdf",")",".","Refer","to","https",":","\/\/github.com\/r-three\/t-few"]
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 = (
          "embeddings",
          "LayerNorm",
          "wte",
          "wpe",
          "shared.weight",
          "encoder.conv.conv",
          "dummy_layer",
      )
      post_encoder_patterns = (
          "head",
          "pooler",
          "ln_f",
          "final_layer_norm",
      )
      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] = 1
  
      for (
          name,
          id,
      ) in (
          name_to_id.items()
      ):  # no layer should be assigned zero id as zero id is finetuned
          if id == 0:
              name_to_id[name] = 1
  
      return name_to_id
  
imports: import collections
  import logging
  import os
  import random
  from functools import lru_cache
  from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import nn
  from transformers import AutoConfig, AutoModelForSeq2SeqLM
  from transformers import logging
  from ..constants import AUTOMM, CHOICES_IDS, COLUMN, COLUMN_FEATURES, FEATURES, LABEL, LM_TARGET, LOGITS, MASKS, TEMPLATE_LOGITS, TEXT_SEGMENT_IDS, TEXT_TOKEN_IDS, TEXT_VALID_LENGTH
  from .utils import DummyLayer, assign_layer_ids, get_column_features, get_pretrained_tokenizer
label_desc: Use image node_id 12 for calling the TFewModel obj's underlying member method code with example usage: obj.get_layer_ids() and returns: name_to_id