def loss(
        self,
        images: torch.Tensor,
        data_samples=None,
    ) -> Union[torch.Tensor, Tuple[torch.Tensor]]:
        """generate train_loss from the input tensor and data_samples.

        Args:
            inputs (Tensor): A batch of inputs. The shape of it should be
                ``(num_samples, num_channels, *img_shape)``.
            data_samples (List[VQADataSample], optional): The annotation
                data of every samples..

        Returns:
            Dict[torch.Tensor]: The losses features.
        """

        # extract image feature
        image_embeds = self.extract_feat(images)
        image_atts = image_embeds.new_ones(
            image_embeds.size()[:-1], dtype=torch.long)

        raw_text = []
        box_targets = []
        for ds in data_samples:

            raw_text.append(ds.text)
            box_t = copy.deepcopy(ds.box) * 1.0
            box_t[1] /= ds.img_shape[0]
            box_t[3] /= ds.img_shape[0]
            box_t[0] /= ds.img_shape[1]
            box_t[2] /= ds.img_shape[1]

            box_targets.append(box_t)

        box_targets = image_embeds.new_tensor(np.stack(box_targets))
        box_targets = box_xyxy_to_cxcywh(box_targets)  # xywh 0-1

        text = self.tokenizer(
            raw_text,
            padding='longest',
            truncation=True,
            max_length=128,
            return_tensors='pt',
        ).to(image_embeds.device)

        text_embeds = self.text_encoder(
            text.input_ids,
            attention_mask=text.attention_mask,
            mode='text',
            return_dict=True)  # bz, seq_len, hid

        # multimodal fusion
        multimodal_embeds = self.multimodal_encoder(
            encoder_embeds=text_embeds.last_hidden_state,
            attention_mask=text.attention_mask,
            encoder_hidden_states=image_embeds,
            encoder_attention_mask=image_atts,
            return_dict=True,
        )

        # put answer from data_samples into tensor form
        losses = self.grounding_head.loss(
            text_embedding=multimodal_embeds.last_hidden_state,
            text_embedding_mask=text.attention_mask,
            encoder_hidden_states=image_embeds,
            encoder_attention_mask=image_atts,
            decoder_targets=box_targets,
        )

        return losses
generate train_loss from the input tensor and data_samples.

        Args:
            inputs (Tensor): A batch of inputs. The shape of it should be
                ``(num_samples, num_channels, *img_shape)``.
            data_samples (List[VQADataSample], optional): The annotation
                data of every samples..

        Returns:
            Dict[torch.Tensor]: The losses features.
        
mmpretrain/models/multimodal/blip/blip_grounding.py