Skip to content

Commit 7ccaaa0

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 495304d commit 7ccaaa0

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

neural_compressor/adaptor/torch_utils/waq/smooth_quant.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def _parse_absorb_to_layers(self, op_types, folding):
363363
input_mins, input_maxes = calib.calibrate(
364364
1, op_types
365365
) ##TODO if using qfunc for calibration, it will calibrate twice
366-
#use qfunc to calibrate, the input min could be used for fixed alpha transformation
366+
# use qfunc to calibrate, the input min could be used for fixed alpha transformation
367367
self.input_mins = input_mins
368368
self.input_maxes = input_maxes
369369
diff_modules = set(self.absorb_to_layer.keys()).difference(input_mins.keys())
@@ -434,7 +434,7 @@ def transform(
434434
for key in self.input_mins.keys():
435435
input_maxes_abs[key] = torch.max(torch.abs(self.input_mins[key]), torch.abs(self.input_maxes[key]))
436436
if self.q_func:
437-
self.need_calibration = False # Avoid double-calibration in fixed-value alpha SQ.
437+
self.need_calibration = False # Avoid double-calibration in fixed-value alpha SQ.
438438

439439
if self.absorb_to_layer is None:
440440
logger.warning("empty absorb_to_layer, smoothquant is ignored ")
@@ -458,7 +458,7 @@ def transform(
458458
self.alpha = auto_alpha_tuner.tune()
459459
input_maxes_abs = auto_alpha_tuner.input_maxes_abs
460460
self.input_mins, self.input_maxes = auto_alpha_tuner.input_mins, auto_alpha_tuner.input_maxes
461-
if auto_alpha_tuner.loss_type == 'blockwise':
461+
if auto_alpha_tuner.loss_type == "blockwise":
462462
self.block_names = auto_alpha_tuner.block_names
463463

464464
elif self.need_calibration:

test/algorithm/test_smooth_quant.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,12 +1537,20 @@ def forward(self, x):
15371537
"alpha_min": 0.5,
15381538
"alpha_max": 0.9,
15391539
"alpha_step": 0.1,
1540-
"shared_criterion": 'mean',
1540+
"shared_criterion": "mean",
15411541
"init_alpha": 0.7,
1542-
"n_samples": 32
1542+
"n_samples": 32,
15431543
}
1544-
alpha_tuner = AutoAlpha(model, sq.dataloader, sq.absorb_to_layer, op_types=[torch.nn.Linear, torch.nn.Conv2d], \
1545-
device=sq.device, q_func=sq.q_func, example_inputs=sq.example_inputs, **auto_alpha_args)
1544+
alpha_tuner = AutoAlpha(
1545+
model,
1546+
sq.dataloader,
1547+
sq.absorb_to_layer,
1548+
op_types=[torch.nn.Linear, torch.nn.Conv2d],
1549+
device=sq.device,
1550+
q_func=sq.q_func,
1551+
example_inputs=sq.example_inputs,
1552+
**auto_alpha_args,
1553+
)
15461554
tuned_alpha = alpha_tuner.tune()
15471555
assert alpha_tuner.init_alpha == 0.7
15481556
assert alpha_tuner.alpha_min == 0.5
@@ -1563,12 +1571,7 @@ def test_sq_linear_Blockwise_auto(self):
15631571
"shared_criterion": "mean",
15641572
"do_blockwise": True,
15651573
}
1566-
sq.transform(
1567-
alpha="auto",
1568-
calib_iter=1,
1569-
folding=False,
1570-
auto_alpha_args=auto_alpha_args
1571-
)
1574+
sq.transform(alpha="auto", calib_iter=1, folding=False, auto_alpha_args=auto_alpha_args)
15721575
for i in range(12):
15731576
op_name1 = "model.decoder.layers." + str(i) + ".self_attn.out_proj"
15741577
op_name2 = "model.decoder.layers." + str(i) + ".fc1"

0 commit comments

Comments
 (0)