code: def compute_auc(
      predictions: torch.Tensor,
      labels: torch.Tensor,
      weights: torch.Tensor,
  ) -> torch.Tensor:
      _, sorted_index = torch.sort(predictions, descending=True)
      sorted_labels = torch.index_select(
          labels, dim=0, index=sorted_index
      )
      sorted_weights = torch.index_select(
          weights, dim=0, index=sorted_index
      )
      cum_fp = torch.cumsum(
          sorted_weights * (1.0 - sorted_labels), dim=0
      )
      cum_tp = torch.cumsum(sorted_weights * sorted_labels, dim=0)
      auc = torch.where(
          cum_fp[-1] * cum_tp[-1] == 0,
          0.5,  # 0.5 is the no-signal default value for auc.
          torch.trapz(cum_tp, cum_fp) / cum_fp[-1] / cum_tp[-1],
      )
      return auc
  
imports: import unittest
  from typing import Dict, Iterable, List, Optional, Type, Union
  import torch
  from torch import no_grad
  from torchrec.metrics.auc import AUCMetric
  from torchrec.metrics.metrics_config import DefaultTaskInfo
  from torchrec.metrics.rec_metric import RecComputeMode, RecMetric, RecMetricException, RecTaskInfo
  from torchrec.metrics.test_utils import metric_test_helper, rec_metric_value_test_launcher, TestMetric
label_desc: Use image node_id 1 for calling a global function with example usage: compute_auc(predictions, labels, weights) and returns: auc