class_docstr: Computes scaled dot-product attention as described in
  :cite:t:`https://doi.org/10.48550/arxiv.1901.02860`.
class_docstr_tok: ["Computes","scaled","dot-product","attention","as","described","in",":","cite",":","t",":","`","https",":","\/\/doi.org\/10.48550\/arxiv.1901.02860","`","."]
docstr: :param model_dim:
      The dimensionality of the model.
  :param: num_heads:
      The number of attention heads.
  :param: pos_encoding:
      The relative positional encoding table.
  :param inner_sdpa:
      The actual :class:`SDPA` module to compute head attentions.
docstr_tok: [":","param","model_dim",":","The","dimensionality","of","the","model",".",":","param",":","num_heads",":","The","number","of","attention","heads",".",":","param",":","pos_encoding",":","The","relative","positional","encoding","table",".",":","param","inner_sdpa",":","The","actual",":","class",":","`","SDPA","`","module","to","compute","head","attentions","."]
code: def __init__(
      self,
      model_dim: int,
      num_heads: int,
      pos_encoding: RelativePositionalEncoding,
      *,
      inner_sdpa: Optional[SDPA] = None,
      device: Optional[Device] = None,
      dtype: Optional[DataType] = None,
  ) -> None:
      """
      :param model_dim:
          The dimensionality of the model.
      :param: num_heads:
          The number of attention heads.
      :param: pos_encoding:
          The relative positional encoding table.
      :param inner_sdpa:
          The actual :class:`SDPA` module to compute head attentions.
      """
      super().__init__()
  
      if model_dim % num_heads != 0:
          raise ValueError(
              f"`model_dim` must be a multiple of `num_heads` ({num_heads}), but is {model_dim} instead."
          )
  
      self.model_dim = model_dim
      self.num_heads = num_heads
  
      if pos_encoding.encoding_dim != model_dim:
          raise ValueError(
              f"`encoding_dim` of `pos_encoding` must be equal to `model_dim` ({model_dim}), but is {pos_encoding.encoding_dim} instead."
          )
  
      self.pos_encoding = pos_encoding
  
      head_dim = model_dim // num_heads
  
      self.u_bias = Parameter(
          torch.empty((num_heads, head_dim), device=device, dtype=dtype)
      )
      self.v_bias = Parameter(
          torch.empty((num_heads, head_dim), device=device, dtype=dtype)
      )
  
      self.r_proj = Linear(
          model_dim, model_dim, bias=False, device=device, dtype=dtype
      )
  
      if inner_sdpa is not None:
          self.inner_sdpa = inner_sdpa
      else:
          self.inner_sdpa = create_default_sdpa()
  
      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 RelativePositionSDPA object from inherited base classes: SDPA with example: obj = RelativePositionSDPA(model_dim, num_heads, pos_encoding)