Skip to content

Commit 8be6dad

Browse files
committed
Merge branch 'fix/v0-5-0-rotation' into 'export/v0-5-0'
Fix: WeightQuantizer の groupsize>0 時の GPU メモリ爆発を修正 See merge request onecomp/onecomp-lab!40
2 parents 0f9ffd3 + f61f397 commit 8be6dad

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

onecomp/pre_process/quant_models.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ def find_params(self, x):
181181
self.zero = torch.round(q_min - x_min / self.scale).clamp(q_min, q_max)
182182

183183
if self.weight_groupsize > 0:
184-
self.scale = self.scale.repeat(1, 1, self.weight_groupsize).reshape(shape)
185-
self.zero = self.zero.repeat(1, 1, self.weight_groupsize).reshape(shape)
184+
pass
186185
elif self.perchannel:
187186
s = [-1] + [1] * (len(shape) - 1)
188187
self.scale = self.scale.reshape(s)
@@ -203,6 +202,14 @@ def quantize(self, x):
203202
"""
204203
x_dtype = x.dtype
205204
if self.ready() and self.bits < 16:
205+
if self.weight_groupsize > 0:
206+
orig_shape = x.shape
207+
x = x.reshape(-1, x.shape[-1] // self.weight_groupsize, self.weight_groupsize)
208+
if self.sym:
209+
x = STEQuantize.apply(x, self.scale, self.maxq)
210+
else:
211+
x = AsymSTEQuantize.apply(x, self.scale, self.zero, self.maxq)
212+
return x.reshape(orig_shape).to(x_dtype)
206213
if self.sym:
207214
return STEQuantize.apply(x, self.scale, self.maxq).to(x_dtype)
208215
return AsymSTEQuantize.apply(x, self.scale, self.zero, self.maxq).to(x_dtype)

0 commit comments

Comments
 (0)