MCPcopy Create free account
hub / github.com/TabbyML/tabby / test_fp16_weights

Function test_fp16_weights

python/tests/test_spec.py:166–195  ·  view source on GitHub ↗
(
    quantization, expected_weight, expected_weight_scale, expected_bias
)

Source from the content-addressed store, hash-verified

164 ],
165)
166def test_fp16_weights(
167 quantization, expected_weight, expected_weight_scale, expected_bias
168):
169 class Spec(ctranslate2.specs.LayerSpec):
170 def __init__(self, weight, bias):
171 self.weight = weight
172 self.weight_scale = OPTIONAL
173 self.bias = bias
174
175 weight = np.array([[-10, -3, 5, 2]], dtype=np.float16)
176 bias = np.array([4], dtype=np.float16)
177
178 spec = Spec(weight, bias)
179 spec.validate()
180 spec.optimize(quantization=quantization)
181
182 assert test_utils.array_equal(spec.weight.numpy(), expected_weight)
183 assert test_utils.array_equal(spec.bias.numpy(), expected_bias)
184
185 # Check the weights were not copied or converted.
186 if quantization in (None, "float16"):
187 assert spec.weight.numpy() is weight
188 assert spec.bias.numpy() is bias
189 elif quantization in ("int8", "int8_float16"):
190 assert spec.bias.numpy() is bias
191
192 if expected_weight_scale is None:
193 assert spec.weight_scale == OPTIONAL
194 else:
195 assert test_utils.array_equal(spec.weight_scale.numpy(), expected_weight_scale)
196
197
198def test_index_spec():

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