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

migrate "jagged_flash_attention" #3490

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .github/scripts/fbgemm_gpu_test.bash
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ __configure_fbgemm_gpu_test_cpu () {
./sll/jagged_flash_attention_basic_test.py
./sll/jagged_jagged_bmm_jagged_out_test.py
./sll/jagged_dense_flash_attention_test.py
./sll/multi_head_jagged_flash_attention_test.py
)
}

Expand Down
22 changes: 22 additions & 0 deletions fbgemm_gpu/fbgemm_gpu/sll/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
jagged_jagged_bmm,
jagged_jagged_bmm_jagged_out,
jagged_softmax,
multi_head_jagged_flash_attention,
triton_jagged_self_substraction_jagged_out,
)

Expand Down Expand Up @@ -263,6 +264,19 @@ def register_sll_op(op_name: str, functors: Dict[str, Callable]) -> None:
"""
)

if "fbgemm::sll_multi_head_jagged_flash_attention" not in torch.library._defs:
lib.define(
"""sll_multi_head_jagged_flash_attention(
Tensor q_weights,
Tensor k_weights,
Tensor v_weights,
Tensor offsets,
int max_seq_len,
bool allow_tf32=True
) -> Tensor
"""
)

# NOTE: here we register the op for AutogradCUDA/CPU and CUDA/CPU with the same function
# however, this is not ideal because in the inference case, we don't need the autograd forward
# to save the context because we don't need to do backward.
Expand Down Expand Up @@ -396,3 +410,11 @@ def register_sll_op(op_name: str, functors: Dict[str, Callable]) -> None:
"AutogradCPU": cpu_jagged_dense_flash_attention,
},
)

register_sll_op(
"sll_multi_head_jagged_flash_attention",
{
"CUDA": multi_head_jagged_flash_attention,
"AutogradCUDA": multi_head_jagged_flash_attention,
},
)
Loading
Loading