mirror of
https://github.com/vladmandic/automatic
synced 2026-09-07 05:20:47 +02:00
lint
This commit is contained in:
@@ -357,9 +357,8 @@ if use_torch_compile:
|
||||
kwargs["fullgraph"] = True
|
||||
if kwargs.get("dynamic", None) is None:
|
||||
kwargs["dynamic"] = False
|
||||
if torch_version[0] > 2 or (torch_version[0] == 2 and torch_version[1] >= 12):
|
||||
if kwargs.get("recompile_limit", None) is None:
|
||||
kwargs["recompile_limit"] = max(8192, getattr(torch._dynamo.config, "recompile_limit", 0))
|
||||
if (torch_version[0] > 2 or (torch_version[0] == 2 and torch_version[1] >= 12)) and kwargs.get("recompile_limit", None) is None:
|
||||
kwargs["recompile_limit"] = max(8192, getattr(torch._dynamo.config, "recompile_limit", 0))
|
||||
if os.environ.get("SDNQ_COMPILE_KWARGS", None) is not None:
|
||||
for key, value in json.loads(os.environ.get("SDNQ_COMPILE_KWARGS")).items():
|
||||
kwargs[key] = value
|
||||
|
||||
@@ -19,7 +19,7 @@ def load_safetensors(files: list[str], state_dict: dict | None = None, key_mappi
|
||||
state_dict = {}
|
||||
for fn in files:
|
||||
with safe_open(fn, framework="pt", device=str(device)) as f:
|
||||
for key in f.keys():
|
||||
for key in f:
|
||||
state_dict[map_keys(key, key_mapping)] = f.get_tensor(key)
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class SDNQLayer(torch.nn.Module):
|
||||
return self.forward_func(self, *args, **kwargs)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"{self.__class__.__name__}(original_class={self.original_class} forward_func={self.forward_func} sdnq_dequantizer={repr(getattr(self, 'sdnq_dequantizer', None))})"
|
||||
return f"{self.__class__.__name__}(original_class={self.original_class} forward_func={self.forward_func} sdnq_dequantizer={getattr(self, 'sdnq_dequantizer', None)})"
|
||||
|
||||
|
||||
class SDNQLinear(SDNQLayer, torch.nn.Linear):
|
||||
|
||||
@@ -168,9 +168,8 @@ def load_sdnq_model(
|
||||
# older transformers case, handle known models manually
|
||||
if model.__class__.__name__ in {"T5EncoderModel", "UMT5EncoderModel"} and "encoder.embed_tokens.weight" not in state_dict:
|
||||
state_dict["encoder.embed_tokens.weight"] = state_dict["shared.weight"]
|
||||
elif model.__class__.__name__ in {"Qwen3ForCausalLM"} and "lm_head.weight" not in state_dict:
|
||||
if "model.embed_tokens.weight" in state_dict:
|
||||
state_dict["lm_head.weight"] = state_dict["model.embed_tokens.weight"]
|
||||
elif model.__class__.__name__ in {"Qwen3ForCausalLM"} and "lm_head.weight" not in state_dict and "model.embed_tokens.weight" in state_dict:
|
||||
state_dict["lm_head.weight"] = state_dict["model.embed_tokens.weight"]
|
||||
|
||||
model.load_state_dict(state_dict, assign=True)
|
||||
del state_dict
|
||||
|
||||
@@ -130,6 +130,8 @@ def rotate_hadamard(weight: torch.Tensor, group_size: int = 256, hadamard: torch
|
||||
hadamard = get_hadamard(group_size, dtype=weight.dtype, device=weight.device)
|
||||
else:
|
||||
group_size = hadamard.shape[-1]
|
||||
if hadamard.dtype != weight.dtype:
|
||||
hadamard = hadamard.to(dtype=weight.dtype)
|
||||
if is_conv:
|
||||
weight_shape = list(weight.shape)[1:]
|
||||
weight = weight.flatten(1,-1)
|
||||
|
||||
@@ -375,7 +375,7 @@ def sdnq_quantize_layer_weight_dynamic(
|
||||
if quantization_loss <= dynamic_loss_threshold:
|
||||
del original_weight_fp32
|
||||
if quantization_config is not None:
|
||||
if sdnq_dequantizer.weights_dtype not in quantization_config.modules_dtype_dict.keys():
|
||||
if sdnq_dequantizer.weights_dtype not in quantization_config.modules_dtype_dict:
|
||||
quantization_config.modules_dtype_dict[sdnq_dequantizer.weights_dtype] = [param_name]
|
||||
else:
|
||||
quantization_config.modules_dtype_dict[sdnq_dequantizer.weights_dtype].append(param_name)
|
||||
@@ -570,7 +570,7 @@ class SDNQQuantize:
|
||||
missing_keys: list[str] | None = None,
|
||||
**kwargs,
|
||||
) -> dict[str, torch.Tensor]:
|
||||
_module_name, value = tuple(input_dict.items())[0]
|
||||
_module_name, value = next(iter(input_dict.items()))
|
||||
value = value[0]
|
||||
self.hf_quantizer.create_quantized_param(model, value, full_layer_name, value.device)
|
||||
param, name = get_module_from_name(model, full_layer_name)
|
||||
@@ -1001,7 +1001,7 @@ class SDNQConfig(QuantizationConfigMixin):
|
||||
value = list(value)
|
||||
self.modules_dtype_dict[key] = value
|
||||
if not isinstance(key, str) or not isinstance(value, list):
|
||||
raise ValueError(f"modules_dtype_dict must be a dictionary of strings and lists but got {type(key)} and {type(value)}")
|
||||
raise TypeError(f"modules_dtype_dict must be a dictionary of strings and lists but got {type(key)} and {type(value)}")
|
||||
|
||||
if self.modules_quant_config is None:
|
||||
self.modules_quant_config = {}
|
||||
|
||||
@@ -80,7 +80,7 @@ def get_quant_args_from_config(quantization_config: dict) -> dict:
|
||||
quantization_config_dict.pop("is_training", None)
|
||||
quantization_config_dict.pop("sdnq_version", None)
|
||||
if quantization_config_dict.get("modules_quant_config", None) is not None:
|
||||
for key in quantization_config_dict["modules_quant_config"].keys():
|
||||
for key in quantization_config_dict["modules_quant_config"]:
|
||||
quantization_config_dict["modules_quant_config"][key] = get_quant_args_from_config(quantization_config_dict["modules_quant_config"][key])
|
||||
return quantization_config_dict
|
||||
|
||||
@@ -90,7 +90,7 @@ def get_minimum_dtype(weights_dtype: str, param_name: str, modules_dtype_dict: d
|
||||
for key, value in modules_dtype_dict.items():
|
||||
if check_param_name_in(param_name, value) is not None:
|
||||
key = key.lower()
|
||||
if key.startswith("minimum") or key.endswith("bit") or key.endswith("bits"):
|
||||
if key.startswith("minimum") or key.endswith(("bit", "bits")):
|
||||
minimum_bits_str = key.removeprefix("minimum").removeprefix("-").removeprefix("_").removesuffix("bits").removesuffix("bit").removesuffix("-").removesuffix("_")
|
||||
if minimum_bits_str.startswith("uint"):
|
||||
is_unsigned = True
|
||||
@@ -189,7 +189,7 @@ def add_module_skip_keys(model: torch.nn.Module, quantization_config):
|
||||
if skip_key_list is not None:
|
||||
quantization_config.modules_to_not_convert.extend(skip_key_list[0])
|
||||
for key, value in skip_key_list[1].items():
|
||||
if key in quantization_config.modules_dtype_dict.keys():
|
||||
if key in quantization_config.modules_dtype_dict:
|
||||
quantization_config.modules_dtype_dict[key].extend(value)
|
||||
else:
|
||||
quantization_config.modules_dtype_dict[key] = value
|
||||
|
||||
Reference in New Issue
Block a user