(
tmp_dir, variable_dtype, quantization, expected_weight_dtype, expected_bias_dtype
)
| 277 | ], |
| 278 | ) |
| 279 | def 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) |
nothing calls this directly
no test coverage detected