def _global_invariance_loss(
        self,
        global_view_features: Sequence[Tuple[Tensor, Tensor]],
        local_view_features: Optional[Sequence[Tuple[Tensor, Tensor]]] = None,
    ) -> Tensor:
        """Returns invariance 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 invariance loss from global features.
        """
        loss = torch.tensor(0.0)
        loss_count = torch.tensor(0)

        # Compute invariance loss between global views
        for global_features_a, _ in global_view_features:
            for global_features_b, _ in global_view_features:
                if global_features_a is not global_features_b:
                    loss += invariance_loss(global_features_a, global_features_b)
                    loss_count += 1

            # Compute invariance loss between global and local views
            if local_view_features is not None:
                for global_features_b, _ in local_view_features:
                    loss += invariance_loss(global_features_a, global_features_b)
                    loss_count += 1

        return loss / loss_count
Returns invariance 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 invariance loss from global features.
        
lightly/loss/vicregl_loss.py