def loss(self, inputs: torch.Tensor, data_samples: List[DataSample],
             **kwargs) -> Dict[str, torch.Tensor]:
        """The forward function in training.

        Args:
            inputs (torch.Tensor): The input images.
            data_samples (List[DataSample]): All elements required
                during the forward function.

        Returns:
            Dict[str, torch.Tensor]: A dictionary of loss components.
        """
        mask = torch.stack([data_sample.mask for data_sample in data_samples])
        mask = mask.flatten(1).bool()

        latent = self.backbone(inputs, mask)
        B, L, C = latent.shape
        pred = self.neck((latent.view(B * L, C), ))
        pred = pred[0].view(B, L, -1)
        hog = self.target_generator(inputs)

        # remove cls_token before compute loss
        loss = self.head.loss(pred[:, 1:], hog, mask)
        losses = dict(loss=loss)
        return losses
The forward function in training.

        Args:
            inputs (torch.Tensor): The input images.
            data_samples (List[DataSample]): All elements required
                during the forward function.

        Returns:
            Dict[str, torch.Tensor]: A dictionary of loss components.
        
mmpretrain/models/selfsup/maskfeat.py