code: def run_reducer(
      pre_embs: torch.Tensor,
      target_spk_idx: int,
      merge_quantity: int,
      pre_clus_labels: torch.Tensor,
  ):
      """
      Reduce the number of embedding vectors by merging the closest embedding vectors.
          - This merging algorithm is based on the assumption that the closest embeddings
            are the most redundant embedding vectors.
          - The closest embedding vectors are chosen by selecting the highest top-N sum of
            each column in a given affinity matrix.
          - If merge_quantity is N, we choose (N+1) vectors into 1 embedding vector.
            Thus, we reduce N embeddings in the original embedding vector set.
  
      Example:
          >>> merge_quantity = 1 # We merge 1+1 = 2 embedding vectors
          >>> affinity_mat = [[1.0, 0.2, 0.8],
                              [0.2, 1.0, 0.4],
                              [0.8, 0.4, 1.0]]
          >>> affinity_mat.sum(0)
          [2.0, 1.6, 2.2]
  
          The first and the third embedding vectors are merged into one embedding vector.
          >>> index_mapping # (bypassed indices, merged indices)
          ([1], [0, 2])
  
      Args:
          pre_embs (Tensor):
              Potential Embedding vectors to be merged
          affinity_mat (Tensor):
              The affinity matrix of the `pre_embs`
          target_spk_idx (int):
              The targeted speaker index for merging
          merge_quantity (int):
              The count of embeddings to be reduced
          pre_clus_labels (list)
              The original cluster (speaker) index
  
      Returns:
          merged_embs (torch.Tensor):
              The merged embedding vectors.
          merged_clus_labels (torch.Tensor):
              The cluster (speaker) indices for the merged embedding vectors.
          index_mapping (Tuple[torch.Tensor, torch.Tensor]):
              A tuple containing the indices of the original embeddings that were not merged (`bypassed indices`)
              and the indices of the new merged embeddings (`merged indices`).
      """
      if pre_embs.shape[0] != pre_clus_labels.shape[0]:
          raise ValueError(
              "Dimension mismatch between `pre_embs` and `pre_clus_labels`."
          )
  
      target_emb_index = torch.where(pre_clus_labels == target_spk_idx)[
          0
      ]
      org_size = target_emb_index.shape[0]
      if merge_quantity > 0:
          if merge_quantity > (target_emb_index.shape[0] - 1):
              raise ValueError(
                  f"merge_quantity {merge_quantity} should not be larger than target_emb_index length: {target_emb_index.shape[0]-1}"
              )
          total_affinity_mat = getCosAffinityMatrix(pre_embs)
  
          # Get the lower triangle of the affinity_mat array
          affinity_mat = total_affinity_mat[:, target_emb_index][
              target_emb_index, :
          ]
          if affinity_mat.shape[0] != target_emb_index.shape[0]:
              raise ValueError(
                  "Dimension mismatch between targeted speaker affinity `affinity_mat` and targeted speaker index `target_emb_index`."
              )
          # Get the indices of the closest embedding vectors
          selected_inds, rest_inds = get_closest_embeddings(
              affinity_mat, merge_quantity
          )
          spk_cluster_labels, selected_embs = (
              pre_clus_labels[target_emb_index],
              pre_embs[target_emb_index],
          )
  
          # Note that we need to return the indices of speaker-specific indices from `target_emb_index`.
          index_mapping = (
              target_emb_index[rest_inds.sort()[0]],
              target_emb_index[selected_inds],
          )
  
          # Merge the embeddings targeted by the 2-dim indices `index_2d`
          merged_embs, merged_clus_labels = merge_vectors(
              selected_inds, selected_embs, spk_cluster_labels
          )
  
          if (org_size - merge_quantity) != merged_embs.shape[0]:
              raise ValueError(
                  f"Reducer output {merged_embs.shape[0]} is not matched to the target quantity {org_size - merge_quantity}."
              )
  
      else:
          merged_embs = pre_embs[target_emb_index]
          merged_clus_labels = pre_clus_labels[target_emb_index]
          index_mapping = (target_emb_index, torch.arange(0))
      return merged_embs, merged_clus_labels, index_mapping
  
imports: from typing import List, Tuple
  import torch
  from nemo.collections.asr.parts.utils.offline_clustering import NMESC, SpeakerClustering, SpectralClustering, get_scale_interpolated_embs, getAffinityGraphMat, getCosAffinityMatrix, split_input_data
  from nemo.collections.asr.parts.utils.optimization_utils import linear_sum_assignment
label_desc: Use image node_id 8 for calling a global function with example usage: run_reducer(pre_embs, target_spk_idx, merge_quantity, pre_clus_labels) and returns: merged_embs,  merged_clus_labels,  index_mapping