class_docstr: Implementation of the VICRegL loss from VICRegL paper [0].
  
  This implementation follows the code published by the authors [1].
  
  - [0]: VICRegL, 2022, https://arxiv.org/abs/2210.01571
  - [1]: https://github.com/facebookresearch/VICRegL
  
  Attributes:
      lambda_param:
          Coefficient for the invariance term of the loss.
      mu_param:
          Coefficient for the variance term of the loss.
      nu_param:
          Coefficient for the covariance term of the loss.
      alpha:
          Coefficient to weight global with local loss. The final loss is computed as
          (self.alpha * global_loss + (1-self.alpha) * local_loss).
      gather_distributed:
          If True then the cross-correlation matrices from all gpus are gathered and
          summed before the loss calculation.
      eps:
          Epsilon for numerical stability.
      num_matches:
          Number of local features to match using nearest neighbors.
  
  Examples:
  
      >>> # initialize loss function
      >>> criterion = VICRegLLoss()
      >>> transform = VICRegLTransform(n_global_views=2, n_local_views=4)
      >>>
      >>> # generate two random transforms of images
      >>> views_and_grids = transform(images)
      >>> views = views_and_grids[:6] # 2 global views + 4 local views
      >>> grids = views_and_grids[6:]
      >>>
      >>> # feed through model images
      >>> features = [model(view) for view in views]
      >>>
      >>> # calculate loss
      >>> loss = criterion(
      ...     global_view_features=features[:2],
      ...     global_view_grids=grids[:2],
      ...     local_view_features=features[2:],
      ...     local_view_grids=grids[2:],
      ... )
class_docstr_tok: ["Implementation","of","the","VICRegL","loss","from","VICRegL","paper","[","0","]",".","This","implementation","follows","the","code","published","by","the","authors","[","1","]",".","-","[","0","]",":","VICRegL",",","2022",",","https",":","\/\/arxiv.org\/abs\/2210.01571","-","[","1","]",":","https",":","\/\/github.com\/facebookresearch\/VICRegL","Attributes",":","lambda_param",":","Coefficient","for","the","invariance","term","of","the","loss",".","mu_param",":","Coefficient","for","the","variance","term","of","the","loss",".","nu_param",":","Coefficient","for","the","covariance","term","of","the","loss",".","alpha",":","Coefficient","to","weight","global","with","local","loss",".","The","final","loss","is","computed","as","(","self.alpha","*","global_loss","+","(","1-self.alpha",")","*","local_loss",")",".","gather_distributed",":","If","True","then","the","cross-correlation","matrices","from","all","gpus","are","gathered","and","summed","before","the","loss","calculation",".","eps",":","Epsilon","for","numerical","stability",".","num_matches",":","Number","of","local","features","to","match","using","nearest","neighbors",".","Examples",":",">",">",">","#","initialize","loss","function",">",">",">","criterion","=","VICRegLLoss","(",")",">",">",">","transform","=","VICRegLTransform","(","n_global_views=2",",","n_local_views=4",")",">",">",">",">",">",">","#","generate","two","random","transforms","of","images",">",">",">","views_and_grids","=","transform","(","images",")",">",">",">","views","=","views_and_grids","[",":6","]","#","2","global","views","+","4","local","views",">",">",">","grids","=","views_and_grids","[","6",":","]",">",">",">",">",">",">","#","feed","through","model","images",">",">",">","features","=","[","model","(","view",")","for","view","in","views","]",">",">",">",">",">",">","#","calculate","loss",">",">",">","loss","=","criterion","(","...","global_view_features=features","[",":2","]",",","...","global_view_grids=grids","[",":2","]",",","...","local_view_features=features","[","2",":","]",",","...","local_view_grids=grids","[","2",":","]",",","...",")"]
docstr: Returns loss for local features matched with neareast neighbors using L2
  distance in the feature space.
  
  Args:
      z_a:
          Local feature tensor with shape (batch_size, heigh, width, dim).
      z_b:
          Local feature tensor with shape (batch_size, heigh, width, dim).
docstr_tok: ["Returns","loss","for","local","features","matched","with","neareast","neighbors","using","L2","distance","in","the","feature","space",".","Args",":","z_a",":","Local","feature","tensor","with","shape","(","batch_size",",","heigh",",","width",",","dim",")",".","z_b",":","Local","feature","tensor","with","shape","(","batch_size",",","heigh",",","width",",","dim",")","."]
code: def _local_l2_loss(
      self,
      z_a: Tensor,
      z_b: Tensor,
  ) -> Tensor:
      """Returns loss for local features matched with neareast neighbors using L2
      distance in the feature space.
  
      Args:
          z_a:
              Local feature tensor with shape (batch_size, heigh, width, dim).
          z_b:
              Local feature tensor with shape (batch_size, heigh, width, dim).
      """
      # (batch_size, heigh, width, dim) -> (batch_size, heigh * width, dim)
      z_a = z_a.flatten(start_dim=1, end_dim=2)
      z_b = z_b.flatten(start_dim=1, end_dim=2)
  
      z_a_filtered, z_a_nn = self._nearest_neighbors_on_l2(
          input_features=z_a,
          candidate_features=z_b,
          num_matches=self.num_matches[0],
      )
      z_b_filtered, z_b_nn = self._nearest_neighbors_on_l2(
          input_features=z_b,
          candidate_features=z_a,
          num_matches=self.num_matches[1],
      )
      loss_a = self.vicreg_loss.forward(z_a=z_a_filtered, z_b=z_a_nn)
      loss_b = self.vicreg_loss.forward(z_a=z_b_filtered, z_b=z_b_nn)
      return 0.5 * (loss_a + loss_b)
  
file_path: lightly/lightly/loss/vicregl_loss.py
imports: from typing import Optional, Sequence, Tuple
  import torch
  import torch.distributed
  from torch import Tensor
  from lightly.loss.vicreg_loss import VICRegLoss, covariance_loss, invariance_loss, variance_loss
  from lightly.models.utils import nearest_neighbors
  from lightly.utils.dist import gather
label_desc: Use image node_id 7 for calling the VICRegLLoss obj's underlying member method code with example usage: obj._local_l2_loss(z_a, z_b) and returns: unknown