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

[AFQ] Optimize tensor_flatten for runtime #1114

Open
wants to merge 1 commit into
base: gh/IvanKobzarev/2/base
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion torchao/dtypes/affine_quantized_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ def _quantized_linear_op(input_tensor, weight_tensor, bias):
raise QuantizedLinearNotImplementedError("No specialized dispatch found for quantized linear op")

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