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

Fix an autoquant bug in flatten/unflatten #1288

Merged
merged 1 commit into from
Nov 15, 2024
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: 12 additions & 0 deletions test/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,18 @@ def test_aq_float8_weight_only_quant_subclass(self, device, dtype):
AQFloat8WeightOnlyQuantizedLinearWeight.from_float, device, 30, test_dtype=dtype
)

def test_autoquantizable_flatten_unflatten(self):
from torchao.quantization import DEFAULT_AUTOQUANT_CLASS_LIST
weight = torch.randn(16, 32)
qtensor_class_list = DEFAULT_AUTOQUANT_CLASS_LIST
aqw = AutoQuantizableLinearWeight.from_float(weight, qtensor_class_list)
tensor_data_name_dict, tensor_attributes = aqw.__tensor_flatten__()
tensor_data_dict = {name: getattr(aqw, name) for name in tensor_data_name_dict}
outer_size = aqw.size()
outer_stride = aqw.stride()
reconstructed = type(aqw).__tensor_unflatten__(tensor_data_dict, tensor_attributes, outer_size, outer_stride)


@parameterized.expand(COMMON_DEVICE_DTYPE)
@unittest.skipIf(not TORCH_VERSION_AT_LEAST_2_5, "autoquant+aqt needs newer pytorch")
@unittest.skipIf(not is_H100, "Need H100 to run")
Expand Down
2 changes: 1 addition & 1 deletion torchao/quantization/autoquant.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def __tensor_unflatten__(
cls, tensor_data_dict, tensor_attributes, outer_size=None, outer_stride=None
):
weight = tensor_data_dict["weight"]
qtensor_class_list, mode, dtype, shape = tensor_attributes[0]
qtensor_class_list, mode, dtype, shape = tensor_attributes
return cls(
weight,
qtensor_class_list,
Expand Down
Loading