fake_quant: make qparams shape consistent#38587
Closed
vkuzo wants to merge 4 commits intogh/vkuzo/66/basefrom
Closed
fake_quant: make qparams shape consistent#38587vkuzo wants to merge 4 commits intogh/vkuzo/66/basefrom
vkuzo wants to merge 4 commits intogh/vkuzo/66/basefrom
Conversation
Summary: Before this diff, scale+zp were initialized to tensors with a single dimension and 1 element, and then switched to scalar tensors after the first forward. This diff makes the shape stay consistent. This should fix an issue reported when saving/loading models, which crashes on this inconsistent shape. Test Plan: ``` python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations ``` Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
vkuzo
added a commit
that referenced
this pull request
May 15, 2020
Summary: Before this diff, scale+zp were initialized to tensors with a single dimension and 1 element, and then switched to scalar tensors after the first forward. This diff makes the shape stay consistent. This should fix an issue reported when saving/loading models, which crashes on this inconsistent shape. Test Plan: ``` python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations ``` Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: c090edd Pull Request resolved: #38587
💊 CI failures summary and remediationsAs of commit c087aad (more details on the Dr. CI page):
🕵️ 2 new failures recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
| Job | Step | Action |
|---|---|---|
| Build | 🔁 rerun |
ci.pytorch.org: 1 failed
This comment was automatically generated by Dr. CI (expand for details).
Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.
This comment has been revised 16 times.
Summary: Before this diff, scale+zp were initialized to tensors with a single dimension and 1 element, and then switched to scalar tensors after the first forward. This diff makes the shape stay consistent. This should fix an issue reported when saving/loading models, which crashes on this inconsistent shape. Test Plan: ``` python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations ``` Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21605532](https://our.internmc.facebook.com/intern/diff/D21605532) [ghstack-poisoned]
Summary: Before this diff, scale+zp were initialized to tensors with a single dimension and 1 element, and then switched to scalar tensors after the first forward. This diff makes the shape stay consistent. This should fix an issue reported when saving/loading models, which crashes on this inconsistent shape. Test Plan: ``` python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations ``` Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21605532](https://our.internmc.facebook.com/intern/diff/D21605532) [ghstack-poisoned]
vkuzo
added a commit
that referenced
this pull request
May 19, 2020
Summary: Before this diff, scale+zp were initialized to tensors with a single dimension and 1 element, and then switched to scalar tensors after the first forward. This diff makes the shape stay consistent. This should fix an issue reported when saving/loading models, which crashes on this inconsistent shape. Test Plan: ``` python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations ``` Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: a8244db Pull Request resolved: #38587
| x = torch.rand(4, 4, 4, 4) | ||
| m(x) | ||
| scale_shape_after = m.linear.activation_post_process.scale.shape | ||
| zero_point_shape_after = m.linear.activation_post_process.zero_point.shape |
Contributor
There was a problem hiding this comment.
Looks good, should we also check for per-channel quant (i.e the weights?)
Contributor
Author
There was a problem hiding this comment.
just double checked, we expect the per-channel params to change (for C > 1), so it did not have the issue solved by this diff
raghuramank100
approved these changes
May 21, 2020
Summary: Before this diff, scale+zp were initialized to tensors with a single dimension and 1 element, and then switched to scalar tensors after the first forward. This diff makes the shape stay consistent. This should fix an issue reported when saving/loading models, which crashes on this inconsistent shape. Test Plan: ``` python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations ``` Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D21605532](https://our.internmc.facebook.com/intern/diff/D21605532) [ghstack-poisoned]
vkuzo
added a commit
that referenced
this pull request
May 21, 2020
Summary: Before this diff, scale+zp were initialized to tensors with a single dimension and 1 element, and then switched to scalar tensors after the first forward. This diff makes the shape stay consistent. This should fix an issue reported when saving/loading models, which crashes on this inconsistent shape. Test Plan: ``` python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations ``` Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: eab594c Pull Request resolved: #38587
Contributor
|
This pull request has been merged in 8d8b586. |
laurentdupin
pushed a commit
to laurentdupin/pytorch
that referenced
this pull request
Apr 24, 2026
Summary: Pull Request resolved: pytorch#38587 Before this diff, scale+zp were initialized to tensors with a single dimension and 1 element, and then switched to scalar tensors after the first forward. This diff makes the shape stay consistent. This should fix an issue reported when saving/loading models, which crashes on this inconsistent shape. Test Plan: ``` python test/test_quantization.py TestFakeQuantizePerTensor.test_fake_quant_preserves_qparam_shapes_for_activations ``` Imported from OSS Differential Revision: D21605532 fbshipit-source-id: e00cd268d6d3ded1006d18d6c6759c911b3a74ea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack:
Summary:
Before this diff, scale+zp were initialized to tensors
with a single dimension and 1 element, and then switched
to scalar tensors after the first forward.
This diff makes the shape stay consistent. This should fix
an issue reported when saving/loading models, which crashes
on this inconsistent shape.
Test Plan:
Reviewers:
Subscribers:
Tasks:
Tags:
Differential Revision: D21605532