code: def get_column_features(
      batch: Dict[str, torch.Tensor],
      column_name_prefix: str,
      features: torch.Tensor,
      valid_lengths: torch.Tensor,
      cls_feature: Optional[torch.Tensor] = None,
  ):
      """
      Index the features of one column defined by `column_name_prefix`.
      This function can be used to index both image and text features.
      The features have shape (b, n, d), where n can be the image number or
      text token number. One column corresponds to a subset of
      the n images or text tokens. One column name can only appear once in the return.
  
      Parameters
      ----------
      batch
          The batch input containing the feature column information, i.e., indexes.
      column_name_prefix
          The column name prefix of one modality (image or text).
      features
          The features of columns whose names starts with column_name_prefix.
      valid_lengths
          The valid image number or text token number of each sample in a batch.
      cls_feature
          The cls feature containing information from all feature columns.
  
      Returns
      -------
      The column features with masks. If the column has no valid features, its
      mask is 0.
      """
      column_features = {}
      feature_masks = {}
  
      cut_idx = len(column_name_prefix) + 1
      if cls_feature is not None:
          all_column_names = []
          # create a zero mask to do logical_or with each column's mask
          joint_mask = torch.zeros(features.shape[0]).to(
              features
          )  # (b,)
      for key in batch:
          if key.startswith(column_name_prefix):
              per_col_features = []
              per_col_masks = torch.zeros(features.shape[0]).to(
                  features
              )  # (b,)
              assert batch[key].ndim == 2 and batch[key].shape[1] == 2
              for i, per_sample_col_idx in enumerate(batch[key]):
                  start_idx = per_sample_col_idx[0]
                  end_idx = per_sample_col_idx[1]
                  if start_idx < end_idx:
                      assert end_idx <= valid_lengths[i]
                      per_col_features.append(
                          features[i, start_idx:end_idx].mean(dim=0)
                      )
                      per_col_masks[i] = 1
                  else:  # the column has no valid image/text.
                      per_col_features.append(
                          torch.zeros_like(features[0, 0])
                      )
                      per_col_masks[i] = 0
              column_name = key[cut_idx:]
              column_features[column_name] = torch.stack(
                  per_col_features, dim=0
              )  # (b, num_features)
              feature_masks[column_name] = per_col_masks  # (b,)
              if cls_feature is not None:
                  all_column_names.append(column_name)
                  joint_mask = torch.logical_or(
                      joint_mask, per_col_masks
                  )
  
      # all the columns of one model's input share the model's cls feature
      if (
          cls_feature is not None and len(all_column_names) > 0
      ):  # some models', e.g, timm_image, output doesn't have the cls feature.
          # remove the individual column features since these column features not independent
          for column_name in all_column_names:
              column_features.pop(column_name)
              feature_masks.pop(column_name)
  
          joint_column_name = "_".join(all_column_names)
          column_features[joint_column_name] = cls_feature
          feature_masks[joint_column_name] = joint_mask.to(features)
  
      # print(f"column_features: {column_features}")
      return column_features, feature_masks
  
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 8 for calling a global function with example usage: get_column_features(batch, column_name_prefix, features, valid_lengths, cls_feature) and returns: column_features,  feature_masks