/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/int8_gen_quant_params_test.py (3550B)
# Copyright (c) 2016-present, Facebook, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ############################################################################## import caffe2.python.hypothesis_test_util as hu import hypothesis.strategies as st import numpy as np from caffe2.python import core, workspace from caffe2.quantization.server import dnnlowp_pybind11 from hypothesis import given, settings class TestInt8GenQuantParamsOperator(hu.HypothesisTestCase): @settings(max_examples=20, deadline=None) @given( n=st.integers(10, 100), m=st.integers(1, 128), k=st.integers(64, 1024), quantization_kind=st.sampled_from( [ "MIN_MAX_QUANTIZATION", "L2_MIN_QUANTIZATION_APPROX", "L2_MIN_QUANTIZATION", "P99_QUANTIZATION" ] ), preserve_sparsity=st.booleans(), rnd_seed=st.integers(1, 5), **hu.gcs_cpu_only ) def test_int8_gen_quant_params_op( self, n, m, k, quantization_kind, preserve_sparsity, rnd_seed, gc, dc ): assert n > 0, "Zero samples in the input data" X_min = 0 if preserve_sparsity else -77 X_max = X_min + 255 np.random.seed(rnd_seed) X = np.round(np.random.rand(n, m, k) * (X_max - X_min) + X_min).astype( np.float32 ) # Calculate X_qparam hist, bin_edges = np.histogram(X.flatten(), bins=2048) X_qparam = dnnlowp_pybind11.ChooseStaticQuantizationParams( np.min(X), np.max(X), hist, preserve_sparsity, 8, quantization_kind ) # Build a net to generate X's qparam using the Int8GenQuantParams op workspace.FeedBlob("X", X, device_option=gc) dnnlowp_pybind11.CreateInt8QuantSchemeBlob( "quant_scheme", quantization_kind, preserve_sparsity ) assert workspace.HasBlob( "quant_scheme" ), "Failed to create the quant_scheme blob in current workspace" gen_quant_params_net = core.Net("gen_quant_params") gen_quant_params_op = core.CreateOperator( "Int8GenQuantParams", ["X", "quant_scheme"], ["quant_param"], device_option=gc, ) gen_quant_params_net.Proto().op.extend([gen_quant_params_op]) assert workspace.RunNetOnce( gen_quant_params_net ), "Failed to run the gen_quant_params net" scale, zero_point = dnnlowp_pybind11.ObserveInt8QuantParamsBlob("quant_param") shapes, types = workspace.InferShapesAndTypes( [gen_quant_params_net], blob_dimensions={"X": [n, m, k], "quant_scheme": [1]}, blob_types={"X": core.DataType.FLOAT, "quant_scheme": core.DataType.STRING} ) self.assertEqual(shapes["quant_param"], [1]) self.assertEqual(types["quant_param"], core.DataType.FLOAT) np.testing.assert_equal(scale, X_qparam.scale) np.testing.assert_equal(zero_point, X_qparam.zero_point)