From 77c72e03aba96dcc252fe3425fe4ee00c9531728 Mon Sep 17 00:00:00 2001 From: Disty0 Date: Sat, 4 Jul 2026 19:09:25 +0300 Subject: [PATCH] remove dequantize_symmetric_with_bias --- modules/sdnq/dequantizer.py | 13 ------------- modules/sdnq/layers/conv/conv_fp16.py | 4 ++-- modules/sdnq/layers/conv/conv_fp8.py | 4 ++-- modules/sdnq/layers/conv/conv_int8.py | 4 ++-- modules/sdnq/layers/conv/conv_uint8.py | 4 ++-- modules/sdnq/layers/linear/linear_fp16.py | 4 ++-- modules/sdnq/layers/linear/linear_fp8.py | 4 ++-- modules/sdnq/layers/linear/linear_int8.py | 4 ++-- modules/sdnq/layers/linear/linear_uint8.py | 4 ++-- 9 files changed, 16 insertions(+), 29 deletions(-) diff --git a/modules/sdnq/dequantizer.py b/modules/sdnq/dequantizer.py index ebe7ad26e..141794cab 100644 --- a/modules/sdnq/dequantizer.py +++ b/modules/sdnq/dequantizer.py @@ -85,19 +85,6 @@ def dequantize_symmetric( return result -@devices.inference_context() -def dequantize_symmetric_with_bias(weight: torch.Tensor, scale: torch.FloatTensor, bias: torch.FloatTensor, hadamard: torch.FloatTensor | None = None, dtype: torch.dtype = None, result_shape: torch.Size = None) -> torch.FloatTensor: - if hadamard is not None: - result = rotate_hadamard(weight.to(dtype=scale.dtype).mul_(scale), hadamard=hadamard).add_(bias) - else: - result = torch.addcmul(bias, weight.to(dtype=scale.dtype), scale) - if dtype is not None: - result = result.to(dtype=dtype) - if result_shape is not None: - result = result.view(result_shape) - return result - - @devices.inference_context() def dequantize_packed_int_asymmetric(weight: torch.Tensor, scale: torch.FloatTensor, zero_point: torch.FloatTensor, shape: torch.Size, weights_dtype: str, svd_up: torch.FloatTensor | None = None, svd_down: torch.FloatTensor | None = None, hadamard: torch.FloatTensor | None = None, dtype: torch.dtype = None, result_shape: torch.Size = None, skip_quantized_matmul: bool = False, re_quantize_for_matmul: bool = False) -> torch.FloatTensor: return dequantize_asymmetric(unpack_int(weight, weights_dtype, shape), scale, zero_point, svd_up=svd_up, svd_down=svd_down, hadamard=hadamard, dtype=dtype, result_shape=result_shape, skip_quantized_matmul=skip_quantized_matmul, re_quantize_for_matmul=re_quantize_for_matmul) diff --git a/modules/sdnq/layers/conv/conv_fp16.py b/modules/sdnq/layers/conv/conv_fp16.py index 34d4944e7..83783e63b 100644 --- a/modules/sdnq/layers/conv/conv_fp16.py +++ b/modules/sdnq/layers/conv/conv_fp16.py @@ -3,7 +3,7 @@ import torch from ...common import compile_func, fp_mm_func -from ...dequantizer import dequantize_symmetric, dequantize_symmetric_with_bias +from ...dequantizer import dequantize_symmetric, dequantize_asymmetric from ...quant_utils import rotate_hadamard, get_hadamard from ...packed_float import unpack_float @@ -59,7 +59,7 @@ def conv_fp16_matmul( result.append(fp_mm_func(input[:, i], weight[:, i])) result = torch.cat(result, dim=-1).to(dtype=input_scale.dtype).mul_(input_scale) if bias is not None: - dequantize_symmetric_with_bias(result, scale, bias, dtype=return_dtype, result_shape=mm_output_shape) + dequantize_asymmetric(result, scale, bias, dtype=return_dtype, result_shape=mm_output_shape) else: dequantize_symmetric(result, scale, dtype=return_dtype, result_shape=mm_output_shape) diff --git a/modules/sdnq/layers/conv/conv_fp8.py b/modules/sdnq/layers/conv/conv_fp8.py index cfac41d35..23afc9cf3 100644 --- a/modules/sdnq/layers/conv/conv_fp8.py +++ b/modules/sdnq/layers/conv/conv_fp8.py @@ -3,7 +3,7 @@ import torch from ...common import compile_func -from ...dequantizer import dequantize_symmetric, dequantize_symmetric_with_bias +from ...dequantizer import dequantize_symmetric, dequantize_asymmetric from ...quant_utils import rotate_hadamard, get_hadamard from ...packed_float import unpack_float @@ -58,7 +58,7 @@ def conv_fp8_matmul( result.append(torch._scaled_mm(input[:, i], weight[:, i], scale_a=dummy_input_scale, scale_b=dummy_input_scale, bias=None, out_dtype=input_scale.dtype)) result = torch.cat(result, dim=-1).mul_(input_scale) if bias is not None: - dequantize_symmetric_with_bias(result, scale, bias, dtype=return_dtype, result_shape=mm_output_shape) + dequantize_asymmetric(result, scale, bias, dtype=return_dtype, result_shape=mm_output_shape) else: dequantize_symmetric(result, scale, dtype=return_dtype, result_shape=mm_output_shape) diff --git a/modules/sdnq/layers/conv/conv_int8.py b/modules/sdnq/layers/conv/conv_int8.py index 24411c135..e95ba9990 100644 --- a/modules/sdnq/layers/conv/conv_int8.py +++ b/modules/sdnq/layers/conv/conv_int8.py @@ -3,7 +3,7 @@ import torch from ...common import compile_func, int_mm_func -from ...dequantizer import dequantize_symmetric, dequantize_symmetric_with_bias +from ...dequantizer import dequantize_symmetric, dequantize_asymmetric from ...quant_utils import rotate_hadamard, get_hadamard from ...packed_int import unpack_int @@ -73,7 +73,7 @@ def conv_int8_matmul( result.append(int_mm_func(input[:, i], weight[:, i])) result = torch.cat(result, dim=-1).to(dtype=input_scale.dtype).mul_(input_scale) if bias is not None: - result = dequantize_symmetric_with_bias(result, scale, bias, dtype=return_dtype, result_shape=mm_output_shape) + result = dequantize_asymmetric(result, scale, bias, dtype=return_dtype, result_shape=mm_output_shape) else: result = dequantize_symmetric(result, scale, dtype=return_dtype, result_shape=mm_output_shape) diff --git a/modules/sdnq/layers/conv/conv_uint8.py b/modules/sdnq/layers/conv/conv_uint8.py index 3abc0fd8b..615430e55 100644 --- a/modules/sdnq/layers/conv/conv_uint8.py +++ b/modules/sdnq/layers/conv/conv_uint8.py @@ -3,7 +3,7 @@ import torch from ...common import compile_func, int_mm_func -from ...dequantizer import dequantize_symmetric, dequantize_symmetric_with_bias +from ...dequantizer import dequantize_asymmetric from ...quant_utils import rotate_hadamard, get_hadamard from ...packed_int import unpack_int @@ -75,7 +75,7 @@ def conv_uint8_matmul( for i in range(groups): result.append(int_mm_func(input[:, i], weight[:, i])) result = torch.cat(result, dim=-1).to(dtype=input_scale.dtype).mul_(input_scale) - result = dequantize_symmetric_with_bias(result, scale, zero_bias, dtype=return_dtype, result_shape=mm_output_shape) + result = dequantize_asymmetric(result, scale, zero_bias, dtype=return_dtype, result_shape=mm_output_shape) if conv_type == 1: result = result.transpose_(1,2) diff --git a/modules/sdnq/layers/linear/linear_fp16.py b/modules/sdnq/layers/linear/linear_fp16.py index 19d5c7d36..fcfec43f9 100644 --- a/modules/sdnq/layers/linear/linear_fp16.py +++ b/modules/sdnq/layers/linear/linear_fp16.py @@ -3,7 +3,7 @@ import torch from ...common import compile_func, fp_mm_func -from ...dequantizer import dequantize_symmetric, dequantize_symmetric_with_bias +from ...dequantizer import dequantize_symmetric, dequantize_asymmetric from ...quant_utils import rotate_hadamard, get_hadamard from ...packed_float import unpack_float @@ -40,7 +40,7 @@ def fp16_matmul( input, input_scale = quantize_fp_mm_input(input, dtype=scale.dtype, matmul_dtype="float16") input, weight = check_mats(input, weight) if bias is not None: - return dequantize_symmetric_with_bias(fp_mm_func(input, weight).to(dtype=input_scale.dtype).mul_(input_scale), scale, bias, dtype=return_dtype, result_shape=output_shape) + return dequantize_asymmetric(fp_mm_func(input, weight).to(dtype=input_scale.dtype).mul_(input_scale), scale, bias, dtype=return_dtype, result_shape=output_shape) else: return dequantize_symmetric(fp_mm_func(input, weight).to(dtype=input_scale.dtype).mul_(input_scale), scale, dtype=return_dtype, result_shape=output_shape) diff --git a/modules/sdnq/layers/linear/linear_fp8.py b/modules/sdnq/layers/linear/linear_fp8.py index e39d13a2e..4b5610e87 100644 --- a/modules/sdnq/layers/linear/linear_fp8.py +++ b/modules/sdnq/layers/linear/linear_fp8.py @@ -3,7 +3,7 @@ import torch from ...common import compile_func -from ...dequantizer import dequantize_symmetric, dequantize_symmetric_with_bias +from ...dequantizer import dequantize_symmetric, dequantize_asymmetric from ...quant_utils import quantize_fp_mm, rotate_hadamard, get_hadamard from ...packed_float import unpack_float @@ -48,7 +48,7 @@ def fp8_matmul( input, input_scale = quantize_fp_mm_input(input, dtype=scale.dtype) input, weight = check_mats(input, weight, allow_contiguous_mm=False) if bias is not None: - return dequantize_symmetric_with_bias(torch._scaled_mm(input, weight, scale_a=dummy_input_scale, scale_b=dummy_input_scale, bias=None, out_dtype=input_scale.dtype).mul_(input_scale), scale, bias, dtype=return_dtype, result_shape=output_shape) + return dequantize_asymmetric(torch._scaled_mm(input, weight, scale_a=dummy_input_scale, scale_b=dummy_input_scale, bias=None, out_dtype=input_scale.dtype).mul_(input_scale), scale, bias, dtype=return_dtype, result_shape=output_shape) else: return dequantize_symmetric(torch._scaled_mm(input, weight, scale_a=dummy_input_scale, scale_b=dummy_input_scale, bias=None, out_dtype=input_scale.dtype).mul_(input_scale), scale, dtype=return_dtype, result_shape=output_shape) diff --git a/modules/sdnq/layers/linear/linear_int8.py b/modules/sdnq/layers/linear/linear_int8.py index 89d65c9f6..ef9d33430 100644 --- a/modules/sdnq/layers/linear/linear_int8.py +++ b/modules/sdnq/layers/linear/linear_int8.py @@ -3,7 +3,7 @@ import torch from ...common import compile_func, int_mm_func -from ...dequantizer import dequantize_symmetric, dequantize_symmetric_with_bias +from ...dequantizer import dequantize_symmetric, dequantize_asymmetric from ...quant_utils import quantize_int_mm, rotate_hadamard, get_hadamard from ...packed_int import unpack_int @@ -67,7 +67,7 @@ def int8_matmul( input, weight = check_mats(input, weight) if bias is not None: - return dequantize_symmetric_with_bias(int_mm_func(input, weight).to(dtype=input_scale.dtype).mul_(input_scale), scale, bias, dtype=return_dtype, result_shape=output_shape) + return dequantize_asymmetric(int_mm_func(input, weight).to(dtype=input_scale.dtype).mul_(input_scale), scale, bias, dtype=return_dtype, result_shape=output_shape) else: return dequantize_symmetric(int_mm_func(input, weight).to(dtype=input_scale.dtype).mul_(input_scale), scale, dtype=return_dtype, result_shape=output_shape) diff --git a/modules/sdnq/layers/linear/linear_uint8.py b/modules/sdnq/layers/linear/linear_uint8.py index cacdcea5c..dd5f0a9e9 100644 --- a/modules/sdnq/layers/linear/linear_uint8.py +++ b/modules/sdnq/layers/linear/linear_uint8.py @@ -3,7 +3,7 @@ import torch from ...common import compile_func, int_mm_func -from ...dequantizer import dequantize_symmetric, dequantize_symmetric_with_bias +from ...dequantizer import dequantize_asymmetric from ...quant_utils import quantize_uint_mm, rotate_hadamard, get_hadamard from ...packed_int import unpack_int @@ -70,7 +70,7 @@ def uint8_matmul( zero_bias.add_(bias) input, weight = check_mats(input, weight) - return dequantize_symmetric_with_bias(int_mm_func(input, weight).to(dtype=input_scale.dtype).mul_(input_scale), scale, zero_bias, dtype=return_dtype, result_shape=output_shape) + return dequantize_asymmetric(int_mm_func(input, weight).to(dtype=input_scale.dtype).mul_(input_scale), scale, zero_bias, dtype=return_dtype, result_shape=output_shape) def quantized_linear_forward_uint8_matmul(self, input: torch.FloatTensor) -> torch.FloatTensor: