class_docstr: Produces relative positional encodings as described in Appendix B of
  :cite:t:`dai2019transformerxl`.
class_docstr_tok: ["Produces","relative","positional","encodings","as","described","in","Appendix","B","of",":","cite",":","t",":","`","dai2019transformerxl","`","."]
docstr: Reset the non-persistent buffers of the module.
docstr_tok: ["Reset","the","non-persistent","buffers","of","the","module","."]
code: def reset_non_persistent_buffers(self) -> None:
      """Reset the non-persistent buffers of the module."""
      fp32_freqs = self.freqs.float()
  
      device, dtype = fp32_freqs.device, fp32_freqs.dtype
  
      positive_half = fp32_freqs[: self.max_seq_len]
      negative_half = fp32_freqs[self.max_seq_len :]
  
      # (S)
      steps = torch.arange(self.max_seq_len, device=device, dtype=dtype)
  
      # (E / 2)
      indices = torch.arange(
          0, self.encoding_dim, step=2, device=device, dtype=dtype
      )
  
      freqs = torch.exp(
          indices * -math.log(10000.0) / self.encoding_dim
      )
  
      # (S) x (E / 2) -> (S, E / 2)
      freqs = torch.outer(steps, freqs)
  
      flipped_freqs = freqs.flip([0])
  
      # A mirrored matrix of sinusoidal positive and negative positional
      # encodings to use in shift trick.
      #
      # [max, ...,  3,  2,  1,  0, -1, -2, -3, ..., min]
      torch.sin(flipped_freqs, out=positive_half[:, 0::2])
      torch.cos(flipped_freqs, out=positive_half[:, 1::2])
  
      torch.sin(-1 * freqs[1:], out=negative_half[:, 0::2])
      torch.cos(-1 * freqs[1:], out=negative_half[:, 1::2])
  
      self.freqs.copy_(fp32_freqs)
  
imports: from __future__ import annotations
  import math
  from typing import Optional, Tuple, final
  import torch
  import torch.nn
  from torch import Tensor
  from torch.nn import Module, Parameter
  from torch.nn.functional import pad
  from fairseq2.nn.padding import PaddingMask
  from fairseq2.nn.projection import Linear
  from fairseq2.nn.transformer.attention import SDPA, create_default_sdpa
  from fairseq2.nn.transformer.attention_mask import AttentionMask, CustomAttentionMask
  from fairseq2.typing import DataType, Device, finaloverride
label_desc: Use image node_id 3 for calling the RelativePositionalEncoding obj's underlying member method code with example usage: obj.reset_non_persistent_buffers() without return types