-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
[BUGFIX][ROCM] ViT FlashAttention on ROCm (no GFX9) and contiguous on qwen3vl ROCm TORCH_SDPA #27190
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
[BUGFIX][ROCM] ViT FlashAttention on ROCm (no GFX9) and contiguous on qwen3vl ROCm TORCH_SDPA #27190
Changes from 2 commits
e87f29c
c8735e7
889cde8
633792c
493f683
010fa99
f8aa45f
0dabbf1
c42f2d1
1e3074b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,12 @@ | |
| SlidingWindowSpec, | ||
| ) | ||
|
|
||
| if current_platform.is_rocm(): | ||
| from vllm.platforms.rocm import on_gfx9 | ||
| else: | ||
| on_gfx9 = lambda *args, **kwargs: False | ||
|
|
||
|
|
||
| FP8_DTYPE = current_platform.fp8_dtype() | ||
| logger = init_logger(__name__) | ||
| USE_XFORMERS_OPS = None | ||
|
|
@@ -93,14 +99,22 @@ def check_upstream_fa_availability(dtype: torch.dtype): | |
|
|
||
| def maybe_get_vit_flash_attn_backend( | ||
| attn_backend: _Backend, use_upstream_fa: bool | ||
| ) -> tuple[_Backend, Callable]: | ||
| if ( | ||
| attn_backend != _Backend.FLASH_ATTN | ||
| and attn_backend != _Backend.ROCM_AITER_FA | ||
| and check_upstream_fa_availability(torch.get_default_dtype()) | ||
| ): | ||
| attn_backend = _Backend.FLASH_ATTN | ||
| use_upstream_fa = True | ||
| ) -> tuple[_Backend, Callable | None]: | ||
| if current_platform.is_rocm(): | ||
| if envs.VLLM_ROCM_USE_AITER and envs.VLLM_ROCM_USE_AITER_MHA and on_gfx9(): | ||
| attn_backend = _Backend.ROCM_AITER_FA | ||
| elif on_gfx9(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This condition was crafted for ROCm platform ( if (
attn_backend != _Backend.FLASH_ATTN
and attn_backend != _Backend.ROCM_AITER_FA
and check_upstream_fa_availability(torch.get_default_dtype())
):On
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tjtanaa The first step was simply to check if it was rocm and if it was on_gfx1x and if so, return _Backend.TORCH_SDPA, None directly. Would you like to leave it like this with a comment indicating why? I've only seen it affect RDNA3 with the upstream flow. I think this way we could mark the required changes as resolved. If not, please tell me how the code should be :) |
||
| attn_backend = _Backend.FLASH_ATTN | ||
| else: | ||
| return _Backend.TORCH_SDPA, None | ||
| else: | ||
| if ( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned above, this condition and its content is also applicable to ROCm on |
||
| attn_backend != _Backend.FLASH_ATTN | ||
| and attn_backend != _Backend.ROCM_AITER_FA | ||
| and check_upstream_fa_availability(torch.get_default_dtype()) | ||
| ): | ||
| attn_backend = _Backend.FLASH_ATTN | ||
| use_upstream_fa = True | ||
|
JartX marked this conversation as resolved.
|
||
|
|
||
| if current_platform.is_rocm() and attn_backend == _Backend.FLASH_ATTN: | ||
| use_upstream_fa = True | ||
|
|
@@ -534,6 +548,7 @@ def forward( | |
| value = torch.repeat_interleave(value, num_repeat, dim=2) | ||
|
|
||
| if self.is_flash_attn_backend: | ||
| assert self._flash_attn_varlen_func is not None | ||
| cu_seqlens_q = torch.arange( | ||
| 0, (bsz + 1) * q_len, step=q_len, dtype=torch.int32, device=query.device | ||
| ) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.