@@ -59,6 +59,7 @@ def test_need_calibration():
5959
6060def test_need_calibration_with_quantize_config_type ():
6161 """need_calibration accepts schema-backed QuantizeConfig objects."""
62+ assert need_calibration (QuantizeConfig ())
6263 assert need_calibration (QuantizeConfig .model_validate (FP8_DEFAULT_CFG ))
6364 assert not need_calibration (QuantizeConfig .model_validate (FP8_PER_CHANNEL_PER_TOKEN_CFG ))
6465
@@ -100,16 +101,27 @@ def test_quantizer_cfg_entry_is_pydantic_and_dict_like():
100101 entry = QuantizerCfgEntry (quantizer_name = "*" , enable = False )
101102 assert isinstance (entry , ModeloptBaseConfig )
102103 assert entry ["quantizer_name" ] == "*"
103- assert entry .get ("cfg" ) is None
104+ assert entry ["cfg" ] is None
105+ assert "cfg" in entry
106+ assert list (entry ) == ["quantizer_name" , "parent_class" , "cfg" , "enable" ]
107+ assert dict (entry .items ()) == {
108+ "quantizer_name" : "*" ,
109+ "parent_class" : None ,
110+ "cfg" : None ,
111+ "enable" : False ,
112+ }
113+ assert dict (entry .explicit_items ()) == {"quantizer_name" : "*" , "enable" : False }
114+ with pytest .raises (KeyError ):
115+ entry ["unknown" ] = 1
104116 assert entry .model_dump (exclude_unset = True ) == {"quantizer_name" : "*" , "enable" : False }
105117
106118 cfg_entry = QuantizerCfgEntry (quantizer_name = "*weight_quantizer" , cfg = {"num_bits" : 8 })
107119 assert isinstance (cfg_entry ["cfg" ], QuantizerAttributeConfig )
108120 assert _cfg_to_dict (cfg_entry ["cfg" ]) == {"num_bits" : 8 }
109121
110122
111- def test_quantizer_cfg_entry_mutable_mapping_delitem_unsets_field ():
112- """Deleting a config key resets it to unset for exclude_unset dumps ."""
123+ def test_quantizer_cfg_entry_mutable_mapping_rejects_key_deletion ():
124+ """ModeloptBaseConfig mappings have a fixed key set and reject deletion ."""
113125 entry = QuantizerCfgEntry (quantizer_name = "*weight_quantizer" , cfg = {"num_bits" : 8 }, enable = True )
114126 assert isinstance (entry , MutableMapping )
115127 assert entry .model_dump (exclude_unset = True ) == {
@@ -118,11 +130,14 @@ def test_quantizer_cfg_entry_mutable_mapping_delitem_unsets_field():
118130 "enable" : True ,
119131 }
120132
121- del entry ["cfg" ]
133+ with pytest .raises (TypeError ):
134+ del entry ["cfg" ]
122135
123- assert entry ["cfg" ] is None
136+ assert "cfg" in entry
137+ assert entry ["cfg" ] is not None
124138 assert entry .model_dump (exclude_unset = True ) == {
125139 "quantizer_name" : "*weight_quantizer" ,
140+ "cfg" : {"num_bits" : 8 },
126141 "enable" : True ,
127142 }
128143
@@ -196,10 +211,13 @@ def test_quantizer_cfg_entry_rejects_explicit_null_values(raw, match):
196211 normalize_quant_cfg_list ([raw ])
197212
198213
199- def test_quantizer_cfg_entry_rejects_no_effect_entry ():
200- """Direct QuantizerCfgEntry construction rejects entries with no cfg or enable."""
201- with pytest .raises (ValidationError , match = "must specify 'cfg', 'enable'" ):
202- QuantizerCfgEntry (quantizer_name = "*" )
214+ def test_quantizer_cfg_entry_defaults_enable_true ():
215+ """Direct QuantizerCfgEntry construction uses enable=True when omitted."""
216+ entry = QuantizerCfgEntry (quantizer_name = "*" )
217+ assert entry ["enable" ] is True
218+ assert entry ["cfg" ] is None
219+ assert dict (entry .explicit_items ()) == {"quantizer_name" : "*" }
220+ assert entry .model_dump (exclude_unset = True ) == {"quantizer_name" : "*" }
203221
204222
205223def test_quantizer_cfg_entry_rejects_empty_name ():
@@ -231,7 +249,8 @@ def test_new_format_passthrough(self):
231249 assert result [0 ]["quantizer_name" ] == "*weight_quantizer"
232250 assert isinstance (result [0 ]["cfg" ], QuantizerAttributeConfig )
233251 assert _cfg_to_dict (result [0 ]["cfg" ]) == {"num_bits" : 8 , "axis" : 0 }
234- assert result [0 ]["enable" ] is True # defaulted
252+ assert result [0 ]["enable" ] is True # schema default
253+ assert "enable" not in dict (result [0 ].explicit_items ())
235254
236255 def test_typed_entry_list_passthrough (self ):
237256 """Already-parsed QuantizerCfgEntry lists are returned unchanged."""
@@ -256,6 +275,7 @@ def test_mixed_typed_and_dict_entries_normalize_to_typed_entries(self):
256275 assert isinstance (result [1 ], QuantizerCfgEntry )
257276 assert _cfg_to_dict (result [1 ]["cfg" ]) == {"num_bits" : 8 }
258277 assert result [1 ]["enable" ] is True
278+ assert "enable" not in dict (result [1 ].explicit_items ())
259279
260280 def test_new_format_enable_false (self ):
261281 """Explicit enable=False is preserved."""
@@ -277,7 +297,8 @@ def test_legacy_single_key_dict(self):
277297 result = normalize_quant_cfg_list (raw )
278298 assert result [0 ]["quantizer_name" ] == "*weight_quantizer"
279299 assert _cfg_to_dict (result [0 ]["cfg" ]) == {"num_bits" : 8 , "axis" : 0 }
280- assert result [0 ]["enable" ] is True # defaulted
300+ assert result [0 ]["enable" ] is True # schema default
301+ assert "enable" not in dict (result [0 ].explicit_items ())
281302
282303 def test_legacy_single_key_dict_with_enable (self ):
283304 """Legacy {'*path': {'enable': False}} splits enable out from cfg."""
@@ -296,17 +317,19 @@ def test_legacy_nn_class_scoped(self):
296317 assert result [0 ]["enable" ] is False
297318
298319 def test_normalization_cfg_defaults_to_none (self ):
299- """Entries without cfg get cfg=None after normalization ."""
320+ """Entries without cfg expose the default mapping key but keep it unset ."""
300321 raw = [{"quantizer_name" : "*lm_head*" , "enable" : False }]
301322 result = normalize_quant_cfg_list (raw )
302323 assert "cfg" in result [0 ]
303324 assert result [0 ]["cfg" ] is None
325+ assert "cfg" not in dict (result [0 ].explicit_items ())
304326
305327 def test_normalization_enable_defaults_to_true (self ):
306- """Entries with cfg but no enable get enable=True after normalization ."""
328+ """Entries with cfg but no enable read as enable=True without marking it explicit ."""
307329 raw = [{"quantizer_name" : "*" , "cfg" : {"num_bits" : 4 }}]
308330 result = normalize_quant_cfg_list (raw )
309331 assert result [0 ]["enable" ] is True
332+ assert "enable" not in dict (result [0 ].explicit_items ())
310333
311334 def test_empty_list (self ):
312335 """Empty list is returned unchanged."""
@@ -322,10 +345,13 @@ def test_multiple_entries_order_preserved(self):
322345 assert result [0 ]["quantizer_name" ] == "*"
323346 assert result [1 ]["quantizer_name" ] == "*weight_quantizer"
324347
325- def test_error_on_quantizer_name_only (self ):
326- """Entry with only quantizer_name and no cfg or enable is rejected."""
327- with pytest .raises (ValueError , match = "must specify 'cfg', 'enable'" ):
328- normalize_quant_cfg_list ([{"quantizer_name" : "*" }])
348+ def test_quantizer_name_only_defaults_enable_true (self ):
349+ """Entry with only quantizer_name uses enable=True from the schema default."""
350+ result = normalize_quant_cfg_list ([{"quantizer_name" : "*" }])
351+ assert result [0 ]["enable" ] is True
352+ assert result [0 ]["cfg" ] is None
353+ assert dict (result [0 ].explicit_items ()) == {"quantizer_name" : "*" }
354+ assert result [0 ].model_dump (exclude_unset = True ) == {"quantizer_name" : "*" }
329355
330356 def test_error_on_empty_dict (self ):
331357 """An empty dict entry is rejected."""
@@ -421,6 +447,7 @@ def test_legacy_flat_dict_conversion(self):
421447 assert result [1 ]["quantizer_name" ] == "*weight_quantizer"
422448 assert _cfg_to_dict (result [1 ]["cfg" ]) == {"num_bits" : 8 , "axis" : 0 }
423449 assert result [1 ]["enable" ] is True
450+ assert "enable" not in dict (result [1 ].explicit_items ())
424451
425452 def test_legacy_enable_only_produces_cfg_none (self ):
426453 """Legacy {'*': {'enable': False}} should produce cfg=None, not cfg={}."""
0 commit comments