-
Notifications
You must be signed in to change notification settings - Fork 257
[PT2E] Fix per-tensor observer issue with varying shape & rank #2177
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
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/2177
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New FailureAs of commit 330e2c0 with merge base 07ca637 ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
87f1249
to
2ac41fb
Compare
@@ -1891,6 +1891,10 @@ def convert(self, model: torch.fx.GraphModule, observer_node: Node): | |||
assert self.original_dtype is not None, ( | |||
"Expecting original_dtype to be populated" | |||
) | |||
# Since input shape & rank may change (e.g. Resnet18), here we need to update block_size for each input | |||
self.block_size = get_block_size( |
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.
when does this happen? can you give an example? I thought using -1
for dynamic dimensions will be enough?
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.
To reproduce the issue, you may run the code here: #2094 (comment)
You will have to using -1
for block_size
without updating of self.block_size
here.
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.
are you saying the rank / number of dimension changes for input as well? can we use a single -1
to represent this case?
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.
are you saying the rank / number of dimension changes for input as well?
Yes
can we use a single -1 to represent this case?
I think it's doable. But there are checks to guard len(self.block_size) == len(input.shape)
. We need to handle the special case for per-tensor quant at these locations. Is it ok?
Fixes #2094 and #2112
We may find inputs with varying shapes and ranks, e.g. when running Resnet18. The current implementation is based on block_size, which is not enough for such cases. The fix is simple: use block_size = -1 for each dimension for per-tensor quantization and update block_size for each input when inserting q/dq in
convert
.