apeforest commented on a change in pull request #14749: [Mxnet-1397] Support 
symbolic api for requantize and dequantize
URL: https://github.com/apache/incubator-mxnet/pull/14749#discussion_r277123578
 
 

 ##########
 File path: tests/python/quantization/test_quantization.py
 ##########
 @@ -63,19 +63,45 @@ def test_quantize_float32_to_int8():
 
 @with_seed()
 def test_dequantize_int8_to_float32():
+
+    def get_test_data(real_range, qdata_np):
+        qdata = mx.nd.array(qdata_np, dtype=np.int8)
+        min_range = mx.nd.array([-real_range], dtype=np.float32)
+        max_range = mx.nd.array([real_range], dtype=np.float32)
+        return qdata, min_range, max_range
+
+    def baseline_dequantization(qdata, real_range, qdata_np):
+        quantized_range = 127.0
+        scale = real_range / quantized_range
+        data_np = qdata_np * scale
+        return data_np
+
+    def test_nd_array_dequantization(qdata, min_range, max_range, 
expected_result):
+        data = mx.nd.contrib.dequantize(qdata, min_range, max_range, 
out_type='float32')
+        assert data.dtype == np.float32
+        assert_almost_equal(data.asnumpy(), expected_result)
+
+    def test_symbolic_api_dequantization(qdata, min_range, max_range, 
expected_result):
+        sym_data = mx.sym.Variable('data')
+        sym_min_range = mx.sym.Variable('min_range')
+        sym_max_range = mx.sym.Variable('max_range')
+        dequant = mx.sym.contrib.dequantize(sym_data, sym_min_range, 
+                                     sym_max_range, out_type='float32')
+        out = dequant.bind(ctx=mx.cpu(), args={'data':qdata, 
'min_range':min_range, 
 
 Review comment:
   use ctx=mx.current_context() so this test can cover both CPU and GPU 
computation?
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to