class_docstr: Multi-Head Attention layer of Transformer-XL with support of relative positional encoding.
  Paper: https://arxiv.org/abs/1901.02860
  Args:
      n_head (int): number of heads
      n_feat (int): size of the features
      dropout_rate (float): dropout rate
class_docstr_tok: ["Multi-Head","Attention","layer","of","Transformer-XL","with","support","of","relative","positional","encoding",".","Paper",":","https",":","\/\/arxiv.org\/abs\/1901.02860","Args",":","n_head","(","int",")",":","number","of","heads","n_feat","(","int",")",":","size","of","the","features","dropout_rate","(","float",")",":","dropout","rate"]
docstr: Compute relative positional encoding.
  Args:
      x (torch.Tensor): (batch, nheads, time, 2*time-1)
docstr_tok: ["Compute","relative","positional","encoding",".","Args",":","x","(","torch.Tensor",")",":","(","batch",",","nheads",",","time",",","2","*","time-1",")"]
code: def rel_shift(self, x):
      """Compute relative positional encoding.
      Args:
          x (torch.Tensor): (batch, nheads, time, 2*time-1)
      """
      b, h, qlen, pos_len = x.size()  # (b, h, t1, t2)
      # need to add a column of zeros on the left side of last dimension to perform the relative shifting
      x = torch.nn.functional.pad(x, pad=(1, 0))  # (b, h, t1, t2+1)
      x = x.view(b, h, -1, qlen)  # (b, h, t2+1, t1)
      # need to drop the first row
      x = x[:, :, 1:].view(b, h, qlen, pos_len)  # (b, h, t1, t2)
      return x
  
imports: import math
  from functools import lru_cache
  from typing import List, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from nemo.utils import avoid_float16_autocast_context
label_desc: Use image node_id 2 for calling the RelPositionMultiHeadAttention obj's underlying member method code with example usage: obj.rel_shift(x) and returns: x