cerebras.modelzoo.common.utils.model.transformer_utils.make_key_padding_mask_broadcastable#
- cerebras.modelzoo.common.utils.model.transformer_utils.make_key_padding_mask_broadcastable(key_padding_mask, dtype=None, revert_mask=True, use_neg_inf=True)[source]#
Makes broadcastable key_padding masks so that padding tokens are ignored.
- Parameters
key_padding_mask (torch.Tensor) – Key padding mask with shape in [2,3,4], with entry values either 1 or 0.
dtype (torch.dtype) – Dtype of the resulting mask.
revert_mask (bool) – Whether to flip the 1’s and 0’s of the attention mask, default to True.
use_neg_inf (bool) – Use negative infinity instead of one in the resulting mask, default to True.
- Returns
The key padding mask of shape [batch_size, num_heads, src_seq_len, target_seq_len], with broadcast dimensions set to 1.