mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 17:24:32 +02:00
remove dequantize_symmetric_with_bias
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user