[FlashAttention] Symlink FA4 instead of copying when using VLLM_FLASH_ATTN_SRC_DIR (#38814)

Signed-off-by: Matthew Bonanni <mbonanni@redhat.com>
This commit is contained in:
Matthew Bonanni
2026-04-08 12:04:34 +00:00
committed by GitHub
parent 4e2ab1861d
commit 308cec5864
2 changed files with 47 additions and 16 deletions
+20 -1
View File
@@ -1,7 +1,26 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from vllm.vllm_flash_attn.flash_attn_interface import (
import importlib.machinery
import os
import sys
import types
# In symlink mode (VLLM_FLASH_ATTN_SRC_DIR), cute/ is a symlink to the real
# source tree and its files use `flash_attn.cute.*` imports (not rewritten).
# Register a virtual `flash_attn` package so those imports resolve.
_cute_dir = os.path.join(os.path.dirname(__file__), "cute")
if os.path.islink(_cute_dir) and "flash_attn" not in sys.modules:
_fa_mod = types.ModuleType("flash_attn")
_fa_mod.__path__ = [os.path.dirname(os.path.realpath(_cute_dir))]
_fa_mod.__package__ = "flash_attn"
_fa_mod.__spec__ = importlib.machinery.ModuleSpec(
"flash_attn", None, is_package=True
)
_fa_mod.__spec__.submodule_search_locations = _fa_mod.__path__
sys.modules["flash_attn"] = _fa_mod
from vllm.vllm_flash_attn.flash_attn_interface import ( # noqa: E402
FA2_AVAILABLE,
FA3_AVAILABLE,
fa_version_unsupported_reason,