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

Remove unused function #156

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
47 changes: 0 additions & 47 deletions src/compressed_tensors/quantization/lifecycle/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,62 +16,15 @@
Miscelaneous helpers for the quantization lifecycle
"""

from typing import Optional

import torch
from torch.nn import Module


__all__ = [
"update_layer_weight_quant_params",
"enable_quantization",
"disable_quantization",
]


def update_layer_weight_quant_params(
layer: Module,
weight: Optional[torch.Tensor] = None,
g_idx: Optional[torch.Tensor] = None,
reset_obs: bool = False,
):
"""
Update quantization parameters on layer

:param layer: input layer
:param weight: weight to update quant params with, defaults to layer weight
:param g_idx: optional mapping from column index to group index
:param reset_obs: reset the observer before calculating quant params,
defaults to False
"""
attached_weight = getattr(layer, "weight", None)

if weight is None:
weight = attached_weight
scale = getattr(layer, "weight_scale", None)
zero_point = getattr(layer, "weight_zero_point", None)
if g_idx is None:
g_idx = getattr(layer, "weight_g_idx", None)
observer = getattr(layer, "weight_observer", None)

if weight is None or observer is None or scale is None or zero_point is None:
# scale, zp, or observer not calibratable or weight not available
return

if reset_obs:
observer.reset()

if attached_weight is not None:
weight = weight.to(attached_weight.dtype)

updated_scale, updated_zero_point = observer(weight)

# update scale and zero point
device = next(layer.parameters()).device
scale.data = updated_scale.to(device)
zero_point.data = updated_zero_point.to(device)


def enable_quantization(module: Module):
module.quantization_enabled = True

Expand Down
Loading