Skip to content

Commit 18f23fb

Browse files
committed
Simplify clip selection
Signed-off-by: Andrea Fasoli <[email protected]>
1 parent cd000d9 commit 18f23fb

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

fms_mo/calib.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ def __call__(self, module, inputs: torch.Tensor):
9090
x.reshape(1, -1).kthvalue(int(self.per[1] * nelem)).values.data[0]
9191
)
9292
if symmetric:
93-
upper_per_cur = (
94-
upper_per_cur_candidate
95-
if upper_per_cur_candidate > lower_per_cur_candidate.abs()
96-
else lower_per_cur_candidate.abs()
93+
upper_per_cur = max(
94+
upper_per_cur_candidate,
95+
lower_per_cur_candidate.abs(),
9796
)
9897
lower_per_cur = -upper_per_cur
9998
else:

fms_mo/quant/quantizers.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,11 +3574,7 @@ def forward(self, input_tensor):
35743574
) # for very small tensor, lower_k could be 0, kthvalue(0) will cause error
35753575

35763576
if self.symmetric:
3577-
cv_new = (
3578-
cv_new_candidate
3579-
if cv_new_candidate > cvn_new_candidate.abs()
3580-
else cvn_new_candidate.abs()
3581-
)
3577+
cv_new = max(cv_new_candidate, cvn_new_candidate.abs())
35823578
cvn_new = -cv_new
35833579
else:
35843580
cv_new = cv_new_candidate

0 commit comments

Comments
 (0)