code: def gather_column_features(
      output: Dict[str, Dict],
      column_names: Union[str, List[str]],
  ):
      """
      Gather column features from models' outputs.
      For each feature name in one model's output, we enumerate the provided column names to see
      whether (partial) the provided columns share one cls feature or they have independent features.
  
      TODO: return features' masks and use them to filter the losses.
  
      Parameters
      ----------
      output
          The models' outputs.
      column_names
          The columns whose features we want to get.
  
      Returns
      -------
      The gathered feature vectors. Each sample should only have one feature vector.
      """
      if isinstance(column_names, str):
          column_names = [column_names]
  
      gathered_features = []
      # logger.debug(f"gather features for columns: {column_names}")
      for per_model_name, per_model_output in output.items():
          # logger.debug(f"gather column features from model: {per_model_name}")
          for feature_name in per_model_output[COLUMN_FEATURES][
              FEATURES
          ]:
              # logger.debug(f"processing feature: {feature_name}")
              columns_share_one_feature = []
              for col_name in column_names:
                  if col_name in feature_name:
                      # this column feature is part of the cls feature
                      if not (
                          feature_name.startswith(col_name)
                          and feature_name.endswith(col_name)
                      ):
                          columns_share_one_feature.append(col_name)
                          # logger.debug(f"column {col_name} is included in feature {feature_name}")
                      else:  # this column's feature is independent of other columns'
                          gathered_features.append(
                              per_model_output[COLUMN_FEATURES][
                                  FEATURES
                              ][col_name]
                          )
                          # logger.debug(f"col_name {col_name} has an independent feature in model: {per_model_name}")
  
              # two or more columns share one cls feature, and no other columns share it.
              if len(columns_share_one_feature) > 0:
                  assert len(
                      "_".join(columns_share_one_feature)
                  ) == len(
                      feature_name
                  ), f"model `{per_model_name}`'s cls feature name `{feature_name}` doesn't match `{columns_share_one_feature}`"
                  gathered_features.append(
                      per_model_output[COLUMN_FEATURES][FEATURES][
                          feature_name
                      ]
                  )
  
      if len(gathered_features) > 1:
          # currently only support features of the same shape
          assert all(
              per_features.shape == gathered_features[0].shape
              for per_features in gathered_features
          ), "Currently we only support gathering features of the same dimension."
  
      if len(gathered_features) == 0:
          raise ValueError(
              f"No features are found for columns names {column_names}."
          )
  
      gathered_features = torch.stack(gathered_features, dim=0).mean(
          dim=0
      )  # (b, d)
  
      return gathered_features
  
imports: import functools
  import logging
  import re
  import warnings
  from typing import Any, Dict, List, Optional, Tuple, Union
  import torch
  import torchmetrics
  from omegaconf import DictConfig, OmegaConf
  from packaging import version
  from pytorch_metric_learning import distances, losses, miners
  from torch import nn, optim
  from torch.nn import functional
  from torchmetrics.detection.mean_ap import MeanAveragePrecision
  from transformers import Adafactor
  from transformers.models.mask2former.modeling_mask2former import Mask2FormerConfig, Mask2FormerLoss
  from transformers.trainer_pt_utils import get_parameter_names
  from ..constants import ACC, ACCURACY, AVERAGE_PRECISION, BER, BINARY, BIT_FIT, COLUMN_FEATURES, CONTRASTIVE_LOSS, COSINE_EMBEDDING_LOSS, COSINE_SIMILARITY, CROSS_ENTROPY, DETECTION_METRICS, DIRECT_LOSS, EM, F1, F1_MACRO, F1_MICRO, F1_WEIGHTED, FEATURES, FEW_SHOT_CLASSIFICATION, FM, HIT_RATE, IA3, IA3_BIAS, IA3_LORA, IA3_LORA_BIAS, IA3_LORA_NORM, IA3_NORM, IOU, LOG_LOSS, LORA, LORA_BIAS, LORA_NORM, MAE, MULTI_NEGATIVES_SOFTMAX_LOSS, MULTICLASS, NER, NER_TOKEN_F1, NORM_FIT, OBJECT_DETECTION, OPEN_VOCABULARY_OBJECT_DETECTION, OVERALL_ACCURACY, PAIR_MARGIN_MINER, PEARSONR, PEFT_STRATEGIES, QUADRATIC_KAPPA, R2, RECALL, REGRESSION, RMSE, ROC_AUC, ROOT_MEAN_SQUARED_ERROR, SEMANTIC_SEGMENTATION, SM, SPEARMANR
  from .losses import BBCEWithLogitLoss, FocalLoss, MultiNegativesSoftmaxLoss, SoftTargetCrossEntropy, StructureLoss
  from .lr_scheduler import get_cosine_schedule_with_warmup, get_linear_schedule_with_warmup, get_polynomial_decay_schedule_with_warmup
  from .semantic_seg_metrics import COD_METRICS_NAMES, Balanced_Error_Rate, Binary_IoU, Multiclass_IoU
label_desc: Use image node_id 13 for calling a global function with example usage: gather_column_features(output, column_names) and returns: gathered_features