Skip to content

Commit

Permalink
quant: update tpu_int8 to use AphroditeParameters (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlpinDale authored Dec 22, 2024
1 parent 9ff3239 commit f4b62bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion aphrodite/modeling/layers/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"CompressedTensorsLinearMethod", "GPTQMarlinLinearMethod",
"AWQMarlinLinearMethod", "AWQLinearMethod", "HQQMarlinMethod",
"Fp8LinearMethod", "MarlinLinearMethod", "QQQLinearMethod",
"GPTQMarlin24LinearMethod",
"GPTQMarlin24LinearMethod", "TPUInt8LinearMethod"
]


Expand Down
21 changes: 11 additions & 10 deletions aphrodite/quantization/tpu_int8.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from torch.nn.parameter import Parameter

from aphrodite.modeling.layers.linear import LinearBase, LinearMethodBase
from aphrodite.modeling.utils import set_weight_attrs
from aphrodite.modeling.parameter import ModelWeightParameter
from aphrodite.quantization.base_config import QuantizationConfig

ACTIVATION_SCHEMES = ["none"]
Expand Down Expand Up @@ -63,16 +63,16 @@ def create_weights(self, layer: Module, input_size_per_partition: int,
output_partition_sizes: List[int], input_size: int,
output_size: int, params_dtype: torch.dtype,
**extra_weight_attrs):
weight = Parameter(torch.empty(sum(output_partition_sizes),
input_size_per_partition,
dtype=params_dtype),
requires_grad=False)

weight_loader = extra_weight_attrs.get("weight_loader")
weight = ModelWeightParameter(data=torch.empty(
sum(output_partition_sizes),
input_size_per_partition,
dtype=params_dtype),
input_dim=1,
output_dim=0,
weight_loader=weight_loader)
layer.register_parameter("weight", weight)
set_weight_attrs(weight, {
**extra_weight_attrs,
"input_dim": 1,
"output_dim": 0,
})

def _quantize_weight(
self, weight: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
Expand All @@ -91,6 +91,7 @@ def _quantize_weight(
return qweight, qscale

def process_weights_after_loading(self, layer: Module) -> None:
layer.weight = Parameter(layer.weight.data, requires_grad=False)
device = layer.weight.device
qweight, qscale = self._quantize_weight(layer.weight)
qweight = qweight.to(device)
Expand Down

0 comments on commit f4b62bf

Please sign in to comment.