Skip to content
Open
Changes from 3 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
21 changes: 14 additions & 7 deletions torchao/quantization/quant_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1373,11 +1373,16 @@ def _int8_weight_only_transform(
"applying int8 weight only quant requires module to have {parameter_name} attribute"
+ " but {module} does not have one"
)
new_weight = _int8_weight_only_quantize_tensor(
quantized_tensor = _int8_weight_only_quantize_tensor(
getattr(module, parameter_name), config
)
setattr(module, parameter_name, torch.nn.Parameter(new_weight, requires_grad=False))
module.extra_repr = types.MethodType(_linear_extra_repr, module)
setattr(
module,
parameter_name,
torch.nn.Parameter(quantized_tensor, requires_grad=False),
)
if isinstance(module, torch.nn.Linear):
module.extra_repr = types.MethodType(_linear_extra_repr, module)
return module


Expand Down Expand Up @@ -1662,16 +1667,17 @@ def _float8_weight_only_transform(
if isinstance(module, Float8Linear):
module = _unwrap_float8_linear(module)

new_weight = _float8_weight_only_quant_tensor(
quantized_tensor = _float8_weight_only_quant_tensor(
getattr(module, parameter_name), config
)

setattr(
module,
parameter_name,
torch.nn.Parameter(new_weight, requires_grad=False),
torch.nn.Parameter(quantized_tensor, requires_grad=False),
)
module.extra_repr = types.MethodType(_linear_extra_repr, module)
if isinstance(module, torch.nn.Linear):
module.extra_repr = types.MethodType(_linear_extra_repr, module)
return module


Expand Down Expand Up @@ -1918,7 +1924,8 @@ def _float8_dynamic_activation_float8_weight_transform(
parameter_name,
torch.nn.Parameter(quantized_tensor, requires_grad=False),
)
module.extra_repr = types.MethodType(_linear_extra_repr, module)
if isinstance(module, torch.nn.Linear):
module.extra_repr = types.MethodType(_linear_extra_repr, module)
return module


Expand Down
Loading