code: def generate_metric_learning_labels(
      num_samples: int,
      match_label: int,
      labels: torch.Tensor,
  ):
      """
      Generate labels to compute the metric learning loss of one mini-batch.
      For n samples, it generates 2*n labels since each match has two sides, each of which
      has one label. If we know the matching label, then it determines the two sides' labels
      according to whether their label is the matching label. If the matching label is None,
      it assigns a unique label for each side.
  
      Parameters
      ----------
      num_samples
          number of samples.
      match_label
          The matching label, which can be None.
      labels
          The sample labels used in the supervised setting. It's required only when match_label is not None.
  
      Returns
      -------
      The labels used in computing the metric learning loss.
      """
      device = labels.device
      labels_1 = torch.arange(num_samples, device=device)
  
      if match_label is not None:
          labels_2 = torch.arange(
              num_samples, num_samples * 2, device=device
          )
          # users need to specify the match_label based on the raw label's semantic meaning.
          mask = labels == match_label
          labels_2[mask] = labels_1[mask]
      else:
          labels_2 = torch.arange(num_samples, device=device)
  
      metric_learning_labels = torch.cat([labels_1, labels_2], dim=0)
  
      return metric_learning_labels
  
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 18 for calling a global function with example usage: generate_metric_learning_labels(num_samples, match_label, labels) and returns: metric_learning_labels