def forward(
        self,
        global_view_features: Sequence[Tuple[Tensor, Tensor]],
        global_view_grids: Sequence[Tensor],
        local_view_features: Optional[Sequence[Tuple[Tensor, Tensor]]] = None,
        local_view_grids: Optional[Sequence[Tensor]] = None,
    ) -> Tensor:
        """Computes the global and local VICRegL loss from the input features.

        Args:
            global_view_features:
                Sequence of (global_features, local_features) tuples from the global
                crop views. global_features must have size
                (batch_size, global_feature_dim) and local_features must have size
                (batch_size, grid_height, grid_width, local_feature_dim).
            global_view_grids:
                Sequence of grid tensors from the global crop views. Every tensor must
                have shape (batch_size, grid_height, grid_width, 2).
            local_view_features:
                Sequence of (global_features, local_features) tuples from the local crop
                views. global_features must have size
                (batch_size, global_feature_dim) and local_features must have size
                (batch_size, grid_height, grid_width, local_feature_dim). Note that
                grid_height and grid_width can differ between global_view_features and
                local_view_features.
            local_view_grids:
                Sequence of grid tensors from the local crop views. Every tensor must
                have shape (batch_size, grid_height, grid_width, 2). Note that
                grid_height and grid_width can differ between global_view_features and
                local_view_features.

        Returns:
            Weighted sum of the global and local loss, calculated as:
            `self.alpha * global_loss + (1-self.alpha) * local_loss`.

        Raises:
            ValueError: If the lengths of global_view_features and global_view_grids are not the same.
            ValueError: If the lengths of local_view_features and local_view_grids are not the same.
            ValueError: If only one of local_view_features or local_view_grids is set.
        """
        if len(global_view_features) != len(global_view_grids):
            raise ValueError(
                f"global_view_features and global_view_grids must have same length "
                f"but found {len(global_view_features)} and {len(global_view_grids)}."
            )
        if local_view_features is not None and local_view_grids is not None:
            if len(local_view_features) != len(local_view_grids):
                raise ValueError(
                    f"local_view_features and local_view_grids must have same length "
                    f"but found {len(local_view_features)} and {len(local_view_grids)}."
                )
        elif local_view_features is not None or local_view_grids is not None:
            raise ValueError(
                f"local_view_features and local_view_grids must either both be set or "
                f"None but found {type(local_view_features)} and {type(local_view_grids)}."
            )

        # Calculate loss from global features
        global_loss = self._global_loss(
            global_view_features=global_view_features,
            local_view_features=local_view_features,
        )

        # Calculate loss from local features
        local_loss = self._local_loss(
            global_view_features=global_view_features,
            global_view_grids=global_view_grids,
            local_view_features=local_view_features,
            local_view_grids=local_view_grids,
        )

        loss = self.alpha * global_loss + (1 - self.alpha) * local_loss
        return loss
Computes the global and local VICRegL loss from the input features.

        Args:
            global_view_features:
                Sequence of (global_features, local_features) tuples from the global
                crop views. global_features must have size
                (batch_size, global_feature_dim) and local_features must have size
                (batch_size, grid_height, grid_width, local_feature_dim).
            global_view_grids:
                Sequence of grid tensors from the global crop views. Every tensor must
                have shape (batch_size, grid_height, grid_width, 2).
            local_view_features:
                Sequence of (global_features, local_features) tuples from the local crop
                views. global_features must have size
                (batch_size, global_feature_dim) and local_features must have size
                (batch_size, grid_height, grid_width, local_feature_dim). Note that
                grid_height and grid_width can differ between global_view_features and
                local_view_features.
            local_view_grids:
                Sequence of grid tensors from the local crop views. Every tensor must
                have shape (batch_size, grid_height, grid_width, 2). Note that
                grid_height and grid_width can differ between global_view_features and
                local_view_features.

        Returns:
            Weighted sum of the global and local loss, calculated as:
            `self.alpha * global_loss + (1-self.alpha) * local_loss`.

        Raises:
            ValueError: If the lengths of global_view_features and global_view_grids are not the same.
            ValueError: If the lengths of local_view_features and local_view_grids are not the same.
            ValueError: If only one of local_view_features or local_view_grids is set.
        
lightly/loss/vicregl_loss.py