@@ -143,13 +143,12 @@ def quantize_dequantize_weight(w, n_bit):
143
143
w_q_asym , s_asym , zp_asym = quantize_tensor (
144
144
w , (1 ,), n_bit = n_bit , symmetric = False
145
145
)
146
- # print(f"w_q_asym {w_q_asym}, s_asym {s_asym}, zp_asym {zp_asym}")
147
146
w_dq_asym = dequantize_tensor (w_q_asym , s_asym , zp_asym )
148
- # print(f"w_dq_asym {w_dq_asym}")
149
- # self._print_diff(w, w_dq)
150
- # self._print_diff(w, w_dq_asym)
151
147
# Asymmetric is more accurate than symmetric.
152
- self .assertLess ((w - w_dq_asym ).norm (), (w - w_dq ).norm ())
148
+ self .assertLess (
149
+ (w - w_dq_asym ).norm (),
150
+ (w - w_dq ).norm (),
151
+ )
153
152
# Blockwise quant.
154
153
w_block_q , s_block , _ = quantize_tensor (
155
154
w , (1 ,), n_bit = n_bit , symmetric = True , block_size = 2
@@ -169,7 +168,9 @@ def quantize_dequantize_weight(w, n_bit):
169
168
# Blockwise asymmetric is more accurate than blockwise symmetric.
170
169
self .assertLess ((w - w_block_asym_dq ).norm (), (w - w_block_dq ).norm ())
171
170
172
- w = torch .randn (2 , 8 )
171
+ w = (
172
+ torch .randn (2 , 8 ) + 2
173
+ ) # Add a bias to normal dist to test asymmetric quant.
173
174
for bit in [4 , 8 ]:
174
175
with self .subTest (bit = bit ):
175
176
quantize_dequantize_weight (w , bit )
0 commit comments