[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2025-11-25 15:20:18 +00:00
commit e7acd095eb
4 changed files with 24 additions and 13 deletions

View file

@ -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"

View file

@ -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(

View file

@ -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.

View file

@ -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]