Skip to content

flash_attn version selection for GPU under SM_89 (e.g., L20)聽#1338

Open

Description

@Luchuanzhao

馃悰 Bug

Hi~
Thanks for your excellent work.
However, I am very confused that the minimum architecture required in flash3 is SM_80 when selecting the version of flash_attn:
https://github.com/facebookresearch/xformers/blob/main/xformers/ops/fmha/flash3.py#L597
Actually, flash_attn3 should run on a GPU with Hopper architecture, and the required architecture is SM_90. I am not sure if this is a little bug?
In my practical use, I found that the flash_attn version used in xformers is flash3, which works well on H20 GPU, while there is a CUDA illegal memory access issue on L20 GPU. Further investigation using cuda-gdb revealed that the exception occurred in the flash:: prepare_varlen_num-blocks_kernel, which is exactly one of the kernels in _C.so in xformers. To solve this problem, I changed CUDA_MINIMUM_COMPUTE_CAPABILITY to (9,0) when running on L20, and the program can run normally.
I'm not sure if it's my improper use or if there's a bug in the selection logic here.

To Reproduce

When I change CUDA_MINIMUM_COMPUTE_CAPABILITY to (8, 0), it can be stably reproduced on L20
While it works well if changing CUDA_MINIMUM_COMPUTE_CAPABILITY to (9, 0)

Environment

Python version: 3.10.12
PyTorch version: 2.7.1+cu126

CUDA runtime version: 12.2.91
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA L20
GPU 1: NVIDIA L20
GPU 2: NVIDIA L20
GPU 3: NVIDIA L20

torch==2.7.1
transformers==4.54.1
xformers==0.0.31
vllm==0.10.0

Addition notes

I find a PR #1178 on Dec 18, 2024, which enables the default version of flash_attn to 3. However, there is no code executed to check if it is compatible with flash3.
https://github.com/facebookresearch/xformers/blob/v0.0.31/xformers/ops/fmha/dispatch.py#L22

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions