Test applying parametrization to multiple parameters in the same module.
(device, dtype)
| 304 | @pytest.mark.parametrize("dtype", [torch.float32, torch.float16, torch.bfloat16], ids=describe_dtype) |
| 305 | @pytest.mark.skipif(torch.__version__ < (2, 5), reason="state dict hook requires torch >= 2.5.0") |
| 306 | def test_multiple_parameters(device, dtype): |
| 307 | """Test applying parametrization to multiple parameters in the same module.""" |
| 308 | if device == "hpu" and not is_supported_on_hpu("nf4", dtype): |
| 309 | pytest.skip("Configuration not supported on HPU.") |
| 310 | |
| 311 | module = ParametrizeTestModule(device=device, dtype=dtype) |
| 312 | original_2d = module.weight_2d.clone() |
| 313 | original_3d = module.expert_weights.clone() |
| 314 | |
| 315 | # Apply parametrization to multiple parameters, with varying configurations |
| 316 | replace_parameter_4bit(module, "weight_2d", quant_type="nf4", blocksize=128) |
| 317 | replace_parameter_4bit(module, "expert_weights", quant_type="fp4", blocksize=256) |
| 318 | |
| 319 | # Verify both parameters are parametrized and work correctly |
| 320 | reconstructed_2d = module.weight_2d |
| 321 | reconstructed_3d = module.expert_weights |
| 322 | |
| 323 | assert reconstructed_2d.shape == original_2d.shape, "2D parameter shape should be preserved" |
| 324 | assert reconstructed_3d.shape == original_3d.shape, "3D parameter shape should be preserved" |
| 325 | |
| 326 | # Check that state dict includes quantization info for both parameters |
| 327 | state_dict = module.state_dict() |
| 328 | assert "weight_2d" in state_dict, "2D parameter should be in state dict" |
| 329 | assert "expert_weights" in state_dict, "3D parameter should be in state dict" |
| 330 | assert "weight_2d.absmax" in state_dict, "2D parameter quantization metadata should be saved" |
| 331 | assert "expert_weights.absmax" in state_dict, "3D parameter quantization metadata should be saved" |
| 332 | |
| 333 | |
| 334 | @pytest.mark.parametrize("device", get_available_devices()) |
nothing calls this directly
no test coverage detected