Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable complete BlockDiagonalGappyKeysMask and BlockDiagonalPaddedKey Support on CK #1108

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions xformers/ops/fmha/ck.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
BlockDiagonalCausalWithOffsetPaddedKeysMask,
BlockDiagonalGappyKeysMask,
BlockDiagonalMask,
BlockDiagonalPaddedKeysMask,
LowerTriangularFromBottomRightLocalAttentionMask,
LowerTriangularFromBottomRightMask,
LowerTriangularMask,
Expand All @@ -48,7 +49,8 @@ def _get_seqlen_info(
) -> Tuple[Optional[torch.Tensor], Optional[torch.Tensor], int, int]:
attn_bias = inp.attn_bias
if isinstance(
attn_bias, (BlockDiagonalMask, BlockDiagonalCausalWithOffsetPaddedKeysMask)
attn_bias,
(BlockDiagonalMask, BlockDiagonalPaddedKeysMask, BlockDiagonalGappyKeysMask),
):
attn_bias.k_seqinfo.to(inp.query.device)
attn_bias.q_seqinfo.to(inp.query.device)
Expand Down Expand Up @@ -159,6 +161,7 @@ class FwOp(AttentionFwOpBase):
BlockDiagonalCausalWithOffsetGappyKeysMask,
BlockDiagonalCausalWithOffsetPaddedKeysMask,
BlockDiagonalGappyKeysMask,
BlockDiagonalPaddedKeysMask,
attn_bias.BlockDiagonalCausalFromBottomRightMask,
attn_bias.BlockDiagonalCausalLocalAttentionMask,
BlockDiagonalCausalLocalAttentionFromBottomRightMask,
Expand All @@ -167,6 +170,7 @@ class FwOp(AttentionFwOpBase):
SUPPORTS_DROPOUT = True
SUPPORTS_CUSTOM_SCALE = True
SUPPORTS_DIFFERENT_VALUE_EMBED = True
SUPPORTS_PARTIAL = True
SUPPORTS_BMGHK = True
NAME = "ckF"

Expand Down Expand Up @@ -273,7 +277,11 @@ def apply_bmhk(
seqlen_k=(
inp.attn_bias.k_seqinfo.seqlen
if isinstance(
inp.attn_bias, BlockDiagonalCausalWithOffsetPaddedKeysMask
inp.attn_bias,
(
BlockDiagonalGappyKeysMask,
BlockDiagonalPaddedKeysMask,
),
)
else None
),
Expand Down Expand Up @@ -417,7 +425,11 @@ def apply(cls, ctx: Context, inp: Inputs, grad: torch.Tensor) -> Gradients:
seqlen_k=(
inp.attn_bias.k_seqinfo.seqlen
if isinstance(
inp.attn_bias, BlockDiagonalCausalWithOffsetPaddedKeysMask
inp.attn_bias,
(
BlockDiagonalGappyKeysMask,
BlockDiagonalPaddedKeysMask,
),
)
else None
),
Expand Down
Loading