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: :param encoding_dim:
      The dimensionality of positional encodings.
  :param max_seq_len:
      The expected maximum sequence length.
docstr_tok: [":","param","encoding_dim",":","The","dimensionality","of","positional","encodings",".",":","param","max_seq_len",":","The","expected","maximum","sequence","length","."]
code: def __init__(
      self,
      encoding_dim: int,
      max_seq_len: int,
      *,
      device: Optional[Device] = None,
      dtype: Optional[DataType] = None,
  ) -> None:
      """
      :param encoding_dim:
          The dimensionality of positional encodings.
      :param max_seq_len:
          The expected maximum sequence length.
      """
      super().__init__()
  
      if encoding_dim % 2 != 0:
          raise ValueError(
              f"`encoding_dim` must be even, but is {encoding_dim} instead."
          )
  
      self.encoding_dim = encoding_dim
      self.max_seq_len = max_seq_len
  
      freqs = torch.empty(
          ((max_seq_len * 2) - 1, encoding_dim),
          device=device,
          dtype=dtype,
      )
  
      self.register_buffer("freqs", freqs, persistent=False)
  
      self.reset_parameters()
  
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 1 to create a new RelativePositionalEncoding object from inherited base classes: Module with example: obj = RelativePositionalEncoding(encoding_dim, max_seq_len)