Skip to content
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

gptq fixes #1317

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 4 additions & 2 deletions model_compression_toolkit/gptq/keras/quantization_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def get_keras_gptq_config(n_epochs: int,
if regularization_factor is None:
regularization_factor = REG_DEFAULT_SLA if use_hessian_sample_attention else REG_DEFAULT

loss = loss or GPTQMultipleTensorsLoss()
hessian_weights_config = None
if use_hessian_sample_attention:
if not use_hessian_based_weights: # pragma: no cover
Expand All @@ -129,7 +128,10 @@ def get_keras_gptq_config(n_epochs: int,
hessian_weights_config = GPTQHessianScoresConfig(per_sample=False,
hessians_num_samples=GPTQ_HESSIAN_NUM_SAMPLES,
hessian_batch_size=hessian_batch_size)


# If a loss was not passed (and was not initialized due to use_hessian_sample_attention), use the default loss
loss = loss or GPTQMultipleTensorsLoss()

if isinstance(gradual_activation_quantization, bool):
gradual_quant_config = GradualActivationQuantizationConfig() if gradual_activation_quantization else None
elif isinstance(gradual_activation_quantization, GradualActivationQuantizationConfig):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def get_pytorch_gptq_config(n_epochs: int,
if regularization_factor is None:
regularization_factor = REG_DEFAULT_SLA if use_hessian_sample_attention else REG_DEFAULT

loss = loss or multiple_tensors_mse_loss
hessian_weights_config = None
if use_hessian_sample_attention:
if not use_hessian_based_weights: # pragma: no cover
Expand All @@ -118,6 +117,9 @@ def get_pytorch_gptq_config(n_epochs: int,
hessian_weights_config = GPTQHessianScoresConfig(per_sample=False,
hessians_num_samples=GPTQ_HESSIAN_NUM_SAMPLES,
hessian_batch_size=hessian_batch_size)

# If a loss was not passed (and was not initialized due to use_hessian_sample_attention), use the default loss
loss = loss or multiple_tensors_mse_loss

if isinstance(gradual_activation_quantization, bool):
gradual_quant_config = GradualActivationQuantizationConfig() if gradual_activation_quantization else None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@
"outputs": [],
"source": [
"quantized_model.compile(loss=keras.losses.SparseCategoricalCrossentropy(), metrics=\"accuracy\")\n",
"quantized_accuracy = float_model.evaluate(val_dataset)\n",
"quantized_accuracy = quantized_model.evaluate(val_dataset)\n",
"print(f\"Quantized model's Top 1 accuracy on the Imagenet validation set: {(quantized_accuracy[1] * 100):.2f}%\")"
]
},
Expand Down
Loading