class_docstr: Implementation of the loss function from MSN [0].
  
  Code inspired by [1].
  
  - [0]: Masked Siamese Networks, 2022, https://arxiv.org/abs/2204.07141
  - [1]: https://github.com/facebookresearch/msn
  
  Attributes:
      temperature:
          Similarities between anchors and targets are scaled by the inverse of
          the temperature. Must be in (0, inf).
      sinkhorn_iterations:
          Number of sinkhorn normalization iterations on the targets.
      regularization_weight:
          Weight factor lambda by which the regularization loss is scaled. Set to 0
          to disable regularization.
      me_max_weight:
          Deprecated, use `regularization_weight` instead. Takes precendence over
          `regularization_weight` if not None. Weight factor lambda by which the mean
          entropy maximization regularization loss is scaled. Set to 0 to disable
          mean entropy maximization reguliarization.
      gather_distributed:
          If True, then target probabilities are gathered from all GPUs.
  
   Examples:
  
      >>> # initialize loss function
      >>> loss_fn = MSNLoss()
      >>>
      >>> # generate anchors and targets of images
      >>> anchors = transforms(images)
      >>> targets = transforms(images)
      >>>
      >>> # feed through MSN model
      >>> anchors_out = model(anchors)
      >>> targets_out = model.target(targets)
      >>>
      >>> # calculate loss
      >>> loss = loss_fn(anchors_out, targets_out, prototypes=model.prototypes)
code: def __init__(
      self,
      temperature: float = 0.1,
      sinkhorn_iterations: int = 3,
      regularization_weight: float = 1.0,
      me_max_weight: Union[float, None] = None,
      gather_distributed: bool = False,
  ):
      super().__init__()
      if temperature <= 0:
          raise ValueError(
              f"temperature must be in (0, inf) but is {temperature}."
          )
      if sinkhorn_iterations < 0:
          raise ValueError(
              f"sinkhorn_iterations must be >= 0 but is {sinkhorn_iterations}."
          )
      if gather_distributed and not 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."
          )
  
      self.temperature = temperature
      self.sinkhorn_iterations = sinkhorn_iterations
      self.regularization_weight = regularization_weight
      # set regularization_weight to me_max_weight for backwards compatibility
      if me_max_weight is not None:
          warnings.warn(
              DeprecationWarning(
                  "me_max_weight is deprecated in favor of regularization_weight and "
                  "will be removed in the future."
              )
          )
          self.regularization_weight = me_max_weight
      self.gather_distributed = gather_distributed
  
file_path: lightly/lightly/loss/msn_loss.py
imports: import math
  import warnings
  from typing import Union
  import torch
  import torch.distributed
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
label_desc: Use image node_id 1 to create a new MSNLoss object from inherited base classes: nn with example: obj = MSNLoss(temperature, sinkhorn_iterations, regularization_weight, me_max_weight, gather_distributed)