def forward(self, image, text, idx):
        """forward and calculate loss.

        Args:
            image (torch.Tensor): The input images. Shape: [B,T,C,H,W].
            text (dict): TODO
            idx (torch.Tensor): TODO

        Returns: TODO

        """
        self.clip_contrastive_temperature()

        vision_embeds, vision_query_embeds, vision_past_key_values = self.encode_vision(
            image, return_key_values=True
        )
        text_embeds, pooled_text_embeds = self.encode_text(text)

        # obtain vision and text representations.
        vision_proj = self.vision_proj(vision_query_embeds)  # [B, T, L, C]
        text_proj = self.text_proj(pooled_text_embeds)  # [B, C]

        # calculate loss

        ## VTC loss
        if self.loss_weight.vtc != 0:
            # sim_idx: (sim_v2t, idx), to save computation
            loss_vtc = self.criterion_vtc_vtm.vtc_loss(
                vision_proj,
                text_proj,
                idx,
                self.temp,
                all_gather=True,
                agg_method=self.agg_method,
            )
        else:
            loss_vtc = torch.tensor(0)

        ## VTM loss
        if self.loss_weight.vtm != 0:
            loss_vtm = self.vtm_loss(
                text,
                vision_embeds,
                vision_proj,
                text_proj,
                idx,
            )
        else:
            loss_vtm = torch.tensor(0)

        ## CAP loss
        if self.loss_weight.cap != 0:
            loss_cap = self.cap_loss(
                text,
                vision_past_key_values,
            )
        else:
            loss_cap = torch.tensor(0)

        return dict(
            loss_vtc=loss_vtc * self.loss_weight.vtc,
            loss_vtm=loss_vtm * self.loss_weight.vtm,
            loss_cap=loss_cap * self.loss_weight.cap,
        )
forward and calculate loss.

        Args:
            image (torch.Tensor): The input images. Shape: [B,T,C,H,W].
            text (dict): TODO
            idx (torch.Tensor): TODO

        Returns: TODO

        
video_chat2/models/videochat2_qformer.py