class_docstr: The rotary position embeddings from RoFormer_ (Su et. al).
  A crucial insight from the method is that the query and keys are
  transformed by rotation matrices which depend on the relative positions.
  Other implementations are available in the Rotary Transformer repo_ and in
  GPT-NeoX_, GPT-NeoX was an inspiration
  .. _RoFormer: https://arxiv.org/abs/2104.09864
  .. _repo: https://github.com/ZhuiyiTechnology/roformer
  .. _GPT-NeoX: https://github.com/EleutherAI/gpt-neox
class_docstr_tok: ["The","rotary","position","embeddings","from","RoFormer_","(","Su","et",".","al",")",".","A","crucial","insight","from","the","method","is","that","the","query","and","keys","are","transformed","by","rotation","matrices","which","depend","on","the","relative","positions",".","Other","implementations","are","available","in","the","Rotary","Transformer","repo_","and","in","GPT-NeoX_",",","GPT-NeoX","was","an","inspiration","..","_RoFormer",":","https",":","\/\/arxiv.org\/abs\/2104.09864","..","_repo",":","https",":","\/\/github.com\/ZhuiyiTechnology\/roformer","..","_GPT-NeoX",":","https",":","\/\/github.com\/EleutherAI\/gpt-neox"]
code: def _update_cos_sin_tables(
      self, x: torch.Tensor, seq_dimension: int = -2
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      seq_len = x.shape[seq_dimension]
  
      # Reset the tables if the sequence length has changed,
      # or if we're on a new device (possibly due to tracing for instance)
      # if seq_len != self._seq_len_cached:  # or self._cos_cached.device != x.device or self._cos_cached.dtype != x.dtype:
      self._seq_len_cached = seq_len
      t = torch.arange(
          x.shape[seq_dimension],
          device=x.device,
          dtype=self.inv_freq.dtype,
      )
      # Don't do einsum, it converts fp32 to fp16
      # freqs = torch.einsum("i,j->ij", t, self.inv_freq)
      freqs = torch.outer(t, self.inv_freq)
      cos_cached = repeat(
          torch.cos(freqs).to(x.dtype), "... d -> ... (d 2)"
      )
      sin_cached = repeat(
          torch.sin(freqs).to(x.dtype), "... d -> ... (d 2)"
      )
  
      return cos_cached, sin_cached
  
imports: import torch
  import math
  from typing import Tuple
  from einops import repeat
label_desc: Use image node_id 2 for calling the RotaryEleutherAI obj's underlying member method code with example usage: obj._update_cos_sin_tables(x, seq_dimension) and returns: cos_cached,  sin_cached