Skip to content
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
22 changes: 15 additions & 7 deletions torchao/dtypes/uintx/plain_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,16 +253,24 @@ def _linear_fp_act_int8_weight_impl(input_tensor, weight_tensor, bias):
# return torch.ops.aten._weight_int8pack_mm(input_tensor.contiguous(), w_vals_int8_t, weight_tensor.tensor_impl.scale)

# per channel int8 weight only quantizated mm
w_vals_int8_t = weight_tensor.tensor_impl.int_data.t()
w_vals_int8 = weight_tensor.tensor_impl.int_data
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a code path for int8 cuda as well I think, changing it has a risk of perf regressions

also this is the older stack, I'd suggest to migrate first, WIP here for int8 + plain layout: #3038

scale = weight_tensor.tensor_impl.scale
m = torch.mm(
input_tensor.reshape(-1, input_tensor.shape[-1]),
w_vals_int8_t.to(input_tensor.dtype),
)
y = m * scale.to(m.dtype)
try:
y = torch.ops.aten._weight_int8pack_mm(
input_tensor.reshape(-1, input_tensor.shape[-1]),
w_vals_int8,
scale.to(input_tensor.dtype),
)
except Exception:
w_vals_int8_t = w_vals_int8.t()
m = torch.mm(
input_tensor.reshape(-1, input_tensor.shape[-1]),
w_vals_int8_t.to(input_tensor.dtype),
)
y = m * scale.to(m.dtype)
y = y.reshape(*input_tensor.shape[:-1], y.shape[-1])
if bias is not None:
y += bias.to(m.dtype)
y += bias.to(input_tensor.dtype)
return y


Expand Down
Loading