torch.nn.attention.bias.causal_upper_left¶
- torch.nn.attention.bias.causal_upper_left(*size)[source][source]¶
创建左上三角因果偏置。
此函数生成一个左上三角矩阵,以表示因果注意力偏置,并设置对角线偏移,以便将包含值与矩阵的左上角对齐。这等效于 scaled_dot_product_attention 中的 is_causal=True 参数。
用于构建此偏置的等效 PyTorch 代码是
torch.tril(torch.ones(size, dtype=torch.bool))
例如,对于 shape=(3,4),物化的偏置张量将是
[[1, 0, 0, 0], [1, 1, 0, 0], [1, 1, 1, 0]]
- 参数
size – 偏置矩阵的大小。
- 返回
左上三角因果偏置变体。
- 返回类型