Skip to content

Commit

Permalink
Update quantizers tests
Browse files Browse the repository at this point in the history
  • Loading branch information
james77777778 committed Mar 7, 2024
1 parent 792545a commit 1d124bb
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions keras/quantizers/quantizers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ def test_abs_max_quantizer(self):
values = random.uniform([3, 4, 5], minval=-1, maxval=1)
quantizer = quantizers.AbsMaxQuantizer(axis=-1)

# Test quantize
# Test quantizing
quantized_values, scale = quantizer(values)
self.assertEqual(quantized_values.shape, [3, 4, 5])
self.assertEqual(scale.shape, [3, 4, 1])
self.assertEqual(tuple(quantized_values.shape), (3, 4, 5))
self.assertEqual(tuple(scale.shape), (3, 4, 1))
self.assertLessEqual(ops.max(quantized_values), 127)
self.assertGreaterEqual(ops.min(quantized_values), -127)

# Test dequantize
# Test dequantizing
dequantized_values = ops.divide(quantized_values, scale)
self.assertAllClose(values, dequantized_values, atol=1)
rmse = ops.sqrt(
ops.mean(ops.square(ops.subtract(values, dequantized_values)))
)
self.assertLess(rmse, 1e-1) # loose assertion

# Test serialization
self.run_class_serialization_test(quantizer)

0 comments on commit 1d124bb

Please sign in to comment.