    def __init__(
        self,
        n_head,
        n_feat,
        dropout_rate,
        do_rel_shift=False,
        adaptive_scale=False,
        init_weights=False,
    ):
        """Construct an RelPositionMultiHeadedAttention object."""
        super().__init__(n_head, n_feat, dropout_rate)
        # linear transformation for positional encoding
        self.linear_pos = nn.Linear(n_feat, n_feat, bias=False)
        # these two learnable bias are used in matrix c and matrix d
        # as described in https://arxiv.org/abs/1901.02860 Section 3.3
        self.do_rel_shift = do_rel_shift
        self.pos_bias_u = nn.Parameter(torch.Tensor(self.h, self.d_k))
        self.pos_bias_v = nn.Parameter(torch.Tensor(self.h, self.d_k))
        torch.nn.init.xavier_uniform_(self.pos_bias_u)
        torch.nn.init.xavier_uniform_(self.pos_bias_v)
        self.adaptive_scale = adaptive_scale
        self.ada_scale = nn.Parameter(
            torch.ones([1, 1, n_feat]), requires_grad=adaptive_scale
        )
        self.ada_bias = nn.Parameter(
            torch.zeros([1, 1, n_feat]), requires_grad=adaptive_scale
        )
        if init_weights:
            self.init_weights()
Construct an RelPositionMultiHeadedAttention object.
modules/wenet_extractor/squeezeformer/attention.py