code: def _compute_auc_helper(
      predictions: torch.Tensor,
      labels: torch.Tensor,
      weights: torch.Tensor,
      apply_bin: bool = False,
  ) -> torch.Tensor:
      sorted_indices = torch.argsort(
          predictions, descending=True, dim=-1
      )
      sorted_labels = torch.index_select(
          labels, dim=0, index=sorted_indices
      )
      if apply_bin:
          # TODO - [add flag to set bining dyamically] for use with soft labels, >=0.039 --> 1, <0.039 --> 0
          sorted_labels = torch.ge(sorted_labels, 0.039).to(
              dtype=sorted_labels.dtype
          )
      sorted_weights = torch.index_select(
          weights, dim=0, index=sorted_indices
      )
      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: from functools import partial
  from typing import Any, cast, Dict, List, Optional, Type
  import torch
  import torch.distributed
  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 1 for calling a global function with example usage: _compute_auc_helper(predictions, labels, weights, apply_bin) and returns: auc