Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ htmlcov/
durations/*
coverage*.xml
qcfg.json
models
configs
pytest.out

# IDEs
.vscode/
Expand Down
2 changes: 1 addition & 1 deletion fms_mo/quant/quantizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3029,7 +3029,7 @@ def __init__(
self.register_buffer("clip_valn", torch.zeros(perGp[0]))
else:
self.register_buffer(
"clip_val", torch.zeros(perCh) if perCh else torch.Tensor([1.0])
"clip_val", torch.zeros(perCh) if perCh else torch.Tensor([0.0])

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uninitialized clip_vals are supposed to be zero tensors, but for some reason this one was set to 1.0. This is consistent for other quantizers currently.

)
self.register_buffer(
"clip_valn", torch.zeros(perCh) if perCh else torch.Tensor([0.0])
Expand Down
8 changes: 8 additions & 0 deletions fms_mo/utils/aiu_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,14 @@ def process_weight(
is_w_recomputed = False
if layer_name + ".quantize_weight.clip_val" in model.state_dict():
w_cv = model.state_dict()[layer_name + ".quantize_weight.clip_val"]

# Check that clip values are initialized
if torch.any(w_cv.isclose(torch.tensor(0.0))):
raise ValueError(
f"Quantization clip values for {layer_name=} have near-zero values and "
"are likely uninitialized."
)

if w_cv.numel() > 1:
w_cv = w_cv.unsqueeze(dim=1)
weight_int_as_fp = torch.clamp(127 / w_cv * weight_pre_quant, -127, 127).round()
Expand Down
3 changes: 1 addition & 2 deletions fms_mo/utils/qconfig_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,7 @@ def qconfig_save(

# Save config as json
if os.path.isfile(fname):
message = f"{fname} already exist, will overwrite."
warnings.warn(message, UserWarning)
logger.info(f"{fname} already exist, will overwrite.")
with open(fname, "w", encoding="utf-8") as outfile:
json.dump(temp_qcfg, outfile, indent=4)

Expand Down
Loading
Loading