|
|
|
@ -35,7 +35,7 @@ class TestFakeQuantizeOp(OpTest):
|
|
|
|
|
self.check_output()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFakeQuantizeOp(OpTest):
|
|
|
|
|
class TestFakeQuantizeRangeAbsMaxOp(OpTest):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.op_type = "fake_quantize_range_abs_max"
|
|
|
|
|
self.attrs = {
|
|
|
|
@ -43,8 +43,10 @@ class TestFakeQuantizeOp(OpTest):
|
|
|
|
|
'window_size': int(1),
|
|
|
|
|
'is_test': False
|
|
|
|
|
}
|
|
|
|
|
x = (np.random.random((8, 16, 7, 7)) - 0.5) * 10
|
|
|
|
|
x = x.astype("float32")
|
|
|
|
|
self.inputs = {
|
|
|
|
|
'X': np.random.random((8, 16, 7, 7)).astype("float32"),
|
|
|
|
|
'X': x,
|
|
|
|
|
'Iter': np.zeros(1).astype("int64"),
|
|
|
|
|
'InScale': np.zeros(1).astype("float32")
|
|
|
|
|
}
|
|
|
|
@ -62,5 +64,36 @@ class TestFakeQuantizeOp(OpTest):
|
|
|
|
|
self.check_output()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestFakeQuantizeRangeAbsMaxOp2(OpTest):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
self.op_type = "fake_quantize_range_abs_max"
|
|
|
|
|
self.attrs = {
|
|
|
|
|
'bit_length': int(8),
|
|
|
|
|
'window_size': int(1),
|
|
|
|
|
'is_test': True
|
|
|
|
|
}
|
|
|
|
|
x = (np.random.random((8, 16, 7, 7)) - 0.5) * 10
|
|
|
|
|
x = x.astype("float32")
|
|
|
|
|
scale = np.max(np.abs(x)).astype("float32") - 1.0
|
|
|
|
|
out_scales = np.zeros(self.attrs['window_size']).astype("float32")
|
|
|
|
|
out_scales[0] = scale
|
|
|
|
|
|
|
|
|
|
self.inputs = {
|
|
|
|
|
'X': x,
|
|
|
|
|
'Iter': np.zeros(1).astype("int64"),
|
|
|
|
|
'InScale': scale.astype("float32")
|
|
|
|
|
}
|
|
|
|
|
xs = np.clip(x, -scale, scale)
|
|
|
|
|
qs = np.round(xs / scale * ((1 << (self.attrs['bit_length'] - 1)) - 1))
|
|
|
|
|
self.outputs = {
|
|
|
|
|
'Out': qs,
|
|
|
|
|
'OutScale': scale.astype("float32"),
|
|
|
|
|
'OutScales': out_scales,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def test_check_output(self):
|
|
|
|
|
self.check_output(no_check_set=set(['OutScale', 'OutScales']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
unittest.main()
|
|
|
|
|