torch.nn.attention.bias.causal_lower_right¶
- torch.nn.attention.bias.causal_lower_right(*size)[source][source]¶
创建一个下三角因果偏置。
此函数生成一个下三角矩阵,以表示具有对角偏移的因果注意力偏置,使得包含的值与矩阵的右下角对齐。
构建此偏置的等效 PyTorch 代码为:
diagonal_offset = size[1] - size[0] torch.tril( torch.ones(size, dtype=torch.bool), diagonal=diagonal_offset, )
例如,当 shape=(3,4)时,所得到的偏置张量将是:
[[1, 1, 0, 0], [1, 1, 1, 0], [1, 1, 1, 1]]
- 参数:
大小 - 偏置矩阵的大小。
- 返回值:
下三角因果偏置变体。
- 返回类型: