def __call__(
        self,
        attn: Attention,
        hidden_states: torch.Tensor,
        encoder_hidden_states: torch.Tensor,
        attention_mask: Optional[torch.Tensor] = None,
        image_rotary_emb: Optional[torch.Tensor] = None,
    ) -> Tuple[torch.Tensor, torch.Tensor]:
        r"""
        Process the dual-path attention for the inversion-guided denoising procedure.

        Args:
            attn (`Attention`): Parent attention module
            hidden_states (`torch.Tensor`): `[batch_size, image_seq_len, dim]` Image tokens
            encoder_hidden_states (`torch.Tensor`): `[batch_size, text_seq_len, dim]` Text tokens
            attention_mask (`Optional[torch.Tensor]`): Optional attention mask
            image_rotary_emb (`Optional[torch.Tensor]`): Rotary embeddings for image tokens

        Returns:
            `Tuple[torch.Tensor, torch.Tensor]`:
                (1) Final hidden states: `[batch_size, image_seq_length, dim]` Resulting image tokens
                (2) Final encoder states: `[batch_size, text_seq_length, dim]` Resulting text tokens
        """
        image_seq_length = hidden_states.size(1)
        text_seq_length = encoder_hidden_states.size(1)

        hidden_states = torch.cat([encoder_hidden_states, hidden_states], dim=1)

        batch_size, sequence_length, _ = (
            hidden_states.shape if encoder_hidden_states is None else encoder_hidden_states.shape
        )

        if attention_mask is not None:
            attention_mask = attn.prepare_attention_mask(attention_mask, sequence_length, batch_size)
            attention_mask = attention_mask.view(batch_size, attn.heads, -1, attention_mask.shape[-1])

        query = attn.to_q(hidden_states)
        key = attn.to_k(hidden_states)
        value = attn.to_v(hidden_states)

        query, query_reference = query.chunk(2)
        key, key_reference = key.chunk(2)
        value, value_reference = value.chunk(2)
        batch_size = batch_size // 2

        hidden_states, encoder_hidden_states = self.calculate_attention(
            query=query,
            key=torch.cat((key, key_reference), dim=1),
            value=torch.cat((value, value_reference), dim=1),
            attn=attn,
            batch_size=batch_size,
            image_seq_length=image_seq_length,
            text_seq_length=text_seq_length,
            attention_mask=attention_mask,
            image_rotary_emb=image_rotary_emb,
        )
        hidden_states_reference, encoder_hidden_states_reference = self.calculate_attention(
            query=query_reference,
            key=key_reference,
            value=value_reference,
            attn=attn,
            batch_size=batch_size,
            image_seq_length=image_seq_length,
            text_seq_length=text_seq_length,
            attention_mask=attention_mask,
            image_rotary_emb=image_rotary_emb,
        )

        return (
            torch.cat((hidden_states, hidden_states_reference)),
            torch.cat((encoder_hidden_states, encoder_hidden_states_reference)),
        )

        Process the dual-path attention for the inversion-guided denoising procedure.

        Args:
            attn (`Attention`): Parent attention module
            hidden_states (`torch.Tensor`): `[batch_size, image_seq_len, dim]` Image tokens
            encoder_hidden_states (`torch.Tensor`): `[batch_size, text_seq_len, dim]` Text tokens
            attention_mask (`Optional[torch.Tensor]`): Optional attention mask
            image_rotary_emb (`Optional[torch.Tensor]`): Rotary embeddings for image tokens

        Returns:
            `Tuple[torch.Tensor, torch.Tensor]`:
                (1) Final hidden states: `[batch_size, image_seq_length, dim]` Resulting image tokens
                (2) Final encoder states: `[batch_size, text_seq_length, dim]` Resulting text tokens
        
examples/community/cogvideox_ddim_inversion.py