From daa13cf3ade875cd0b88cc3f45555bda827aeaa2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Mar 2026 07:10:47 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- unsloth/kernels/fp8.py | 25 ++++++++++++++++--------- unsloth/models/_utils.py | 5 +++++ unsloth/models/loader_utils.py | 5 +---- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/unsloth/kernels/fp8.py b/unsloth/kernels/fp8.py index b7fb43adb1..a1d88444e6 100644 --- a/unsloth/kernels/fp8.py +++ b/unsloth/kernels/fp8.py @@ -628,9 +628,9 @@ def module_forward_patch(forward_function, scale_attr = "weight_scale"): def _compressed_linear_supports_unsloth_fp8(self): if ( - CompressedLinear is None or - QuantizationStrategy is None or - QuantizationStatus is None + CompressedLinear is None + or QuantizationStrategy is None + or QuantizationStatus is None ): return False @@ -639,10 +639,10 @@ def _compressed_linear_supports_unsloth_fp8(self): quantization_scheme = getattr(self, "quantization_scheme", None) quantization_args = getattr(quantization_scheme, "weights", None) if ( - weight is None or - weight_scale is None or - quantization_args is None or - weight.dtype != torch.float8_e4m3fn + weight is None + or weight_scale is None + or quantization_args is None + or weight.dtype != torch.float8_e4m3fn ): return False @@ -679,6 +679,7 @@ def _compressed_linear_forward_fallback(self, input): weight_data = self.compressor.decompress_module(self) param = nn.Parameter(weight_data, requires_grad = False) from compressed_tensors.utils import register_offload_parameter + register_offload_parameter(self, "weight", param) self.quantization_status = QuantizationStatus.FROZEN @@ -715,7 +716,11 @@ def _fp8_moe_lora_extractor(wrapper, weight_A, weight_B, scaling, num_experts): param_name = getattr(wrapper, "parameter_name", None) - if param_name == "down_proj" and intermediate_dim is not None and hidden_dim is not None: + if ( + param_name == "down_proj" + and intermediate_dim is not None + and hidden_dim is not None + ): first_weight = weight_B.view(dim_B, num_experts, rank_per_expert) first_weight = first_weight.permute(1, 0, 2).contiguous() second_weight = weight_A.view(num_experts, rank_per_expert, dim_A) @@ -764,7 +769,9 @@ def _patch_fp8_moe_experts(): experts_interface["grouped_mm"] = forward_moe_backend experts_interface["batched_mm"] = forward_native_moe_loop if hasattr(finegrained_fp8, "FP8Experts"): - finegrained_fp8.FP8Experts._unsloth_lora_extractor_fn = staticmethod(_fp8_moe_lora_extractor) + finegrained_fp8.FP8Experts._unsloth_lora_extractor_fn = staticmethod( + _fp8_moe_lora_extractor + ) # Patch the forward functions of the layers (for compiled models) diff --git a/unsloth/models/_utils.py b/unsloth/models/_utils.py index 9eddab9f71..37d3e9a2bc 100644 --- a/unsloth/models/_utils.py +++ b/unsloth/models/_utils.py @@ -94,13 +94,18 @@ import functools import textwrap import logging import warnings, subprocess, inspect, psutil, os, math + try: from transformers.utils import auto_docstring except: + def auto_docstring(*args, **kwargs): def decorator(obj): return obj + return decorator + + from unsloth_zoo.utils import Version, get_quant_type from importlib.metadata import version as importlib_version from ..device_type import ( diff --git a/unsloth/models/loader_utils.py b/unsloth/models/loader_utils.py index 113506e73c..c5c417b0b2 100644 --- a/unsloth/models/loader_utils.py +++ b/unsloth/models/loader_utils.py @@ -454,10 +454,7 @@ def _get_fp8_mode_and_check_settings( assert load_in_fp8 is not False if load_in_fp8 is True: fp8_mode = "row" # default - if ( - not fast_inference - and os.environ.get("UNSLOTH_HAS_FBGEMM", "0") != "1" - ): + if not fast_inference and os.environ.get("UNSLOTH_HAS_FBGEMM", "0") != "1": fp8_mode = "block" else: fp8_mode = load_in_fp8