@@ -143,18 +143,9 @@ 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
- print ((w - w_dq_asym ))
153
- print ((w - w_dq ))
154
- self .assertLess (
155
- (w - w_dq_asym ).to (torch .float32 ).norm (),
156
- (w - w_dq ).to (torch .float32 ).norm (),
157
- )
148
+ self .assertLess ((w - w_dq_asym ).norm (), (w - w_dq ).norm (),)
158
149
# Blockwise quant.
159
150
w_block_q , s_block , _ = quantize_tensor (
160
151
w , (1 ,), n_bit = n_bit , symmetric = True , block_size = 2
@@ -174,7 +165,7 @@ def quantize_dequantize_weight(w, n_bit):
174
165
# Blockwise asymmetric is more accurate than blockwise symmetric.
175
166
self .assertLess ((w - w_block_asym_dq ).norm (), (w - w_block_dq ).norm ())
176
167
177
- w = torch .randn (2 , 8 )
168
+ w = torch .randn (2 , 8 ) + 2 # Add a bias to normal dist to test asymmetric quant.
178
169
for bit in [4 , 8 ]:
179
170
with self .subTest (bit = bit ):
180
171
quantize_dequantize_weight (w , bit )
0 commit comments