code: def _compute_auprc_helper(
      predictions: torch.Tensor,
      labels: torch.Tensor,
      weights: torch.Tensor,
  ) -> torch.Tensor:
      sorted_indices = torch.argsort(
          predictions, descending=True, dim=-1
      )
  
      threshold = torch.index_select(
          predictions, dim=0, index=sorted_indices
      )
  
      sorted_labels = torch.index_select(
          labels, dim=0, index=sorted_indices
      )
  
      sorted_weights = torch.index_select(
          weights, dim=0, index=sorted_indices
      )
  
      mask = F.pad(threshold.diff(dim=0) != 0, [0, 1], value=1.0)
      num_tp = torch.cumsum(sorted_weights * sorted_labels, dim=0)[mask]
      num_fp = torch.cumsum(
          sorted_weights * (1.0 - sorted_labels), dim=0
      )[mask]
  
      precision = (num_tp / (num_tp + num_fp)).flip(0)
      recall = (num_tp / num_tp[-1]).flip(0)
  
      # The last precision and recall values are 1.0 and 0.0 without a corresponding threshold.
      # This ensures that the graph starts on the y-axis.
      precision = torch.cat([precision, precision.new_ones(1)])
      recall = torch.cat([recall, recall.new_zeros(1)])
  
      # If recalls are NaNs, set NaNs to 1.0s.
      if torch.isnan(recall[0]):
          recall = torch.nan_to_num(recall, 1.0)
  
      auprc = _riemann_integral(recall, precision)
      return auprc
  
imports: from functools import partial
  from typing import Any, cast, Dict, List, Optional, Type
  import torch
  import torch.distributed
  import torch.nn.functional
  from torchrec.metrics.metrics_config import RecComputeMode, RecTaskInfo
  from torchrec.metrics.metrics_namespace import MetricName, MetricNamespace, MetricPrefix
  from torchrec.metrics.rec_metric import MetricComputationReport, RecMetric, RecMetricComputation, RecMetricException
label_desc: Use image node_id 2 for calling a global function with example usage: _compute_auprc_helper(predictions, labels, weights) and returns: auprc