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
| # -------------------------------------------------------------------------
| # Copyright (c) Microsoft Corporation. All rights reserved.
| # Licensed under the MIT License.
| # --------------------------------------------------------------------------
|
| import os
|
| import torch
|
| from ._mm import triton_gemm, triton_gemm_out, triton_matmul, triton_matmul_out # noqa: F401
| from ._slice_scel import slice_scel, slice_scel_backward # noqa: F401
|
| _all_kernels = [
| "triton_gemm",
| "triton_gemm_out",
| "triton_matmul",
| "triton_matmul_out",
| "slice_scel",
| "slice_scel_backward",
| ]
|
| if (
| "ORTMODULE_USE_FLASH_ATTENTION" in os.environ
| and int(os.getenv("ORTMODULE_USE_FLASH_ATTENTION")) == 1
| and torch.cuda.is_available()
| and torch.cuda.get_device_capability()[0] >= 8
| ):
| from ._flash_attn import flash_attn_backward, flash_attn_forward # noqa: F401
|
| _all_kernels.extend(["flash_attn_forward", "flash_attn_backward"])
|
| __all__ = _all_kernels # noqa: PLE0605
|
|