From e7acd095eba7070364ba1fc1514d412f79d0e4c8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 25 Nov 2025 15:20:18 +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 | 13 ++++++++----- unsloth/models/loader.py | 14 +++++++++----- unsloth/models/loader_utils.py | 9 +++++++-- unsloth/models/mapper.py | 1 - 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/unsloth/kernels/fp8.py b/unsloth/kernels/fp8.py index 7968c2c429..435a6e83d2 100644 --- a/unsloth/kernels/fp8.py +++ b/unsloth/kernels/fp8.py @@ -532,23 +532,26 @@ def test_has_fbgemm(): block_scale = torch.ones(M // 128, K // 128, dtype = torch.float32, device = "cuda") has_fbgemm = False try: - out = torch.ops.fbgemm.f8f8bf16_blockwise( - xq, wq, block_scale, block_scale - ) + out = torch.ops.fbgemm.f8f8bf16_blockwise(xq, wq, block_scale, block_scale) assert torch.unique(out).item() == 128 has_fbgemm = True del out except Exception as e: e = str(e) if "cutlass cannot initialize" in e.lower(): - print(f"Unsloth: FBGEMM on the current GPU cannot load - will switch to Triton kernels") + print( + f"Unsloth: FBGEMM on the current GPU cannot load - will switch to Triton kernels" + ) else: - print(f"Unsloth: FBGEMM on the current GPU cannot load with error = {e} - will switch to Triton kernels") + print( + f"Unsloth: FBGEMM on the current GPU cannot load with error = {e} - will switch to Triton kernels" + ) has_fbgemm = False del block_scale, xq torch.cuda.empty_cache() return has_fbgemm + fp8_block_quant_linear = fp8_torch_block_quant_forward if "UNSLOTH_HAS_FBGEMM" not in os.environ: os.environ["UNSLOTH_HAS_FBGEMM"] = "0" diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py index cbc5c51c5e..951bcb1e0c 100644 --- a/unsloth/models/loader.py +++ b/unsloth/models/loader.py @@ -223,7 +223,9 @@ class FastLanguageModel(FastLlamaModel): old_model_name = model_name fp8_mode = None if not use_exact_model_name: - new_model_name = get_model_name(model_name, load_in_4bit = load_in_4bit, load_in_fp8 = load_in_fp8) + new_model_name = get_model_name( + model_name, load_in_4bit = load_in_4bit, load_in_fp8 = load_in_fp8 + ) if new_model_name is None and load_in_fp8 != False: fp8_mode = _get_fp8_mode_and_check_settings( load_in_fp8, @@ -378,7 +380,7 @@ class FastLanguageModel(FastLlamaModel): if model_name.lower().endswith("-bf16"): load_in_4bit = False load_in_8bit = False - load_in_fp8 = False + load_in_fp8 = False load_in_16bit = True model_config = AutoConfig.from_pretrained( @@ -730,7 +732,9 @@ class FastModel(FastBaseModel): old_model_name = model_name fp8_mode = None if not use_exact_model_name: - new_model_name = get_model_name(model_name, load_in_4bit = load_in_4bit, load_in_fp8 = load_in_fp8) + new_model_name = get_model_name( + model_name, load_in_4bit = load_in_4bit, load_in_fp8 = load_in_fp8 + ) if new_model_name is None and load_in_fp8 != False: fp8_mode = _get_fp8_mode_and_check_settings( load_in_fp8, @@ -757,7 +761,7 @@ class FastModel(FastBaseModel): if model_name.lower().endswith("-bf16"): load_in_4bit = False load_in_8bit = False - load_in_fp8 = False + load_in_fp8 = False load_in_16bit = True # Check modelscope @@ -1018,7 +1022,7 @@ class FastModel(FastBaseModel): if model_name.lower().endswith("-bf16"): load_in_4bit = False load_in_8bit = False - load_in_fp8 = False + load_in_fp8 = False load_in_16bit = True model_config = AutoConfig.from_pretrained( diff --git a/unsloth/models/loader_utils.py b/unsloth/models/loader_utils.py index 0898b81cf4..7bcddde2d9 100644 --- a/unsloth/models/loader_utils.py +++ b/unsloth/models/loader_utils.py @@ -242,6 +242,7 @@ def _offline_quantize_to_fp8(model_name: str, fp8_mode: str) -> str: TorchAoConfig, AutoConfig, ) + qconfig = _get_torchao_fp8_config(fp8_mode) qconfig = TorchAoConfig(qconfig) config = AutoConfig.from_pretrained(model_name) @@ -334,11 +335,15 @@ def _get_fp8_mode_and_check_settings( and torch.version.cuda and torch.cuda.get_device_capability() >= (9, 0) ): - raise ValueError("Unsloth: On the fly `load_in_fp8` requires H100 GPUs or after. Try `unsloth/Qwen3-8B` instead.") + raise ValueError( + "Unsloth: On the fly `load_in_fp8` requires H100 GPUs or after. Try `unsloth/Qwen3-8B` instead." + ) # Check if torch >= 2.9.0 if Version(torch.__version__) < Version("2.9.0"): - raise ValueError("Unsloth: On the fly `load_in_fp8` requires torch 2.9.0+. Try `unsloth/Qwen3-8B` instead.") + raise ValueError( + "Unsloth: On the fly `load_in_fp8` requires torch 2.9.0+. Try `unsloth/Qwen3-8B` instead." + ) # Check if torchao has this PR: https://github.com/pytorch/ao/pull/3158, # which will be released in 0.15.0. diff --git a/unsloth/models/mapper.py b/unsloth/models/mapper.py index 522324524c..dcfe890e92 100644 --- a/unsloth/models/mapper.py +++ b/unsloth/models/mapper.py @@ -1281,7 +1281,6 @@ for key, values in __INT_TO_FLOAT_MAPPER.items(): for k in float8_values: FLOAT_TO_FP8_BLOCK_MAPPER[k.lower()] = block FLOAT_TO_FP8_ROW_MAPPER[k.lower()] = row - pass values = float16_values INT_TO_FLOAT_MAPPER[key] = values[0]