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

[Draft] support qk head_dim different from vo head_dim #980

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
166 changes: 107 additions & 59 deletions csrc/flash_attn/flash_api.cpp

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions csrc/flash_attn/src/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ struct Flash_fwd_params : public Qkv_params {

void * __restrict__ alibi_slopes_ptr;
index_t alibi_slopes_batch_stride;
int d_value, d_value_rounded;
};

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -184,7 +185,7 @@ struct Flash_bwd_params : public Flash_fwd_params {

////////////////////////////////////////////////////////////////////////////////////////////////////

template<typename T, int Headdim> void run_mha_fwd_(Flash_fwd_params &params, cudaStream_t stream);
template<typename T, int Headdim> void run_mha_fwd_splitkv_dispatch(Flash_fwd_params &params, cudaStream_t stream);
template<typename T, int Headdim, int HeaddimV> void run_mha_fwd_(Flash_fwd_params &params, cudaStream_t stream);
template<typename T, int Headdim, int HeaddimV> void run_mha_fwd_splitkv_dispatch(Flash_fwd_params &params, cudaStream_t stream);

template<typename T, int Headdim> void run_mha_bwd_(Flash_bwd_params &params, cudaStream_t stream);
template<typename T, int Headdim, int HeaddimV> void run_mha_bwd_(Flash_bwd_params &params, cudaStream_t stream);
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim128_bf16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::bfloat16_t, 128>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::bfloat16_t, 128, 128>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim128<cutlass::bfloat16_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim128_fp16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::half_t, 128>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::half_t, 128, 128>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim128<cutlass::half_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim160_bf16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::bfloat16_t, 160>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::bfloat16_t, 160, 160>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim160<cutlass::bfloat16_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim160_fp16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::half_t, 160>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::half_t, 160, 160>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim160<cutlass::half_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim192_bf16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::bfloat16_t, 192>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::bfloat16_t, 192, 192>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim192<cutlass::bfloat16_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim192_fp16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::half_t, 192>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::half_t, 192, 192>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim192<cutlass::half_t>(params, stream);
}
10 changes: 10 additions & 0 deletions csrc/flash_attn/src/flash_bwd_hdim192_hdim128_bf16_sm80.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2023, Tri Dao.
// Splitting the different head dimensions to different files to speed up compilation.
// This file is auto-generated. See "generate_kernels.py"

#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::bfloat16_t, 192, 128>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim192_hdim128<cutlass::bfloat16_t>(params, stream);
}
10 changes: 10 additions & 0 deletions csrc/flash_attn/src/flash_bwd_hdim192_hdim128_fp16_sm80.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) 2023, Tri Dao.
// Splitting the different head dimensions to different files to speed up compilation.
// This file is auto-generated. See "generate_kernels.py"

#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::half_t, 192, 128>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim192_hdim128<cutlass::half_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim224_bf16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::bfloat16_t, 224>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::bfloat16_t, 224, 224>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim224<cutlass::bfloat16_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim224_fp16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::half_t, 224>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::half_t, 224, 224>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim224<cutlass::half_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim256_bf16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::bfloat16_t, 256>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::bfloat16_t, 256, 256>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim256<cutlass::bfloat16_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim256_fp16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::half_t, 256>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::half_t, 256, 256>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim256<cutlass::half_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim32_bf16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::bfloat16_t, 32>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::bfloat16_t, 32, 32>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim32<cutlass::bfloat16_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim32_fp16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::half_t, 32>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::half_t, 32, 32>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim32<cutlass::half_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim64_bf16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::bfloat16_t, 64>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::bfloat16_t, 64, 64>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim64<cutlass::bfloat16_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim64_fp16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::half_t, 64>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::half_t, 64, 64>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim64<cutlass::half_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim96_bf16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::bfloat16_t, 96>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::bfloat16_t, 96, 96>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim96<cutlass::bfloat16_t>(params, stream);
}
2 changes: 1 addition & 1 deletion csrc/flash_attn/src/flash_bwd_hdim96_fp16_sm80.cu
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
#include "flash_bwd_launch_template.h"

template<>
void run_mha_bwd_<cutlass::half_t, 96>(Flash_bwd_params &params, cudaStream_t stream) {
void run_mha_bwd_<cutlass::half_t, 96, 96>(Flash_bwd_params &params, cudaStream_t stream) {
run_mha_bwd_hdim96<cutlass::half_t>(params, stream);
}
Loading