Skip to content

Commit

Permalink
Skip writing empty g_idx to disk, fix compress_quantized_weights (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylesayrs authored Sep 9, 2024
1 parent d8a717c commit b885229
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compressed_tensors/compressors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def compress(
else:
compressed_dict[name] = value.to("cpu")
elif name.endswith("zero_point") and torch.all(value == 0):
# all zero_points are 0, no need to include in
# compressed state_dict
continue
elif name.endswith("g_idx") and torch.any(value <= -1):
continue
else:
compressed_dict[name] = value.to("cpu")
Expand Down
2 changes: 2 additions & 0 deletions src/compressed_tensors/quantization/lifecycle/compressed.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def compress_quantized_weights(module: Module):
weight = getattr(module, "weight", None)
scale = getattr(module, "weight_scale", None)
zero_point = getattr(module, "weight_zero_point", None)
g_idx = getattr(module, "weight_g_idx", None)

if weight is None or scale is None:
# no weight, scale, or ZP, nothing to do
Expand All @@ -62,6 +63,7 @@ def compress_quantized_weights(module: Module):
x=weight,
scale=scale,
zero_point=zero_point,
g_idx=g_idx,
args=scheme.weights,
dtype=torch.int8,
)
Expand Down

0 comments on commit b885229

Please sign in to comment.