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

Function test_torch_variables

python/tests/test_spec.py:279–310  ·  view source on GitHub ↗
(
    tmp_dir, variable_dtype, quantization, expected_weight_dtype, expected_bias_dtype
)

Source from the content-addressed store, hash-verified

277 ],
278)
279def test_torch_variables(
280 tmp_dir, variable_dtype, quantization, expected_weight_dtype, expected_bias_dtype
281):
282 import torch
283
284 if expected_weight_dtype is None:
285 expected_weight_dtype = variable_dtype
286 if expected_bias_dtype is None:
287 expected_bias_dtype = variable_dtype
288
289 variable_dtype = getattr(torch, variable_dtype)
290
291 class TorchModel(ctranslate2.specs.ModelSpec):
292 def __init__(self):
293 super().__init__()
294 self.dense = common_spec.LinearSpec()
295 self.dense.weight = torch.ones([16, 4], dtype=variable_dtype)
296 self.dense.bias = torch.ones([16], dtype=variable_dtype)
297
298 @property
299 def name(self):
300 return "TorchModel"
301
302 model = TorchModel()
303 model.validate()
304 model.optimize(quantization)
305
306 variables = model.variables()
307 assert variables["dense/weight"].dtype == expected_weight_dtype
308 assert variables["dense/bias"].dtype == expected_bias_dtype
309
310 model.save(tmp_dir)

Callers

nothing calls this directly

Calls 5

TorchModelClass · 0.85
optimizeMethod · 0.80
variablesMethod · 0.80
validateMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected