code: def fast_nms(
      multi_bboxes: Tensor,
      multi_scores: Tensor,
      multi_coeffs: Tensor,
      score_thr: float,
      iou_thr: float,
      top_k: int,
      max_num: int = -1,
  ) -> Union[Tuple[Tensor, Tensor, Tensor], Tuple[Tensor, Tensor]]:
      """Fast NMS in `YOLACT <https://arxiv.org/abs/1904.02689>`_.
  
      Fast NMS allows already-removed detections to suppress other detections so
      that every instance can be decided to be kept or discarded in parallel,
      which is not possible in traditional NMS. This relaxation allows us to
      implement Fast NMS entirely in standard GPU-accelerated matrix operations.
  
      Args:
          multi_bboxes (Tensor): shape (n, #class*4) or (n, 4)
          multi_scores (Tensor): shape (n, #class+1), where the last column
              contains scores of the background class, but this will be ignored.
          multi_coeffs (Tensor): shape (n, #class*coeffs_dim).
          score_thr (float): bbox threshold, bboxes with scores lower than it
              will not be considered.
          iou_thr (float): IoU threshold to be considered as conflicted.
          top_k (int): if there are more than top_k bboxes before NMS,
              only top top_k will be kept.
          max_num (int): if there are more than max_num bboxes after NMS,
              only top max_num will be kept. If -1, keep all the bboxes.
              Default: -1.
  
      Returns:
          Union[Tuple[Tensor, Tensor, Tensor], Tuple[Tensor, Tensor]]:
              (dets, labels, coefficients), tensors of shape (k, 5), (k, 1),
              and (k, coeffs_dim). Dets are boxes with scores.
              Labels are 0-based.
      """
  
      scores = multi_scores[:, :-1].t()  # [#class, n]
      scores, idx = scores.sort(1, descending=True)
  
      idx = idx[:, :top_k].contiguous()
      scores = scores[:, :top_k]  # [#class, topk]
      num_classes, num_dets = idx.size()
      boxes = multi_bboxes[idx.view(-1), :].view(
          num_classes, num_dets, 4
      )
      coeffs = multi_coeffs[idx.view(-1), :].view(
          num_classes, num_dets, -1
      )
  
      iou = bbox_overlaps(boxes, boxes)  # [#class, topk, topk]
      iou.triu_(diagonal=1)
      iou_max, _ = iou.max(dim=1)
  
      # Now just filter out the ones higher than the threshold
      keep = iou_max <= iou_thr
  
      # Second thresholding introduces 0.2 mAP gain at negligible time cost
      keep *= scores > score_thr
  
      # Assign each kept detection to its corresponding class
      classes = torch.arange(num_classes, device=boxes.device)[
          :, None
      ].expand_as(keep)
      classes = classes[keep]
  
      boxes = boxes[keep]
      coeffs = coeffs[keep]
      scores = scores[keep]
  
      # Only keep the top max_num highest scores across all classes
      scores, idx = scores.sort(0, descending=True)
      if max_num > 0:
          idx = idx[:max_num]
          scores = scores[:max_num]
  
      classes = classes[idx]
      boxes = boxes[idx]
      coeffs = coeffs[idx]
  
      cls_dets = torch.cat([boxes, scores[:, None]], dim=1)
      return cls_dets, classes, coeffs
  
file_path: mmdetection/mmdet/models/layers/bbox_nms.py
imports: from typing import Optional, Tuple, Union
  import torch
  from mmcv.ops.nms import batched_nms
  from torch import Tensor
  from mmdet.structures.bbox import bbox_overlaps
  from mmdet.utils import ConfigType
label_desc: Use image node_id 2 for calling a global function with example usage: fast_nms(multi_bboxes, multi_scores, multi_coeffs, score_thr, iou_thr, top_k, max_num) and returns: cls_dets,  classes,  coeffs