Skip to content

Revert "[lint] reformat qat files" #2104

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 1 commit into from
Apr 22, 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
12 changes: 6 additions & 6 deletions torchao/quantization/qat/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def convert(
"""
self._convert_helper(model)
return model

@staticmethod
def quantize_weights(
weight: torch.Tensor,
Expand All @@ -207,11 +207,12 @@ def quantize_weights(
Helper function to quantize weights
"""
(qmin, qmax) = _get_qmin_qmax(bit_width)
(s, zp) = get_group_qparams_symmetric(weight, bit_width, group_size)
(s, zp) = get_group_qparams_symmetric(
weight, bit_width, group_size
)
from torchao._executorch_ops import (
_quantized_decomposed_quantize_per_channel_group_wrapper,
)

q_weight = _quantized_decomposed_quantize_per_channel_group_wrapper(
weight,
s,
Expand All @@ -223,6 +224,7 @@ def quantize_weights(
)
return (q_weight, s, zp)


def _convert_helper(self, module: torch.nn.Module):
"""
Helper function to recursively swap `Int4WeightOnlyQATEmbedding`
Expand Down Expand Up @@ -253,9 +255,7 @@ def _convert_helper(self, module: torch.nn.Module):
)
setattr(module, name, quantized_embedding)

q_weight, s, zp = self.quantize_weights(
child.weight, self.bit_width, group_size
)
q_weight, s, zp = self.quantize_weights(child.weight, self.bit_width, group_size)
# Load weights and qparams into quantized embedding
quantized_embedding.weight = q_weight
quantized_embedding.scale = s.to(scale_precision)
Expand Down
11 changes: 6 additions & 5 deletions torchao/quantization/qat/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def convert(
) -> torch.nn.Module:
self._convert_qat_linear_8da4w(model)
return model

@staticmethod
def quantize_weights(
weight: torch.Tensor,
Expand All @@ -209,7 +209,9 @@ def quantize_weights(
# Load weights and qparams into quantized linear
n_bit = 4
(qmin, qmax) = _get_qmin_qmax(n_bit)
(s, zp) = get_group_qparams_symmetric(weight, n_bit, group_size)
(s, zp) = get_group_qparams_symmetric(
weight, n_bit, group_size
)
from torchao._executorch_ops import (
_quantized_decomposed_quantize_per_channel_group_wrapper,
)
Expand All @@ -225,6 +227,7 @@ def quantize_weights(
)
return (q_weight, s, zp)


def _convert_qat_linear_8da4w(self, module: torch.nn.Module):
"""
Replace all `Int8DynActInt4WeightQATLinear` with `Int8DynActInt4WeightLinear`.
Expand All @@ -242,9 +245,7 @@ def _convert_qat_linear_8da4w(self, module: torch.nn.Module):
)
setattr(module, name, quantized_linear)

q_weight, scales, zeros = self.quantize_weights(
child.weight, config.group_size
)
q_weight, scales, zeros = self.quantize_weights(child.weight, config.group_size)
quantized_linear.weight = q_weight
quantized_linear.scales = scales
quantized_linear.zeros = zeros
Expand Down
Loading