class_docstr: This class implements the relative multihead implementation similar to that in Transformer XL
  https://arxiv.org/pdf/1901.02860.pdf
  
  Arguments
  ---------
  embed_dim : int
      Size of the encoder feature vectors from which keys and values are computed.
  num_heads: int
      Number of attention heads.
  dropout : float, optional
      Dropout rate.
  vbias: bool, optional
      Whether to use bias for computing value.
  vdim: int, optional
      Size for value. Default is embed_dim (Note each head is embed_dim // num_heads).
  mask_pos_future: bool, optional
      Whether to mask future positional encodings values.
      Must be true for causal applications e.g. decoder.
  Example
  -------
  >>> inputs = torch.rand([6, 60, 512])
  >>> pos_emb = torch.rand([1, 2*60-1, 512])
  >>> net = RelPosMHAXL(num_heads=8, embed_dim=inputs.shape[-1])
  >>> outputs, attn = net(inputs, inputs, inputs, pos_emb)
  >>> outputs.shape
  torch.Size([6, 60, 512])
code: def __init__(
      self,
      embed_dim,
      num_heads,
      dropout=0.0,
      vbias=False,
      vdim=None,
      mask_pos_future=False,
  ):
      super(RelPosMHAXL, self).__init__()
      self.embed_dim = embed_dim
      self.vdim = vdim if vdim is not None else embed_dim
      self._qkv_same_embed_dim = self.vdim == embed_dim
      self.mask_pos_future = mask_pos_future
      self.vbias = vbias
  
      self.num_heads = num_heads
      self.dropout = dropout
      self.head_dim = embed_dim // num_heads
      self.vhead_dim = self.vdim // num_heads
  
      assert (
          self.head_dim * num_heads == self.embed_dim
      ), "embed_dim must be divisible by num_heads"
      assert (
          self.vhead_dim * num_heads == self.vdim
      ), "vdim must be divisible by num_heads"
  
      if self._qkv_same_embed_dim is False:
          self.qk_proj_weight = nn.Parameter(
              torch.empty(2 * embed_dim, embed_dim)
          )
          self.v_proj_weight = nn.Parameter(
              torch.empty(self.vdim, embed_dim)
          )
      else:
          self.in_proj_weight = nn.Parameter(
              torch.empty(3 * embed_dim, embed_dim)
          )
  
      if vbias:
          self.value_bias_weight = nn.Parameter(torch.empty(self.vdim))
      else:
          self.vbias = None
  
      self.dropout_att = nn.Dropout(dropout)
      self.out_proj = nn.Linear(self.vdim, embed_dim)
  
      self.linear_pos = nn.Linear(embed_dim, embed_dim, bias=False)
  
      self.pos_bias_u = nn.Parameter(
          torch.empty(self.head_dim, self.num_heads)
      )
      self.pos_bias_v = nn.Parameter(
          torch.empty(self.head_dim, self.num_heads)
      )
  
      if next(self.parameters()).dtype == torch.float16:
          self.attn_fill_value = -65000
      else:
          self.attn_fill_value = -float("inf")
  
      self._reset_parameters()
      self.scale = 1 / math.sqrt(self.embed_dim)
  
imports: import torch
  import logging
  import torch.nn
  import numpy
  from typing import Optional
  from speechbrain.dataio.dataio import length_to_mask
  import torch.nn.functional
  import math
label_desc: Use image node_id 1 to create a new RelPosMHAXL object from inherited base classes: nn with example: obj = RelPosMHAXL(embed_dim, num_heads, dropout, vbias, vdim, mask_pos_future)