code: def _reference_global_loss(
      embedding: List[Tensor],
      inv_coeff: float = 25.0,
      var_coeff: float = 25.0,
      cov_coeff: float = 1.0,
  ) -> Tensor:
      # Original global loss from VICRegL:
      # https://github.com/facebookresearch/VICRegL/blob/803ae4c8cd1649a820f03afb4793763e95317620/main_vicregl.py#L421
      def center(x):
          return x - x.mean(dim=0)
  
      def off_diagonal(x: Tensor) -> Tensor:
          n, m = x.shape
          assert n == m
          return x.flatten()[:-1].view(n - 1, n + 1)[:, 1:].flatten()
  
      num_views = len(embedding)
      inv_loss = 0.0
      iter_ = 0
      for i in range(2):
          for j in np.delete(np.arange(np.sum(num_views)), i):
              inv_loss = inv_loss + F.mse_loss(
                  embedding[i], embedding[j]
              )
              iter_ = iter_ + 1
      inv_loss = inv_coeff * inv_loss / iter_
  
      var_loss = 0.0
      cov_loss = 0.0
      iter_ = 0
      embedding_dim = embedding[0].shape[1]
      for i in range(num_views):
          x = center(embedding[i])
          std_x = torch.sqrt(x.var(dim=0) + 0.0001)
          var_loss = var_loss + torch.mean(torch.relu(1.0 - std_x))
          cov_x = (x.T @ x) / (x.size(0) - 1)
          cov_loss = cov_loss + off_diagonal(cov_x).pow_(2).sum().div(
              embedding_dim
          )
          iter_ = iter_ + 1
      var_loss = var_coeff * var_loss / iter_
      cov_loss = cov_coeff * cov_loss / iter_
  
      return inv_loss + var_loss + cov_loss
  
file_path: lightly/tests/loss/test_VICRegLLoss.py
imports: import unittest
  from typing import List
  import numpy
  import torch
  import torch.nn.functional
  from torch import Tensor
  from lightly.loss import VICRegLLoss
label_desc: Use image node_id 1 for calling a global function with example usage: _reference_global_loss(embedding, inv_coeff, var_coeff, cov_coeff) and returns: unknown, unknown, x