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)
code: def __init__(
      self,
      temperature: float = 0.1,
      weight_fn: Optional[Callable[[Tensor, Tensor], Tensor]] = None,
      gather_distributed: bool = False,
  ):
      super().__init__()
      self.temperature = temperature
      self.weight_fn = weight_fn
      self.gather_distributed = gather_distributed
  
      if gather_distributed and not torch_dist.is_available():
          raise ValueError(
              "gather_distributed is True but torch.distributed is not available. "
              "Please set gather_distributed=False or install a torch version with "
              "distributed support."
          )
  
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 1 to create a new DCLLoss object from inherited base classes: nn with example: obj = DCLLoss(temperature, weight_fn, gather_distributed)