@@ -188,7 +188,7 @@ def recompute_weight_with_sawb(
188188 f"(std_min={ weight_int_std_min :.1f} "
189189 f"-> { weight_int_sawb_std_min :.1f} ) "
190190 f"and clips of { layer_name + '.weight' } "
191- )
191+ )
192192 else :
193193 weight_int_sawb_as_fp_std = weight_int_sawb_as_fp .std ()
194194 if verbose :
@@ -410,6 +410,13 @@ def save_sd_for_aiu(
410410) -> None :
411411 """Save model state dictionary after conversion for AIU compatibility."""
412412
413+ if qcfg is None :
414+ logger .info (
415+ "Attention: saving state dictionary without specifying a quantization "
416+ "configuration (qcfg) performs no recomputation for narrow weight "
417+ "distributions and assumes the weight quantizer used was per-tensor."
418+ )
419+
413420 converted_sd = convert_sd_for_aiu (
414421 model = model ,
415422 recompute_narrow_weights = (
@@ -426,7 +433,7 @@ def save_sd_for_aiu(
426433
427434def save_for_aiu (
428435 model : PreTrainedModel ,
429- qcfg : dict ,
436+ qcfg : dict | None = None ,
430437 output_dir : str | Path = "./" ,
431438 file_name : str | Path = "qmodel_for_aiu.pt" ,
432439 cfg_name : str | Path = "qcfg.json" ,
@@ -440,11 +447,18 @@ def save_for_aiu(
440447 weights presenting narrow distributions in the integer domain.
441448 The general qconfig_save function is used to save the quantization configuration.
442449
443- Required arguments: model (quantized), qcfg
450+ Required arguments: model (quantized)
444451 """
445452
446453 save_sd_for_aiu (model , qcfg , output_dir , file_name , verbose )
447454
455+ if qcfg is None :
456+ logger .info (
457+ "Quantization configuration was not provided. Only converted checkpoint is "
458+ "saved."
459+ )
460+ return
461+
448462 # enforce specific keys needed when reloading model for AIU
449463 qcfg ["keys_to_save" ] = [
450464 "qa_mode" ,
@@ -455,4 +469,9 @@ def save_for_aiu(
455469 "qskip_large_mag_layers" ,
456470 "recompute_narrow_weights" ,
457471 ]
458- qconfig_save (qcfg , recipe = recipe , minimal = True , fname = Path (output_dir ) / cfg_name )
472+ qconfig_save (
473+ qcfg = qcfg ,
474+ recipe = recipe ,
475+ minimal = True ,
476+ fname = str (Path (output_dir ) / cfg_name ), # only str is fname accepted type
477+ )
0 commit comments