Skip to content

Commit 08064a5

Browse files
committed
Document AWQ chunked scale-search branches
1 parent d5b2665 commit 08064a5

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

gptqmodel/looper/awq_processor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,9 @@ def _search_best_scale(
849849
if "use_cache" in kwargs:
850850
kwargs.pop("use_cache")
851851

852+
# Keep AWQ scale search on the low-memory path by default. Disabling this
853+
# restores the legacy eager behavior that materializes full activations on
854+
# the module device before loss evaluation.
852855
use_chunked_scale_search = getattr(self.qcfg, "scale_search_chunked_activations", True)
853856

854857
# [STEP 1]: Compute per-channel mean of normalised weights
@@ -893,12 +896,17 @@ def _search_best_scale(
893896
module_kwargs.setdefault(key, value)
894897

895898
if use_chunked_scale_search:
899+
# Build the FP reference output one micro-batch at a time and move each
900+
# chunk back to CPU immediately so scale search does not keep the full
901+
# activation tensor resident on GPU.
896902
with ctx(torch.inference_mode()):
897903
fp16_output = [
898904
output.clip(torch.finfo(output.dtype).min, torch.finfo(output.dtype).max).detach().cpu()
899905
for output in self._iter_module_forward_outputs(inp, module2inspect, module_kwargs)
900906
]
901907
else:
908+
# Legacy path: run the full forward eagerly on the module device and keep
909+
# the dense activation tensor for the later reconstruction-loss pass.
902910
inp = inp.to(next(module2inspect.parameters()).device)
903911
with ctx(torch.inference_mode()):
904912
fp16_output = self._module_forward(inp, module2inspect, module_kwargs)
@@ -1138,6 +1146,9 @@ def _compute_best_scale(
11381146
if prev_scale_hint is not None:
11391147
w_mean = w_mean * float(prev_scale_hint)
11401148

1149+
# This flag also controls how each candidate scale is scored: either stream
1150+
# ref/int outputs chunk-by-chunk for lower memory, or reuse the legacy eager
1151+
# tensor-vs-tensor loss computation.
11411152
use_chunked_scale_search = getattr(self.qcfg, "scale_search_chunked_activations", True)
11421153

11431154
for ratio in range(n_grid):
@@ -1166,6 +1177,9 @@ def _compute_best_scale(
11661177

11671178
# W * X
11681179
if use_chunked_scale_search:
1180+
# Compare chunked reference outputs against chunked quantized outputs
1181+
# so reconstruction loss is accumulated without assembling the full
1182+
# output activation on GPU.
11691183
total_loss = 0.0
11701184
total_elements = 0
11711185
for ref_chunk, int_w_output in zip(
@@ -1180,6 +1194,8 @@ def _compute_best_scale(
11801194

11811195
loss = total_loss / max(total_elements, 1)
11821196
else:
1197+
# Legacy eager scoring path: compute one dense quantized output tensor
1198+
# and evaluate loss against the dense FP reference tensor.
11831199
int_w_output = self._module_forward(x, module2inspect, kwargs)
11841200
int_w_output = int_w_output.clip(torch.finfo(int_w_output.dtype).min, torch.finfo(int_w_output.dtype).max)
11851201
loss = self._compute_loss(fp16_output, int_w_output, device)

0 commit comments

Comments
 (0)