Skip to content

Commit 048309d

Browse files
committed
feat: Added 3 tests for qconfig_save/load json typing
Signed-off-by: Brandon Groth <[email protected]>
1 parent 9f412bc commit 048309d

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

tests/models/test_saveconfig.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,82 @@ def test_double_qconfig_save(
198198

199199
delete_config()
200200

201+
def test_qconfig_save_list_as_dict(
202+
config_fp32: dict,
203+
):
204+
"""
205+
Test that save recipes can't be used as dictionary
206+
207+
Args:
208+
config_fp32 (dict): Config for fp32 quantization
209+
"""
210+
delete_config()
211+
212+
# Fill in keys_to_save as dict with nonsense val
213+
config_fp32["keys_to_save"] = {
214+
"qa_mode": None,
215+
"qw_mode": None,
216+
"smoothq": None,
217+
"scale_layers": None,
218+
"qskip_layer_name": None,
219+
"qskip_large_mag_layers": None,
220+
}
221+
222+
with pytest.raises(ValueError):
223+
qconfig_save(config_fp32, minimal=True)
224+
225+
delete_config()
226+
227+
228+
def test_qconfig_save_recipe_as_dict(
229+
config_fp32: dict,
230+
):
231+
"""
232+
Test that save recipes can't be used as dictionary
233+
234+
Args:
235+
config_fp32 (dict): Config for fp32 quantization
236+
"""
237+
delete_config()
238+
239+
# Fill in keys_to_save as dict with nonsense val
240+
save_dict = {
241+
"qa_mode": None,
242+
"qw_mode": None,
243+
"smoothq": None,
244+
"scale_layers": None,
245+
"qskip_layer_name": None,
246+
"qskip_large_mag_layers": None,
247+
}
248+
save_json(save_dict, file_path="keys_to_save.json")
249+
250+
251+
with pytest.raises(ValueError):
252+
qconfig_save(config_fp32, recipe="keys_to_save.json", minimal=True)
253+
254+
delete_config()
255+
256+
257+
def test_qconfig_load_with_recipe_as_list(
258+
config_fp32: dict,
259+
):
260+
"""
261+
Test if using qconfig_load errors when loading a json list
262+
263+
Args:
264+
config_fp32 (dict): Config for fp32 quantization
265+
"""
266+
delete_config()
267+
268+
config_list = list( config_fp32.keys() )
269+
270+
save_json(config_list, file_path="qcfg.json")
271+
272+
with pytest.raises(ValueError):
273+
_ = qconfig_load(fname="qcfg.json")
274+
275+
delete_config()
276+
201277

202278
def test_load_config_restored_pair(
203279
config_fp32: dict,

0 commit comments

Comments
 (0)