class_docstr: Implementation of the Decoupled Contrastive Learning Loss from
  Decoupled Contrastive Learning [0].
  
  This code implements Equation 6 in [0], including the sum over all images `i`
  and views `k`. The loss is reduced to a mean loss over the mini-batch.
  The implementation was inspired by [1].
  
  - [0] Chun-Hsiao Y. et. al., 2021, Decoupled Contrastive Learning https://arxiv.org/abs/2110.06848
  - [1] https://github.com/raminnakhli/Decoupled-Contrastive-Learning
  
  Attributes:
      temperature:
          Similarities are scaled by inverse temperature.
      weight_fn:
          Weighting function `w` from the paper. Scales the loss between the
          positive views (views from the same image). No weighting is performed
          if weight_fn is None. The function must take the two input tensors
          passed to the forward call as input and return a weight tensor. The
          returned weight tensor must have the same length as the input tensors.
      gather_distributed:
          If True then negatives from all gpus are gathered before the
          loss calculation.
  
  Examples:
  
      >>> loss_fn = DCLLoss(temperature=0.07)
      >>>
      >>> # generate two random transforms of images
      >>> t0 = transforms(images)
      >>> t1 = transforms(images)
      >>>
      >>> # embed images using some model, for example SimCLR
      >>> out0 = model(t0)
      >>> out1 = model(t1)
      >>>
      >>> # calculate loss
      >>> loss = loss_fn(out0, out1)
      >>>
      >>> # you can also add a custom weighting function
      >>> weight_fn = lambda out0, out1: torch.sum((out0 - out1) ** 2, dim=1)
      >>> loss_fn = DCLLoss(weight_fn=weight_fn)
docstr: Forward pass of the DCL loss.
  
  Args:
      out0:
          Output projections of the first set of transformed images.
          Shape: (batch_size, embedding_size)
      out1:
          Output projections of the second set of transformed images.
          Shape: (batch_size, embedding_size)
  
  Returns:
      Mean loss over the mini-batch.
docstr_tok: ["Forward","pass","of","the","DCL","loss",".","Args",":","out0",":","Output","projections","of","the","first","set","of","transformed","images",".","Shape",":","(","batch_size",",","embedding_size",")","out1",":","Output","projections","of","the","second","set","of","transformed","images",".","Shape",":","(","batch_size",",","embedding_size",")","Returns",":","Mean","loss","over","the","mini-batch","."]
code: def forward(
      self,
      out0: Tensor,
      out1: Tensor,
  ) -> Tensor:
      """Forward pass of the DCL loss.
  
      Args:
          out0:
              Output projections of the first set of transformed images.
              Shape: (batch_size, embedding_size)
          out1:
              Output projections of the second set of transformed images.
              Shape: (batch_size, embedding_size)
  
      Returns:
          Mean loss over the mini-batch.
      """
      # normalize the output to length 1
      out0 = nn.functional.normalize(out0, dim=1)
      out1 = nn.functional.normalize(out1, dim=1)
  
      if self.gather_distributed and dist.world_size() > 1:
          # gather representations from other processes if necessary
          out0_all = torch.cat(dist.gather(out0), 0)
          out1_all = torch.cat(dist.gather(out1), 0)
      else:
          out0_all = out0
          out1_all = out1
  
      # calculate symmetric loss
      loss0 = self._loss(out0, out1, out0_all, out1_all)
      loss1 = self._loss(out1, out0, out1_all, out0_all)
      return 0.5 * (loss0 + loss1)
  
file_path: lightly/lightly/loss/dcl_loss.py
imports: from functools import partial
  from typing import Callable, Optional
  import torch
  from torch import Tensor
  from torch import distributed
  from torch import nn
  from lightly.utils import dist
label_desc: Use image node_id 2 for calling the DCLLoss obj's underlying member method code with example usage: obj.forward(out0, out1) and returns: unknown