class_docstr: ## RoPE module that rotates in the opposite direction
  
  This inherits from [RoPE rotation implementation](../index.html) and changes the direction.
docstr: * `x` is the Tensor at the head of a key or a query with shape `[seq_len, batch_size, n_heads, d]`
code: def forward(self, x: torch.Tensor):
      """
      * `x` is the Tensor at the head of a key or a query with shape `[seq_len, batch_size, n_heads, d]`
      """
      # Cache $\cos$ and $\sin$ values
      self._build_cache(x)
  
      # Split the features, we can choose to apply rotary embeddings only to a partial set of features.
      x_rope, x_pass = x[..., : self.d], x[..., self.d :]
  
      # Calculate
      # $[-x^{(\frac{d}{2} + 1)}, -x^{(\frac{d}{2} + 2)}, ..., -x^{(d)}, x^{(1)}, x^{(2)}, ..., x^{(\frac{d}{2})}]$
      neg_half_x = self._neg_half(x_rope)
  
      # Calculate
      #
      # \begin{align}
      # \begin{pmatrix}
      # x^{(i)}_m \cos -m \theta_i - x^{(i + \frac{d}{2})}_m \sin -m \theta_i \\
      # x^{(i + \frac{d}{2})}_m \cos -m\theta_i + x^{(i)}_m \sin -m \theta_i \\
      # \end{pmatrix} = \\
      # \begin{pmatrix}
      # x^{(i)}_m \cos m \theta_i + x^{(i + \frac{d}{2})}_m \sin m \theta_i \\
      # x^{(i + \frac{d}{2})}_m \cos m\theta_i - x^{(i)}_m \sin m \theta_i \\
      # \end{pmatrix} \\
      # \end{align}
      #
      # for $i \in {1, 2, ..., \frac{d}{2}}$
      x_rope = (x_rope * self.cos_cached[: x.shape[0]]) - (
          neg_half_x * self.sin_cached[: x.shape[0]]
      )
  
      #
      return torch.cat((x_rope, x_pass), dim=-1)
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/transformers/rope/value_pe/__init__.py
imports: from typing import Optional
  import torch
  from labml_nn.transformers.rope import RotaryPositionalEmbeddings, RotaryPEMultiHeadAttention
label_desc: Use image node_id 1 for calling the ReverseRotaryPositionalEmbeddings obj's underlying member method code with example usage: obj.forward(x) and returns: torch