def _global_variance_and_covariance_loss(
        self,
        global_view_features: Sequence[Tuple[Tensor, Tensor]],
        local_view_features: Optional[Sequence[Tuple[Tensor, Tensor]]] = None,
    ) -> Tuple[Tensor, Tensor]:
        """Returns variance and covariance loss from global features.

        Args:
            global_view_features: Sequence of (global_features, local_features)
                    tuples from the global crop views.
            local_view_features: Sequence of (global_features,local_features)
                    tuples from the local crop views.

        Returns:
            The computed variance and covariance loss from global features.
        """
        view_features = list(global_view_features)
        if local_view_features is not None:
            view_features = view_features + list(local_view_features)

        var_loss = torch.tensor(0.0)
        cov_loss = torch.tensor(0.0)
        loss_count = torch.tensor(0)
        for global_features, _ in view_features:
            if self.gather_distributed and dist.is_initialized():
                world_size = dist.get_world_size()
                if world_size > 1:
                    global_features = torch.cat(gather(global_features), dim=0)

            var_loss += variance_loss(x=global_features, eps=self.eps)
            cov_loss += covariance_loss(x=global_features)
            loss_count += 1
        return var_loss / loss_count, cov_loss / loss_count
Returns variance and covariance loss from global features.

        Args:
            global_view_features: Sequence of (global_features, local_features)
                    tuples from the global crop views.
            local_view_features: Sequence of (global_features,local_features)
                    tuples from the local crop views.

        Returns:
            The computed variance and covariance loss from global features.
        
lightly/loss/vicregl_loss.py