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 seqs:
      The sequences for which to return positional encodings. *Shape:*
      :math:`(*,S,E)`, where :math:`*` is any number of batch dimensions
      including none, :math:`S` is the sequence length, and :math:`E` is
      the dimensionality of the positional encodings.
  
  :returns:
      The positional encodings to use in shift trick in
      :class:`RelativePositionSDPA`. *Shape:* :math:`(2 x S - 1, E)`,
      where :math:`S` is the sequence length and :math:`E` is the
      dimensionality of the positional encodings.
docstr_tok: [":","param","seqs",":","The","sequences","for","which","to","return","positional","encodings",".","*","Shape",":","*",":","math",":","`","(","*",",","S",",","E",")","`",",","where",":","math",":","`","*","`","is","any","number","of","batch","dimensions","including","none",",",":","math",":","`","S","`","is","the","sequence","length",",","and",":","math",":","`","E","`","is","the","dimensionality","of","the","positional","encodings",".",":","returns",":","The","positional","encodings","to","use","in","shift","trick","in",":","class",":","`","RelativePositionSDPA","`",".","*","Shape",":","*",":","math",":","`","(","2","x","S","-","1",",","E",")","`",",","where",":","math",":","`","S","`","is","the","sequence","length","and",":","math",":","`","E","`","is","the","dimensionality","of","the","positional","encodings","."]
code: def forward(self, seqs: Tensor) -> Tensor:
      """
      :param seqs:
          The sequences for which to return positional encodings. *Shape:*
          :math:`(*,S,E)`, where :math:`*` is any number of batch dimensions
          including none, :math:`S` is the sequence length, and :math:`E` is
          the dimensionality of the positional encodings.
  
      :returns:
          The positional encodings to use in shift trick in
          :class:`RelativePositionSDPA`. *Shape:* :math:`(2 x S - 1, E)`,
          where :math:`S` is the sequence length and :math:`E` is the
          dimensionality of the positional encodings.
      """
      seq_len = seqs.size(-2)
  
      if seq_len > self.max_seq_len:
          raise ValueError(
              f"The input sequence length must be less than or equal to the maximum sequence length ({self.max_seq_len}), but is {seq_len} instead."
          )
  
      return self.freqs[
          self.max_seq_len - seq_len : self.max_seq_len + seq_len - 1
      ]
  
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 4 for calling the RelativePositionalEncoding obj's underlying member method code with example usage: obj.forward(seqs) and returns: self