Skip to content

Add update_g_idx flag for setting qweight&g_idx #2143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 21, 2025
7 changes: 7 additions & 0 deletions neural_compressor/transformers/quantization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,16 @@ def _replace_linear(
dtype=torch.int32,
device=torch.device(device),
)

# Note: update_g_idx is only applicable for ipex versions >=2.7
model._modules[name].set_weights_bias(
module.qweight.data if hasattr(module, "qweight") else weight,
None if module.bias is None else module.bias.data,
**(
{"update_g_idx": not empty_weights}
if "update_g_idx" in model._modules[name].set_weights_bias.__code__.co_varnames
else {}
),
)
else:
raise Exception("{} device Unsupported weight only quantization!".format(device))
Expand Down