/usr/local/lib64/python3.6/site-packages/caffe2/quantization/server
NameSizeModeActions
__pycache__/-0755rm
batch_matmul_dnnlowp_op_test.py101520644editdlrm
batch_permutation_dnnlowp_op_test.py14490644editdlrm
channel_shuffle_dnnlowp_op_test.py38900644editdlrm
compute_equalization_scale_test.py31540644editdlrm
concat_dnnlowp_op_test.py32650644editdlrm
conv_depthwise_dnnlowp_op_test.py109310644editdlrm
conv_dnnlowp_acc16_op_test.py142020644editdlrm
conv_dnnlowp_op_test.py179190644editdlrm
conv_groupwise_dnnlowp_acc16_op_test.py116640644editdlrm
conv_groupwise_dnnlowp_op_test.py95370644editdlrm
dequantize_dnnlowp_op_test.py17430644editdlrm
dnnlowp_test_utils.py145440644editdlrm
elementwise_add_dnnlowp_op_test.py66620644editdlrm
elementwise_linear_dnnlowp_op_test.py31010644editdlrm
elementwise_mul_dnnlowp_op_test.py63150644editdlrm
elementwise_sum_dnnlowp_op_test.py96820644editdlrm
fully_connected_dnnlowp_acc16_op_test.py83240644editdlrm
fully_connected_dnnlowp_op_test.py104630644editdlrm
fully_connected_fp16_test.py25190644editdlrm
fully_connected_rowwise_dnnlowp_op_test.py54340644editdlrm
gather_dnnlowp_op_test.py27900644editdlrm
group_norm_dnnlowp_op_test.py45660644editdlrm
int8_gen_quant_params_min_max_test.py34910644editdlrm
int8_gen_quant_params_test.py35500644editdlrm
int8_quant_scheme_blob_fill_test.py18380644editdlrm
lstm_unit_dnnlowp_op_test.py39750644editdlrm
observer_test.py10110644editdlrm
pool_dnnlowp_op_test.py61250644editdlrm
quantize_dnnlowp_op_test.py26680644editdlrm
relu_dnnlowp_op_test.py24180644editdlrm
resize_nearest_3d_dnnlowp_op_test.py22890644editdlrm
resize_nearest_dnnlowp_op_test.py19940644editdlrm
sigmoid_dnnlowp_op_test.py22030644editdlrm
spatial_batch_norm_dnnlowp_op_test.py40940644editdlrm
tanh_dnnlowp_op_test.py21870644editdlrm
utils.py160590644editdlrm
__init__.py00644editdlrm
Edit: /usr/local/lib64/python3.6/site-packages/caffe2/quantization/server/lstm_unit_dnnlowp_op_test.py (3975B)
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, settings dyndep.InitOpsLibrary("//caffe2/caffe2/quantization/server:dnnlowp_ops") workspace.GlobalInit(["caffe2", "--caffe2_omp_num_threads=11"]) class DNNLowPLSTMUnitOpTest(hu.HypothesisTestCase): @given( N=st.integers(0, 64), D=st.integers(4, 64), forget_bias=st.integers(0, 4), **hu.gcs_cpu_only ) @settings(max_examples=10, deadline=None) def test_dnnlowp_lstm_unit(self, N, D, forget_bias, gc, dc): # X has scale 1, so exactly represented after quantization H_in = np.clip(np.random.randn(1, N, D), -1, 1).astype(np.float32) C_in = np.clip(np.random.randn(1, N, D), -1, 1).astype(np.float32) G = np.clip(np.random.randn(1, N, 4 * D), -1, 1).astype(np.float32) seq_lengths = np.round(np.random.rand(N)).astype(np.int32) # seq_lengths.fill(0) t = np.array([5]).astype(np.int32) Output = collections.namedtuple("Output", ["H_out", "C_out", "engine"]) outputs = [] engine_list = ["", "DNNLOWP"] for engine in engine_list: net = core.Net("test_net") if engine == "DNNLOWP": quantize_H_in = core.CreateOperator( "Quantize", ["H_in"], ["H_in_q"], engine=engine, device_option=gc ) quantize_C_in = core.CreateOperator( "Quantize", ["C_in"], ["C_in_q"], engine=engine, device_option=gc ) quantize_G = core.CreateOperator( "Quantize", ["G"], ["G_q"], engine=engine, device_option=gc ) net.Proto().op.extend([quantize_H_in, quantize_C_in, quantize_G]) lstm = core.CreateOperator( "LSTMUnit", [ "H_in_q" if engine == "DNNLOWP" else "H_in", "C_in_q" if engine == "DNNLOWP" else "C_in", "G_q" if engine == "DNNLOWP" else "G", "seq_lengths", "t", ], [ "H_out_q" if engine == "DNNLOWP" else "H_out", "C_out_q" if engine == "DNNLOWP" else "C_out", ], engine=engine, device_option=gc, axis=0, ) net.Proto().op.extend([lstm]) if engine == "DNNLOWP": dequantize_H_out = core.CreateOperator( "Dequantize", ["H_out_q"], ["H_out"], engine=engine, device_option=gc, ) dequantize_C_out = core.CreateOperator( "Dequantize", ["C_out_q"], ["C_out"], engine=engine, device_option=gc, ) net.Proto().op.extend([dequantize_H_out, dequantize_C_out]) self.ws.create_blob("H_in").feed(H_in, device_option=gc) self.ws.create_blob("C_in").feed(C_in, device_option=gc) self.ws.create_blob("G").feed(G, device_option=gc) self.ws.create_blob("seq_lengths").feed(seq_lengths, device_option=gc) self.ws.create_blob("t").feed(t, device_option=gc) self.ws.run(net) outputs.append( Output( H_out=self.ws.blobs["H_out"].fetch(), C_out=self.ws.blobs["C_out"].fetch(), engine=engine, ) ) for o in outputs: np.testing.assert_allclose(o.C_out, outputs[0].C_out, atol=0.1, rtol=0.2) np.testing.assert_allclose(o.H_out, outputs[0].H_out, atol=0.1, rtol=0.2)