[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
7e50c68edb
commit
daa13cf3ad
3 changed files with 22 additions and 13 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue