fix(_utils): coerce _is_package_available tuple to bool for flash_attn/vllm checks (#6168)
transformers >= 5.x makes _is_package_available always return a (exists, version) tuple, which is truthy even when the package is absent. The flash_attn and vLLM availability checks treated the result as a bool, so they always entered the "package present" branch: - flash_attn (CUDA + HIP): the inner import raises when flash-attn is not installed, printing a false "Flash Attention 2 installation seems to be broken" warning before falling back to xformers. - is_vLLM_available(): always reported vLLM as installed. Add a small _package_available() helper that normalises the result to a bool (handling both the new tuple and the legacy bool return), and route the three call sites through it. Fixes #6155 Co-authored-by: Lee Jackson <130007945+Imagineer99@users.noreply.github.com>
This commit is contained in:
parent
3964f44f02
commit
73eed19ce4
1 changed files with 15 additions and 3 deletions
|
|
@ -1264,6 +1264,18 @@ if is_openai_available():
|
|||
from transformers import AutoTokenizer
|
||||
from transformers.utils.import_utils import _is_package_available
|
||||
|
||||
|
||||
def _package_available(pkg_name: str) -> bool:
|
||||
# transformers >= 5.x makes `_is_package_available` always return a
|
||||
# `(exists, version)` tuple, which is truthy even when the package is
|
||||
# absent; older versions returned a plain bool. Normalise to a bool so
|
||||
# callers don't take "package present" branches for missing packages.
|
||||
result = _is_package_available(pkg_name)
|
||||
if isinstance(result, tuple):
|
||||
return bool(result[0])
|
||||
return bool(result)
|
||||
|
||||
|
||||
SUPPORTS_BFLOAT16 = False
|
||||
HAS_FLASH_ATTENTION = False
|
||||
HAS_FLASH_ATTENTION_SOFTCAPPING = False
|
||||
|
|
@ -1274,7 +1286,7 @@ if DEVICE_TYPE == "cuda":
|
|||
|
||||
if major_version >= 8:
|
||||
SUPPORTS_BFLOAT16 = True
|
||||
if _is_package_available("flash_attn"):
|
||||
if _package_available("flash_attn"):
|
||||
# Check for CUDA linking errors "undefined symbol: _ZNK3c106SymIntltEl"
|
||||
try:
|
||||
try:
|
||||
|
|
@ -1319,7 +1331,7 @@ if DEVICE_TYPE == "cuda":
|
|||
HAS_FLASH_ATTENTION = False
|
||||
elif DEVICE_TYPE == "hip":
|
||||
SUPPORTS_BFLOAT16 = True
|
||||
if _is_package_available("flash_attn"):
|
||||
if _package_available("flash_attn"):
|
||||
# Check for CUDA linking errors "undefined symbol: _ZNK3c106SymIntltEl"
|
||||
try:
|
||||
try:
|
||||
|
|
@ -1981,7 +1993,7 @@ def is_bfloat16_supported():
|
|||
|
||||
|
||||
def is_vLLM_available():
|
||||
return _is_package_available("vllm")
|
||||
return _package_available("vllm")
|
||||
|
||||
|
||||
# Patches models to add RoPE Scaling
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue