code: def get_merge_quantity(
      num_to_be_removed: int,
      pre_clus_labels: torch.Tensor,
      min_count_per_cluster: int,
  ) -> torch.Tensor:
      """
      Determine which embeddings we need to reduce or merge in history buffer.
      We want to merge or remove the embedding in the bigger cluster first.
      At the same time, we keep the minimum number of embedding per cluster
      with the variable named min_count_per_cluster.
  
      Constraint:
          - Each cluster should keep the number of vectors over `min_count_per_cluster`.
          - In total, `num_to_be_removed` of vectors should be removed from the total buffer.
          - While merging embeddings, minimize the gap between quantities between clusters.
  
      Example:
          >>> num_to_be_removed = 3
          >>> pre_clus_labels = [0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2]
          >>> min_count_per_cluster = 2
          >>> get_merge_quantity(num_to_be_removed, pre_clus_labels, min_count_per_cluster)
          Return:
              torch.tensor([2, 1, 0])
          >>> # Sum should be equal to `num_to_be_removed` which is 3
  
      Args:
          num_to_be_removed: (int)
              the quantity of the newly obtained embedding from the new stream of input.
          pre_clus_labels: (Tensor)
              the speaker labels of (the history_embedding_buffer_emb) + (the new embeddings to be added)
          min_count_per_cluster: (int)
              Minimum vector quantity for each cluster
  
      Returns:
          removable_counts_mat: (Tensor)
              Tensor containing the number of vectors should be removed from each cluster
      """
      if num_to_be_removed > pre_clus_labels.shape[0] - 1:
          raise ValueError(
              f"num_to_be_removed: {num_to_be_removed} should be less than pre_clus_labels length - 1"
          )
      remain_count = pre_clus_labels.shape[0] - num_to_be_removed
      spk_freq_count = torch.bincount(pre_clus_labels)
      num_clus = len(torch.unique(pre_clus_labels))
      if remain_count < min_count_per_cluster * num_clus:
          raise ValueError(
              f"The remaining embedding vectors should be more than { min_count_per_cluster * num_clus }"
          )
  
      # Minimum vector counts should be excluded from the removable amount
      min_seg_count = torch.tensor(
          [min_count_per_cluster] * len(spk_freq_count)
      ).to(pre_clus_labels.device)
      min_seg_count_mat = torch.stack(
          (min_seg_count, spk_freq_count)
      ).min(0)[0]
  
      # Exclude minimum quantities from the removable count matrix
      remain_count -= int(torch.sum(min_seg_count_mat))
      removable_counts_mat = spk_freq_count - min_seg_count_mat
  
      # Calculate removable counts from `remain_count` variable
      removable_counts_mat = calculate_removable_counts(
          removable_counts_mat, remain_count, num_clus
      )
      if int(removable_counts_mat.sum()) != num_to_be_removed:
          raise ValueError(
              "Sum of `removable_counts_mat` is not equal to `num_to_be_removed` variable."
          )
      if not torch.all(removable_counts_mat >= 0) or not torch.all(
          spk_freq_count - min_seg_count_mat >= 0
      ):
          raise ValueError(
              f"Every value in `removable_counts_mat` should be always non-negative value but got {removable_counts_mat}"
          )
      return removable_counts_mat
  
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 5 for calling a global function with example usage: get_merge_quantity(num_to_be_removed, pre_clus_labels, min_count_per_cluster) and returns: removable_counts_mat