Skip to content

Add fallback for sparsegpt inversion failure #1578

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 4 commits into from
Jun 25, 2025
Merged
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
4 changes: 3 additions & 1 deletion src/llmcompressor/modifiers/obcq/sgpt_sparsify.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import torch
import transformers
from loguru import logger

SGPT_PRECISION = torch.float32

Expand Down Expand Up @@ -108,11 +109,12 @@ def sparsify_weight(
H = torch.linalg.cholesky(H, upper=True)
Hinv = H
except torch._C._LinAlgError:
raise torch._C._LinAlgError(
logger.warning(
"Failed to invert hessian due to numerical instability. Consider "
"increasing SparseGPTModifier.dampening_frac, increasing the number "
"of calibration samples, or shuffling the calibration dataset"
)
Hinv = H = torch.eye(num_columns, dtype=H.dtype, device=H.device)

# sparsity mask
# TODO: consider computing sparsity mask in the same way and place as gptq
Expand Down