2121
2222# Local
2323from fms_mo .utils .qconfig_utils import qconfig_load , qconfig_save
24- from tests .models .test_model_utils import delete_config , load_json , save_serialized_json
24+ from tests .models .test_model_utils import (
25+ delete_config ,
26+ load_json ,
27+ save_json ,
28+ save_serialized_json ,
29+ )
2530
2631#########
2732# Tests #
@@ -45,7 +50,7 @@ def test_save_config_warn_bad_pair(
4550 # Add bad key,val pair and save ; should generate UserWarning(s) for removing bad pair
4651 config_fp32 [key ] = val
4752 with pytest .warns (UserWarning ):
48- qconfig_save (config_fp32 )
53+ qconfig_save (config_fp32 , minimal = False )
4954
5055 # Load saved config and assert the key is not saved
5156 loaded_config = load_json ("qcfg.json" ) # load json as is - do not modify
@@ -71,14 +76,102 @@ def test_save_config_wanted_pairs(
7176 # Delete wanted pair from config and save ; should be reset to default
7277 if key in config_fp32 :
7378 del config_fp32 [key ]
74- qconfig_save (config_fp32 )
79+ qconfig_save (config_fp32 , minimal = False )
7580
7681 # Load saved config and check the wanted pair was reset to default
7782 loaded_config = load_json ()
7883 assert loaded_config .get (key ) == default_val
7984
8085 delete_config ()
8186
87+ def test_save_config_with_qcfg_save (
88+ config_fp32 : dict ,
89+ save_list : list ,
90+ ):
91+ """
92+ Test for checking that the "save_list" functionality works from within a quantized config
93+
94+ Args:
95+ config_fp32 (dict): Config for fp32 quantization
96+ save_list (list): List of variables to save in a quantized config.
97+ """
98+ delete_config ()
99+ config_fp32 ["save" ] = save_list
100+
101+ qconfig_save (config_fp32 , minimal = False )
102+
103+ loaded_config = load_json ()
104+
105+ # Remove pkg_versions and date before processing
106+ del loaded_config ["pkg_versions" ]
107+ del loaded_config ["date" ]
108+
109+ assert len (loaded_config ) == len (save_list )
110+
111+ # Now ensure that every value in save_list was properly saved
112+ for key in save_list :
113+ assert key in loaded_config
114+ assert loaded_config .get (key ) == config_fp32 .get (key )
115+
116+ delete_config ()
117+ del config_fp32 ["save" ]
118+
119+ def test_save_config_with_recipe_save (
120+ config_fp32 : dict ,
121+ save_list : list ,
122+ ):
123+ """
124+ Test for checking that the "save_list" functionality works from a saved json file
125+
126+ Args:
127+ config_fp32 (dict): Config for fp32 quantization
128+ save_list (list): List of variables to save in a quantized config.
129+ """
130+ # Delete both qcfg and the save.json before starting
131+ delete_config ()
132+ delete_config ("save.json" )
133+
134+ # Save new "save.json"
135+ save_path = "save_list.json"
136+ save_json (save_list , file_path = save_path )
137+
138+ qconfig_save (config_fp32 , recipe = "save_list" )
139+
140+ # Check that saved qcfg matches
141+ loaded_config = load_json ()
142+
143+ # Remove pkg_versions and date before processing
144+ del loaded_config ["pkg_versions" ]
145+ del loaded_config ["date" ]
146+
147+ assert len (loaded_config ) == len (save_list )
148+
149+ # Now ensure that every value in save_list was properly saved
150+ for key in save_list :
151+ assert key in loaded_config
152+ assert loaded_config .get (key ) == config_fp32 .get (key )
153+
154+ delete_config ()
155+ delete_config ("save.json" )
156+
157+ def test_save_config_minimal (
158+ config_fp32 : dict ,
159+ ):
160+ delete_config ()
161+
162+ qconfig_save (config_fp32 , minimal = True )
163+
164+ # Check that saved qcfg matches
165+ loaded_config = load_json ()
166+
167+ # Remove pkg_versions and date before processing
168+ del loaded_config ["pkg_versions" ]
169+ del loaded_config ["date" ]
170+
171+ # No items should exist - default config should be completely removed
172+ assert len (loaded_config ) == 0
173+
174+ delete_config ()
82175
83176def test_load_config_restored_pair (
84177 config_fp32 : dict ,
@@ -96,13 +189,16 @@ def test_load_config_restored_pair(
96189
97190 if key in config_fp32 :
98191 del config_fp32 [key ]
192+
99193 save_serialized_json (
100194 config_fp32
101195 ) # Save config as is, no other edits other than to serialize
102196
103197 loaded_config = qconfig_load ("qcfg.json" )
104198 assert loaded_config .get (key ) == default_val
105199
200+ delete_config ()
201+
106202
107203def test_load_config_required_pair (
108204 config_fp32 : dict ,
0 commit comments