| 99 | |
| 100 | |
| 101 | def test_int8_quantization(): |
| 102 | class Spec(ctranslate2.specs.LayerSpec): |
| 103 | def __init__(self): |
| 104 | self.weight = np.array([[-10, -3, 5, 2], [0, 0, 0, 0]], dtype=np.float32) |
| 105 | self.weight_scale = OPTIONAL |
| 106 | |
| 107 | spec = Spec() |
| 108 | spec.validate() |
| 109 | spec.optimize(quantization="int8") |
| 110 | assert test_utils.array_equal( |
| 111 | spec.weight.numpy(), |
| 112 | np.array([[-127, -38, 64, 25], [0, 0, 0, 0]], dtype=np.int8), |
| 113 | ) |
| 114 | assert test_utils.array_equal( |
| 115 | spec.weight_scale.numpy(), np.array([12.7, 1], dtype=np.float32) |
| 116 | ) |
| 117 | |
| 118 | |
| 119 | @pytest.mark.parametrize( |