MCPcopy Create free account
hub / github.com/OpenNMT/CTranslate2 / test_int8_quantization

Function test_int8_quantization

python/tests/test_spec.py:101–116  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

99
100
101def 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(

Callers

nothing calls this directly

Calls 4

SpecClass · 0.85
optimizeMethod · 0.80
validateMethod · 0.45
numpyMethod · 0.45

Tested by

no test coverage detected