class_docstr: Computes scaled dot-product attention as described in
  :cite:t:`https://doi.org/10.48550/arxiv.1803.02155`.
docstr: :param model_dim:
      The dimensionality of the model.
  :param: num_heads:
      The number of attention heads.
  :param: max_left_rel_pos:
      The left clipping value for relative positions.
  :param: max_right_rel_pos:
      The right clipping value for relative positions.
  :param: use_rel_pos_values:
      If ``True``, uses relative position values to compute attention.
  :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",":","max_left_rel_pos",":","The","left","clipping","value","for","relative","positions",".",":","param",":","max_right_rel_pos",":","The","right","clipping","value","for","relative","positions",".",":","param",":","use_rel_pos_values",":","If","``","True","``",",","uses","relative","position","values","to","compute","attention",".",":","param","inner_sdpa",":","The","actual",":","class",":","`","SDPA","`","module","to","compute","head","attentions","."]
code: def __init__(
      self,
      model_dim: int,
      num_heads: int,
      max_left_rel_pos: int,
      *,
      max_right_rel_pos: Optional[int] = None,
      use_rel_pos_values: bool = False,
      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: max_left_rel_pos:
          The left clipping value for relative positions.
      :param: max_right_rel_pos:
          The right clipping value for relative positions.
      :param: use_rel_pos_values:
          If ``True``, uses relative position values to compute attention.
      :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
  
      head_dim = model_dim // num_heads
  
      self.max_left_rel_pos = max_left_rel_pos
  
      self.max_right_rel_pos = (
          max_left_rel_pos
          if max_right_rel_pos is None
          else max_right_rel_pos
      )
  
      num_pos = self.max_left_rel_pos + 1 + self.max_right_rel_pos
  
      self.rel_k_embed = StandardEmbedding(
          num_pos,
          head_dim,
          init_fn=init_shaw_embedding,
          device=device,
          dtype=dtype,
      )
  
      if use_rel_pos_values:
          self.rel_v_embed = StandardEmbedding(
              num_pos,
              head_dim,
              init_fn=init_shaw_embedding,
              device=device,
              dtype=dtype,
          )
      else:
          self.register_module("rel_v_embed", None)
  
      if inner_sdpa is not None:
          self.inner_sdpa = inner_sdpa
      else:
          self.inner_sdpa = create_default_sdpa()
  
file_path: fairseq2/src/fairseq2/nn/transformer/shaw_attention.py
imports: from typing import Optional, Tuple, final
  import torch
  import torch.nn
  from torch import Tensor
  from fairseq2.nn.embedding import StandardEmbedding
  from fairseq2.nn.padding import PaddingMask
  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 ShawRelativePositionSDPA object from inherited base classes: SDPA with example: obj = ShawRelativePositionSDPA(model_dim, num_heads, max_left_rel_pos)