Display warning for unknown quants config instead of an error (#35963)

* add supports_quant_method check

* fix

* add test and fix suggestions

* change logic slightly

---------

Co-authored-by: Mohamed Mekkouri <93391238+MekkCyber@users.noreply.github.com>
This commit is contained in:
Marc Sun
2025-02-04 15:17:01 +01:00
committed by GitHub
parent f19bfa50e7
commit 9f486badd5
3 changed files with 40 additions and 2 deletions

View File

@@ -1819,6 +1819,19 @@ class ModelUtilsTest(TestCasePlus):
self.assertIsNone(model_outputs.past_key_values)
self.assertTrue(model.training)
def test_unknown_quantization_config(self):
with tempfile.TemporaryDirectory() as tmpdir:
config = BertConfig(
vocab_size=99, hidden_size=32, num_hidden_layers=5, num_attention_heads=4, intermediate_size=37
)
model = BertModel(config)
config.quantization_config = {"quant_method": "unknown"}
model.save_pretrained(tmpdir)
with self.assertLogs("transformers", level="WARNING") as cm:
BertModel.from_pretrained(tmpdir)
self.assertEqual(len(cm.records), 1)
self.assertTrue(cm.records[0].message.startswith("Unknown quantization type, got"))
@slow
@require_torch