-
Notifications
You must be signed in to change notification settings - Fork 204
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
[CPU] Fix registration of int4wo linear implementation on CPU #1578
base: main
Are you sure you want to change the base?
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/1578
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 6783a22 with merge base de5c6e1 (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
30570e4
to
708d770
Compare
if x_dim == 3: | ||
example_inputs = (example_inputs[0].unsqueeze(0),) | ||
|
||
with torch.no_grad(), torch.autocast( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the model and inputs have already been converted to target data type, why we still need to enable autocast here?
y = torch.ops.aten._weight_int4pack_mm( | ||
act_mat.contiguous(), packed_weight, groupsize, scale_and_zero | ||
) | ||
y = torch.ops.aten._weight_int4pack_mm( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we change _weight_int4pack_mm_for_cpu
to _weight_int4pack_mm
? I remember _weight_int4pack_mm
didn't register for CPU.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this PR, @Xia-Weiwen moved the CPU implementation to torchao/dtypes/uintx/int4_cpu_layout.py
, where support for more activation dtypes is also being added.
This code now exclusively pertains to CUDA.
The FX IR pattern you shared with me after running a toy model did have a call to Is it possible to add a UT for a small model that uses Thanks! |
Summary
Int4wo on CPU does not run into expected mm op (
torch.ops.aten._weight_int4pack_mm_for_cpu
). It seems to be a regression after some refactoring of related code. This PR fixes it by registering a linear impl for theInt4CPULayout
, which callstorch.ops.aten._weight_int4pack_mm_for_cpu
for computation. The new impl is enabled for torch>=2.6. The new impl does not require dtype to be bfloat16. It supports fp32, fp16, bf16 for both weight and activation.Test plan