class_docstr: This class defines a custom loss function for log confidence.
  
  Attributes:
  aux_coef: A float indicating the auxiliary coefficient.
  warmup_frac: A float indicating the fraction of total training steps for warmup.
class_docstr_tok: ["This","class","defines","a","custom","loss","function","for","log","confidence",".","Attributes",":","aux_coef",":","A","float","indicating","the","auxiliary","coefficient",".","warmup_frac",":","A","float","indicating","the","fraction","of","total","training","steps","for","warmup","."]
code: def __call__(
      self,
      logits: torch.Tensor,
      labels: torch.Tensor,
      step_frac: float,
  ) -> torch.Tensor:
      logits = logits.float()
      labels = labels.float()
      coef = 1.0 if step_frac > self.warmup_frac else step_frac
      coef = coef * self.aux_coef
      preds = torch.softmax(logits, dim=-1)
      mean_weak = torch.mean(labels, dim=0)
      assert mean_weak.shape == (2,)
      threshold = torch.quantile(preds[:, 0], mean_weak[1])
      strong_preds = torch.cat(
          [
              (preds[:, 0] >= threshold)[:, None],
              (preds[:, 0] < threshold)[:, None],
          ],
          dim=1,
      )
      target = labels * (1 - coef) + strong_preds.detach() * coef
      loss = torch.nn.functional.cross_entropy(
          logits, target, reduction="none"
      )
      return loss.mean()
  
file_path: weak-to-strong/weak_to_strong/loss.py
imports: import torch
label_desc: Use image node_id 2 for calling the logconf_loss_fn obj's underlying member method code with example usage: obj.__call__(logits, labels, step_frac) and returns: loss