/
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/pool_dnnlowp_op_test.py
(6125B)
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 caffe2.quantization.server.dnnlowp_test_utils import check_quantized_results_close from hypothesis import assume, given dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", "--caffe2_omp_num_threads=11"]) class DNNLowPOpPoolTest(hu.HypothesisTestCase): @given( stride=st.integers(1, 3), pad=st.integers(0, 3), kernel=st.integers(1, 5), size=st.integers(1, 20), input_channels=st.integers(1, 3), batch_size=st.integers(1, 3), order=st.sampled_from(["NCHW", "NHWC"]), in_quantized=st.booleans(), **hu.gcs_cpu_only ) def test_dnnlowp_max_pool( self, stride, pad, kernel, size, input_channels, batch_size, order, in_quantized, gc, dc, ): assume(kernel <= size) assume(pad < kernel) C = input_channels N = batch_size H = W = size min_ = -10 max_ = 20 if order == "NCHW": X = np.round(np.random.rand(N, C, H, W) * (max_ - min_) + min_) elif order == "NHWC": X = np.round(np.random.rand(N, H, W, C) * (max_ - min_) + min_) X = X.astype(np.float32) Output = collections.namedtuple("Output", ["Y", "op_type", "engine"]) outputs = [] op_engine_list = [ ("MaxPool", ""), ("MaxPool", "DNNLOWP"), ("Int8MaxPool", "DNNLOWP"), ] for op_type, engine in op_engine_list: net = core.Net("test_net") do_quantize = "DNNLOWP" in engine and in_quantized if do_quantize: quantize = core.CreateOperator( "Quantize", ["X"], ["X_q"], engine=engine, device_option=gc ) net.Proto().op.extend([quantize]) max_pool = core.CreateOperator( op_type, ["X_q" if do_quantize else "X"], ["Y_q" if engine == "DNNLOWP" else "Y"], stride=stride, kernel=kernel, pad=pad, order=order, engine=engine, device_option=gc, ) net.Proto().op.extend([max_pool]) if engine == "DNNLOWP": dequantize = core.CreateOperator( "Dequantize", ["Y_q"], ["Y"], engine=engine, device_option=gc ) net.Proto().op.extend([dequantize]) self.ws.create_blob("X").feed(X, device_option=gc) self.ws.run(net) outputs.append( Output(Y=self.ws.blobs["Y"].fetch(), op_type=op_type, engine=engine) ) # Y_i = max(X_j) so the only error is in quantization of inputs check_quantized_results_close(outputs, ref=X) @given( ndim=st.integers(2, 3), stride=st.integers(1, 1), pad=st.integers(0, 0), kernel=st.integers(1, 5), size=st.integers(2, 2), input_channels=st.integers(1, 1), batch_size=st.integers(2, 2), order=st.sampled_from(["NCHW", "NHWC"]), in_quantized=st.booleans(), **hu.gcs_cpu_only ) def test_dnnlowp_average_pool( self, ndim, stride, pad, kernel, size, input_channels, batch_size, order, in_quantized, gc, dc, ): kernel = 2 # Only kernel size 2 is supported assume(kernel <= size) assume(pad < kernel) C = input_channels N = batch_size strides = (stride,) * ndim pads = (pad,) * (ndim * 2) kernels = (kernel,) * ndim sizes = (size,) * ndim # X has scale 1, so no input quantization error min_ = -100 max_ = min_ + 255 if order == "NCHW": X = np.round(np.random.rand(*((N, C) + sizes)) * (max_ - min_) + min_) X = X.astype(np.float32) X[(0,) * (ndim + 2)] = min_ X[(0,) * (ndim + 1) + (1,)] = max_ elif order == "NHWC": X = np.round(np.random.rand(*((N,) + sizes + (C,))) * (max_ - min_) + min_) X = X.astype(np.float32) X[(0,) * (ndim + 2)] = min_ X[(0, 1) + (0,) * ndim] = max_ Output = collections.namedtuple("Output", ["Y", "op_type", "engine"]) outputs = [] op_engine_list = [ ("AveragePool", ""), ("AveragePool", "DNNLOWP"), ("Int8AveragePool", "DNNLOWP"), ] for op_type, engine in op_engine_list: net = core.Net("test_net") do_quantize = "DNNLOWP" in engine and in_quantized if do_quantize: quantize = core.CreateOperator( "Quantize", ["X"], ["X_q"], engine=engine, device_option=gc ) net.Proto().op.extend([quantize]) max_pool = core.CreateOperator( op_type, ["X_q" if do_quantize else "X"], ["Y_q" if engine == "DNNLOWP" else "Y"], strides=strides, kernels=kernels, pads=pads, order=order, engine=engine, device_option=gc, ) net.Proto().op.extend([max_pool]) if engine == "DNNLOWP": dequantize = core.CreateOperator( "Dequantize", ["Y_q"], ["Y"], engine=engine, device_option=gc ) net.Proto().op.extend([dequantize]) self.ws.create_blob("X").feed(X, device_option=gc) self.ws.run(net) outputs.append( Output(Y=self.ws.blobs["Y"].fetch(), op_type=op_type, engine=engine) ) check_quantized_results_close(outputs)
Save
cmd:
run