Skip to content

Align scale dtype with model precision in GPTQ #2403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions torchao/quantization/GPTQ/GPTQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def __torch_function__(
SQNR(DQ, DQ_from_qtensor),
)

qparams2 = cls.get_qparams_func(W)
qparams2 = cls.get_qparams_func(W, W.dtype)
Q2 = cls.quantize_func(W, qparams2)
DQ2 = cls.dequantize_func(Q2, qparams2).to(W.dtype)
old_q_out = (
Expand Down Expand Up @@ -444,7 +444,9 @@ def faster_quant(cls, H, W, device):
group_end = min(group_start + group_size, columns)
if group_start % group_size == 0:
# needed for when group_size == columns so only calculate qparams once
cur_qparams = cls.get_qparams_func(W[:, group_start:group_end])
cur_qparams = cls.get_qparams_func(
W[:, group_start:group_end], orig_dtype
)
all_qparams.append(cur_qparams)

for index in range(group_start, group_end): # within each group
Expand Down Expand Up @@ -679,10 +681,11 @@ def __init__(
else:
self.zero_point_domain = ZeroPointDomain.FLOAT

self.get_qparams_func = lambda w: get_groupwise_affine_qparams(
self.get_qparams_func = lambda w, precision: get_groupwise_affine_qparams(
w,
n_bit,
group_size,
dtype=precision,
zero_point_domain=self.zero_point_domain,
)
self.quantize_func = (
Expand Down
Loading