Skip to content

Commit e7b915f

Browse files
k-arima-3150S4Y-K
andauthored
fix: quantizer unit test fixes and tighten GPTQ thresholds (#21)
* [fix] ensure y_replaced for q/k/v projections in quantizer module test * [test] tighten error thresholds in GPTQ quantization tests * [update] CHANGELOG for v1.1.0+hotfix/unit_test: fix quantizer module forward test and tighten GPTQ test thresholds * [refactor] extract duplicated forward pass into TestModel.forward() in test_module.py * [update] CHANGELOG for v1.1.0+hotfix/unit_test: add test infrastructure entry for extracting duplicated forward pass into TestModel.forward() --------- Co-authored-by: sikoji <seiichiro.kojio@compmind.co.jp>
1 parent e93bab3 commit e7b915f

3 files changed

Lines changed: 33 additions & 36 deletions

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66

77
- Added `.pre-commit-config.yaml` with `black`, `isort`, and local hooks (`no-japanese`, `copyright-header`, `no-email-address`); install with `uv sync --extra dev` then `pre-commit install` (see README)
88

9+
### Quantizer module forward test fix
10+
11+
- Fixed `tests/onecomp/quantizer/test_module.py` to feed `y_replaced` consistently into `q_proj` / `k_proj` / `v_proj` after quantized weights are applied, aligning the replacement-path forward test with the intended residual update flow
12+
13+
### GPTQ quantization test thresholds
14+
15+
- Tightened GPTQ unit test tolerances in `tests/onecomp/quantizer/gptq/test_gptq.py` so regressions in dequantized-weight error are detected earlier (`error < 0.4`, `max_error < 1.71`; previously `0.6` / `2.5`)
16+
17+
### Test infrastructure
18+
19+
- Extracted the duplicated attention+MLP forward loop in `test_quantize_error` into `TestModel.forward()` (`tests/onecomp/quantizer/test_module.py`); both the pre-quantization and post-quantization inference paths now call `model(inp)` directly, eliminating 34 duplicate lines
20+
921
## [v1.1.1] 2026-05-21
1022

1123
### New Feature: Quantization progress logging

tests/onecomp/quantizer/gptq/test_gptq.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ def check_quantize_error(self, error, max_error):
164164
Thresholds are set for FP16 dequantized weights returned by
165165
compute_dequantized_weight().
166166
"""
167-
assert error < 0.6
168-
assert max_error < 2.5
167+
assert error < 0.4
168+
assert max_error < 1.71
169169

170170
def check_forward_error(
171171
self,

tests/onecomp/quantizer/test_module.py

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,23 @@ def __init__(self, hidden_size=2048):
9393
)
9494

9595
def forward(self, x):
96-
"""Forward pass is not needed for quantization tests."""
97-
pass
96+
y = x
97+
for layer in self.model.layers:
98+
q = layer.self_attn.q_proj(y)
99+
k = layer.self_attn.k_proj(y)
100+
v = layer.self_attn.v_proj(y)
101+
head_dim = k.shape[-1]
102+
qk = torch.matmul(q, k.transpose(-2, -1)) / (head_dim**0.5)
103+
attn_weights = torch.nn.functional.softmax(qk, dim=-1)
104+
v = torch.matmul(attn_weights, v)
105+
attn_out = layer.self_attn.o_proj(v)
106+
107+
gate = torch.nn.functional.silu(layer.mlp.gate_proj(y))
108+
up = layer.mlp.up_proj(y)
109+
mlp_out = layer.mlp.down_proj(gate * up)
110+
111+
y = y + attn_out + mlp_out
112+
return y
98113

99114

100115
class BaseQuantizeSpec:
@@ -291,22 +306,7 @@ def test_quantize_error(self, helper):
291306
)
292307

293308
with torch.no_grad():
294-
y_original = inp
295-
for layer in model.model.layers:
296-
q = layer.self_attn.q_proj(y_original)
297-
k = layer.self_attn.k_proj(y_original)
298-
v = layer.self_attn.v_proj(y_original)
299-
head_dim = k.shape[-1]
300-
qk = torch.matmul(q, k.transpose(-2, -1)) / (head_dim**0.5)
301-
attn_weights = torch.nn.functional.softmax(qk, dim=-1)
302-
v = torch.matmul(attn_weights, v)
303-
attn_out = layer.self_attn.o_proj(v)
304-
305-
gate = torch.nn.functional.silu(layer.mlp.gate_proj(y_original))
306-
up = layer.mlp.up_proj(y_original)
307-
mlp_out = layer.mlp.down_proj(gate * up)
308-
309-
y_original = y_original + attn_out + mlp_out
309+
y_original = model(inp)
310310

311311
for layer in model.model.layers:
312312
for _, module_dict in [
@@ -330,22 +330,7 @@ def test_quantize_error(self, helper):
330330
model = model.to(device)
331331

332332
with torch.no_grad():
333-
y_replaced = inp
334-
for layer in model.model.layers:
335-
q = layer.self_attn.q_proj(y_original)
336-
k = layer.self_attn.k_proj(y_original)
337-
v = layer.self_attn.v_proj(y_original)
338-
head_dim = k.shape[-1]
339-
qk = torch.matmul(q, k.transpose(-2, -1)) / (head_dim**0.5)
340-
attn_weights = torch.nn.functional.softmax(qk, dim=-1)
341-
v = torch.matmul(attn_weights, v)
342-
attn_out = layer.self_attn.o_proj(v)
343-
344-
gate = torch.nn.functional.silu(layer.mlp.gate_proj(y_replaced))
345-
up = layer.mlp.up_proj(y_replaced)
346-
mlp_out = layer.mlp.down_proj(gate * up)
347-
348-
y_replaced = y_replaced + attn_out + mlp_out
333+
y_replaced = model(inp)
349334

350335
error = torch.norm(y_original - y_replaced) / torch.norm(y_original)
351336
max_error = torch.abs(y_original - y_replaced).max().item()

0 commit comments

Comments
 (0)