/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
caffe2
/
quantization
/
server
/
/usr/local/lib64/python3.6/site-packages/caffe2/quantization/server
mkdir
upload
Name
Size
Mode
Actions
__pycache__/
-
0755
rm
batch_matmul_dnnlowp_op_test.py
10152
0644
edit
dl
rm
batch_permutation_dnnlowp_op_test.py
1449
0644
edit
dl
rm
channel_shuffle_dnnlowp_op_test.py
3890
0644
edit
dl
rm
compute_equalization_scale_test.py
3154
0644
edit
dl
rm
concat_dnnlowp_op_test.py
3265
0644
edit
dl
rm
conv_depthwise_dnnlowp_op_test.py
10931
0644
edit
dl
rm
conv_dnnlowp_acc16_op_test.py
14202
0644
edit
dl
rm
conv_dnnlowp_op_test.py
17919
0644
edit
dl
rm
conv_groupwise_dnnlowp_acc16_op_test.py
11664
0644
edit
dl
rm
conv_groupwise_dnnlowp_op_test.py
9537
0644
edit
dl
rm
dequantize_dnnlowp_op_test.py
1743
0644
edit
dl
rm
dnnlowp_test_utils.py
14544
0644
edit
dl
rm
elementwise_add_dnnlowp_op_test.py
6662
0644
edit
dl
rm
elementwise_linear_dnnlowp_op_test.py
3101
0644
edit
dl
rm
elementwise_mul_dnnlowp_op_test.py
6315
0644
edit
dl
rm
elementwise_sum_dnnlowp_op_test.py
9682
0644
edit
dl
rm
fully_connected_dnnlowp_acc16_op_test.py
8324
0644
edit
dl
rm
fully_connected_dnnlowp_op_test.py
10463
0644
edit
dl
rm
fully_connected_fp16_test.py
2519
0644
edit
dl
rm
fully_connected_rowwise_dnnlowp_op_test.py
5434
0644
edit
dl
rm
gather_dnnlowp_op_test.py
2790
0644
edit
dl
rm
group_norm_dnnlowp_op_test.py
4566
0644
edit
dl
rm
int8_gen_quant_params_min_max_test.py
3491
0644
edit
dl
rm
int8_gen_quant_params_test.py
3550
0644
edit
dl
rm
int8_quant_scheme_blob_fill_test.py
1838
0644
edit
dl
rm
lstm_unit_dnnlowp_op_test.py
3975
0644
edit
dl
rm
observer_test.py
1011
0644
edit
dl
rm
pool_dnnlowp_op_test.py
6125
0644
edit
dl
rm
quantize_dnnlowp_op_test.py
2668
0644
edit
dl
rm
relu_dnnlowp_op_test.py
2418
0644
edit
dl
rm
resize_nearest_3d_dnnlowp_op_test.py
2289
0644
edit
dl
rm
resize_nearest_dnnlowp_op_test.py
1994
0644
edit
dl
rm
sigmoid_dnnlowp_op_test.py
2203
0644
edit
dl
rm
spatial_batch_norm_dnnlowp_op_test.py
4094
0644
edit
dl
rm
tanh_dnnlowp_op_test.py
2187
0644
edit
dl
rm
utils.py
16059
0644
edit
dl
rm
__init__.py
0
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/caffe2/quantization/server/fully_connected_fp16_test.py
(2519B)
import collections import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, dyndep, workspace from hypothesis import given dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", "--caffe2_omp_num_threads=11"]) def mse(x, xh): d = (x - xh).reshape(-1) return 0 if len(d) == 0 else np.sqrt(np.matmul(d, d.transpose())) / len(d) class FullyConnectedFP16Test(hu.HypothesisTestCase): @given( input_channels=st.integers(128, 256), output_channels=st.integers(128, 256), batch_size=st.integers(128, 256), empty_batch=st.booleans(), **hu.gcs_cpu_only ) def test_fully_connected(self, input_channels, output_channels, batch_size, empty_batch, gc, dc): if empty_batch: batch_size = 0 W = np.random.randn(output_channels, input_channels).astype(np.float32) X = np.random.randn(batch_size, input_channels).astype(np.float32) b = np.random.randn(output_channels).astype(np.float32) Output = collections.namedtuple("Output", ["Y", "engine", "order"]) order = "NHWC" net = core.Net("test_net") engine = "FAKE_FP16" fc = core.CreateOperator( "FC", ["X", "W", "b"], ["Y"], order=order, engine=engine, device_option=gc ) net.Proto().op.extend([fc]) self.ws.create_blob("X").feed(X, device_option=gc) self.ws.create_blob("W").feed(W, device_option=gc) self.ws.create_blob("b").feed(b, device_option=gc) self.ws.run(net) output = Output(Y=self.ws.blobs["Y"].fetch(), engine=engine, order=order) # Mimic the quantization in python Wh = W.astype(np.float16) Xh = X.astype(np.float16) bh = b.astype(np.float16) bbh = np.outer(np.ones(batch_size, dtype=np.float16), bh) assert bbh.dtype == np.float16 Yrefh = np.matmul(Xh, Wh.transpose()) + bbh assert Yrefh.dtype == np.float16 bb = np.outer(np.ones(batch_size, dtype=np.float32), b) Yref = np.matmul(X, W.transpose()) + bb assert Yref.dtype == np.float32 # The error between plain->quantized, and plain->python_quantized # should be very close mse_c2 = mse(Yref, output.Y) mse_py = mse(Yref, Yrefh) print(np.abs(mse_c2 - mse_py)) assert np.isclose(mse_c2, mse_py, atol=1e-3), np.abs(mse_c2 - mse_py)
Save
cmd:
run