Skip to content

Commit

Permalink
Support AWQ quantization with bias (#2117)
Browse files Browse the repository at this point in the history
When the AWQ quantizer was used with a layer that uses a bias,
the bias tensor was not correctly passed/used. Instead, the
value `true`/`1.0` was added to the linear transformation.

Correctly pass through the bias when it is not `None`.

Fixes #2106.
  • Loading branch information
danieldk authored Jun 25, 2024
1 parent 04e1af9 commit 14980df
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions server/text_generation_server/layers/awq/quantize/qmodule.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copied logic from https://github.com/mit-han-lab/llm-awq/blob/f084f40bd996f3cf3a0633c1ad7d9d476c318aaa/awq/quantize/qmodule.py

import math
from typing import Optional
import torch
import torch.nn as nn
import awq_inference_engine # with CUDA kernels
Expand All @@ -17,7 +18,9 @@


class WQLinear(nn.Module):
def __init__(self, w_bit, group_size, qweight, qzeros, scales, bias):
def __init__(
self, w_bit, group_size, qweight, qzeros, scales, bias: Optional[torch.Tensor]
):
super().__init__()

if w_bit not in [4]:
Expand All @@ -35,10 +38,7 @@ def __init__(self, w_bit, group_size, qweight, qzeros, scales, bias):
self.qweight = qweight
self.qzeros = qzeros
self.scales = scales
if bias:
self.bias = bias
else:
self.bias = None
self.bias = bias

@torch.no_grad()
def forward(self, x):
Expand Down
2 changes: 1 addition & 1 deletion server/text_generation_server/layers/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def get_linear(weight, bias, quantize):
qweight=weight.qweight,
qzeros=weight.qzeros,
scales=weight.scales,
bias=bias is not None,
bias=bias,
)
except ImportError:
raise NotImplementedError(
Expand Down

0 comments on commit 14980df

Please sign in to comment.