From b85e7d04888105b26c9f17e966366b3d2b86d3d4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Mar 2026 10:01:35 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- unsloth/models/_utils.py | 21 ++++++++++++++++----- unsloth/models/llama.py | 4 +++- unsloth/models/vision.py | 2 +- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index 822b93a465..b7fa8d5dec 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -226,10 +226,16 @@ def determine_attention_implementation(model_class, config): model_type = getattr(config, "model_type", "").lower() # 1. Flash Attention 2 - if HAS_FLASH_ATTENTION and model_type not in ("gpt_oss", "mllama") and not model_type.startswith("gemma3"): + if ( + HAS_FLASH_ATTENTION + and model_type not in ("gpt_oss", "mllama") + and not model_type.startswith("gemma3") + ): supports_fa2 = False if model_class is not None: - supports_fa2 = getattr(model_class, "_supports_flash_attn_2", False) or getattr(model_class, "_supports_flash_attn", False) + supports_fa2 = getattr( + model_class, "_supports_flash_attn_2", False + ) or getattr(model_class, "_supports_flash_attn", False) if supports_fa2: if config is not None: @@ -243,8 +249,10 @@ def determine_attention_implementation(model_class, config): try: from transformers.utils.import_utils import is_torch_flex_attn_available - if is_torch_flex_attn_available() and (model_class is not None) and getattr( - model_class, "_supports_flex_attn", False + if ( + is_torch_flex_attn_available() + and (model_class is not None) + and getattr(model_class, "_supports_flex_attn", False) ): # GPT-OSS, Mllama and Gemma3 use eager/sdpa attention during # inference since flex attention returns incorrect results or errors out. @@ -254,7 +262,10 @@ def determine_attention_implementation(model_class, config): # decode q_len=1, causing ValueError. Needs transformers update. # Gemma3N: timm vision wrappers (eg Gemma3nVisionConfig) do not # support flex_attention. - if model_type not in ("gpt_oss", "mllama") and not model_type.startswith("gemma3"): + if model_type not in ( + "gpt_oss", + "mllama", + ) and not model_type.startswith("gemma3"): if config is not None: setattr(config, "_attn_implementation", "flex_attention") if hasattr(config, "attn_implementation"): diff --git a/unsloth/models/llama.py b/unsloth/models/llama.py index ee6fc7021a..8e3892c712 100644 --- a/unsloth/models/llama.py +++ b/unsloth/models/llama.py @@ -2341,7 +2341,9 @@ class FastLlamaModel: model_function = MODEL_FOR_CAUSAL_LM_MAPPING[model_config.__class__] IS_FALCON_H1 = model_config.model_type.startswith("falcon_h1") - preferred_attn_impl = determine_attention_implementation(model_function, model_config) + preferred_attn_impl = determine_attention_implementation( + model_function, model_config + ) has_rope_scaling = False try: diff --git a/unsloth/models/vision.py b/unsloth/models/vision.py index 94186da2f0..c44a77eff0 100644 --- a/unsloth/models/vision.py +++ b/unsloth/models/vision.py @@ -608,7 +608,7 @@ class FastBaseModel: model_class = auto_model._model_mapping[auto_config.__class__] except Exception: model_class = None - + attn_impl = determine_attention_implementation(model_class, auto_config) # Handle FP8 models: get_model_name has already redirected this to BF16 sibling if the model ships with