forked from tspeterkim/flash-attention-minimal
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
50 lines (46 loc) · 1.28 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <torch/extension.h>
std::vector<torch::Tensor> flash_attention_1_forward(
torch::Tensor Q, torch::Tensor K, torch::Tensor V
);
std::vector<torch::Tensor> flash_attention_1_backward(
torch::Tensor Q,
torch::Tensor K,
torch::Tensor V,
torch::Tensor O,
torch::Tensor dO,
torch::Tensor l,
torch::Tensor m
);
std::vector<torch::Tensor> flash_attention_2_forward(
torch::Tensor Q, torch::Tensor K, torch::Tensor V
);
std::vector<torch::Tensor> flash_attention_2_backward(
torch::Tensor Q,
torch::Tensor K,
torch::Tensor V,
torch::Tensor O,
torch::Tensor dO,
torch::Tensor L
);
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.def(
"flash_attention_1_forward",
torch::wrap_pybind_function(flash_attention_1_forward),
"flash_attention_1_forward"
);
m.def(
"flash_attention_1_backward",
torch::wrap_pybind_function(flash_attention_1_backward),
"flash_attention_1_backward"
);
m.def(
"flash_attention_2_forward",
torch::wrap_pybind_function(flash_attention_2_forward),
"flash_attention_2_forward"
);
m.def(
"flash_attention_2_backward",
torch::wrap_pybind_function(flash_attention_2_backward),
"flash_attention_2_backward"
);
}