|
40 | 40 | Int4WeightOnlyConfig, |
41 | 41 | Int8DynamicActivationInt8WeightConfig, |
42 | 42 | Int8DynamicActivationIntxWeightConfig, |
| 43 | + Int8StaticActivationInt8WeightConfig, |
43 | 44 | Int8WeightOnlyConfig, |
44 | 45 | IntxWeightOnlyConfig, |
45 | 46 | ModuleFqnToConfig, |
@@ -1036,6 +1037,36 @@ def __init__(self): |
1036 | 1037 | assert isinstance(m.nested.linear.weight, AffineQuantizedTensor) |
1037 | 1038 | assert isinstance(m.linear1.weight, AffineQuantizedTensor) |
1038 | 1039 |
|
| 1040 | + def test_fqn_to_config_non_weight_param(self): |
| 1041 | + configs = [ |
| 1042 | + Int4WeightOnlyConfig(group_size=128), |
| 1043 | + Int8WeightOnlyConfig(), |
| 1044 | + Int8StaticActivationInt8WeightConfig(), |
| 1045 | + Float8WeightOnlyConfig(), |
| 1046 | + Float8DynamicActivationFloat8WeightConfig(granularity=PerTensor()), |
| 1047 | + ] |
| 1048 | + for config in configs: |
| 1049 | + with self.subTest(config=type(config).__name__): |
| 1050 | + model = torch.nn.Sequential( |
| 1051 | + torch.nn.Linear(128, 128).to(torch.bfloat16).cuda() |
| 1052 | + ) |
| 1053 | + model[0].register_parameter( |
| 1054 | + "custom_param", |
| 1055 | + torch.nn.Parameter( |
| 1056 | + torch.randn(128, 128, dtype=torch.bfloat16, device="cuda") |
| 1057 | + ), |
| 1058 | + ) |
| 1059 | + original_custom_param = model[0].custom_param |
| 1060 | + original_weight = model[0].weight |
| 1061 | + quant_config = FqnToConfig({"0.custom_param": config}) |
| 1062 | + quantize_(model, quant_config, filter_fn=None) |
| 1063 | + assert model[0].custom_param is not original_custom_param, ( |
| 1064 | + f"custom_param should be quantized for {type(config).__name__}" |
| 1065 | + ) |
| 1066 | + assert model[0].weight is original_weight, ( |
| 1067 | + f"weight should be unchanged for {type(config).__name__}" |
| 1068 | + ) |
| 1069 | + |
1039 | 1070 | def test_fqn_config_module_config_and_fqn_config_both_specified(self): |
1040 | 1071 | with self.assertRaises(ValueError): |
1041 | 1072 | FqnToConfig( |
|
0 commit comments