2222# Suppress banner for clean output
2323os .environ ["QUANTLLM_BANNER" ] = "0"
2424
25- from quantllm import turbo , TurboModel , register_architecture
25+ from quantllm import turbo , TurboModel , register_architecture , register_model
2626from quantllm .quant import HQQLinear , HQQQuantizer , HQQConfig
2727from quantllm .registry import list_models , search_models
2828
@@ -38,7 +38,7 @@ def phase1_load_model():
3838
3939 print (f"Loaded: { model .config .bits } -bit { model .config .quant_type } " )
4040 print (f"Device: { model .config .device } , dtype: { model .config .dtype } " )
41- print (f"Params: { model .config .stats .get ('params' , 0 )/ 1e9 :.2f} B" )
41+ print (f"Params: { model .config .stats .get ('params' , 0 ) / 1e9 :.2f} B" )
4242 print (f"Quantized: { model .is_quantized } " )
4343
4444 # Test generation
@@ -59,7 +59,9 @@ def phase2_quantization():
5959 print ("\n BitsAndBytes quantization:" )
6060 for bits in [4 , 8 ]:
6161 model = turbo ("Qwen/Qwen2.5-7B-Instruct" , bits = bits )
62- print (f" BnB { bits } -bit: bits={ model .config .bits } , quant={ model .config .quant_type } , quantized={ model .is_quantized } " )
62+ print (
63+ f" BnB { bits } -bit: bits={ model .config .bits } , quant={ model .config .quant_type } , quantized={ model .is_quantized } "
64+ )
6365 del model
6466
6567 # Test HQQ native quantization (no calibration, for export/optimization)
@@ -71,7 +73,9 @@ def phase2_quantization():
7173 for bits in [2 , 4 , 8 ]:
7274 config = HQQConfig (bits = bits , group_size = 64 , optimize = True )
7375 hqq_layer = HQQLinear (weight , config ) # Quantize linear layer
74- print (f" HQQ { bits } -bit: Original={ weight .numel ()* 2 / 1e6 :.2f} MB, Quantized={ hqq_layer .quantized_weight .numel ()/ 1e6 :.2f} MB" )
76+ print (
77+ f" HQQ { bits } -bit: Original={ weight .numel () * 2 / 1e6 :.2f} MB, Quantized={ hqq_layer .quantized_weight .numel () / 1e6 :.2f} MB"
78+ )
7579 del hqq_layer
7680
7781 torch .cuda .empty_cache ()
@@ -102,7 +106,9 @@ def phase3_export(model):
102106 for fmt , quant , desc in formats :
103107 print (f"\n Exporting { desc } ..." )
104108 try :
105- output = tmp_path / f"model_{ fmt } _{ quant or 'default' } .gguf" if fmt == "gguf" else tmp_path / f"model_{ fmt } "
109+ output = (
110+ tmp_path / f"model_{ fmt } _{ quant or 'default' } .gguf" if fmt == "gguf" else tmp_path / f"model_{ fmt } "
111+ )
106112 result = model .export (fmt , str (output ), quantization = quant or "auto" , chunked_conversion = True )
107113 size_gb = Path (result ).stat ().st_size / (1024 ** 3 ) if Path (result ).exists () else 0
108114 exports [f"{ fmt } _{ quant or 'default' } " ] = {"path" : result , "size_gb" : size_gb }
@@ -268,4 +274,4 @@ def main():
268274
269275
270276if __name__ == "__main__" :
271- main ()
277+ main ()
0 commit comments