Skip to content
Merged
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
20 changes: 12 additions & 8 deletions torchao/dtypes/affine_quantized_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,18 @@ def dequantize(self, output_dtype: Optional[torch.dtype] = None) -> torch.Tensor
return dq

def __tensor_flatten__(self):
return ["tensor_impl"], [
self.block_size,
self.shape,
self.quant_min,
self.quant_max,
self.zero_point_domain,
self.dtype,
]
# This is used in rumtime to unwrap AffineQuantizedTensor activations.
# AffineQuantizedTensor has __torch_function__ override:
# Each getattr will go through it, which is up to 10x slower than default attribute access.
with torch._C.DisableTorchFunctionSubclass():
return ["tensor_impl"], [
self.block_size,
self.shape,
self.quant_min,
self.quant_max,
self.zero_point_domain,
self.dtype,
]

@classmethod
def __tensor_unflatten__(
Expand Down
Loading