Skip to content

Commit

Permalink
[SW-194200] Save scale file only with new scales
Browse files Browse the repository at this point in the history
Change-Id: I14a4ef94d188b13c2fbf4ea77d2b42cb5bd6d952
  • Loading branch information
nirda7 authored and Eran Geva committed Jul 25, 2024
1 parent 4f8b257 commit 039af39
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion neural_compressor/torch/algorithms/fp8_quant/_core/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def get_config(
)
scales = convert_scales_to_tensors_dict(scales_obj, scales_file_format, params["hp_dtype"])
model_dict = dict(model.named_modules())
save_file = False
for mname in mod_list:
mod = model_dict[mname]
set_hqt_config(mod, top_level_config) # set config in the module, as it consumed by the patched module
Expand All @@ -123,6 +124,7 @@ def get_config(
scales_obj[mname] = ModuleConfig(
**format_functions_rec((torch.Tensor, scales_file_format))(scales[mname].__dict__)
)
save_file = True

logger.debug(
"Preparing quantization functions for layer %s layer_type=%s",
Expand All @@ -138,7 +140,7 @@ def get_config(
params,
)
qconfig[mname] = mod_extra_config
if scales_file is not None:
if save_file and scales_file is not None:
save_scales(model, scales_obj, scales_file_format, scales_file + ".npz")
save_scales(model, scales_obj, scales_file_format, scales_file + ".json")
return qconfig
Expand Down

0 comments on commit 039af39

Please sign in to comment.