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

[Quant] Bug fix #107899

Closed
wants to merge 5 commits into from
Closed

Conversation

kimishpatel
Copy link
Contributor

@kimishpatel kimishpatel commented Aug 24, 2023

Stack from ghstack (oldest at bottom):

Summary:
When two layers are quantized differently, observer map update updates
map for key (observed_node, node), whereas it should really be
(original_input, node)

Test Plan:
Test in the next diff adds a test where it otherwise fails

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D48663145

Summary:
When two layers are quantized differently, observer map update updates
map for key (observed_node, node), whereas it should really be
(original_input, node)

Test Plan:
Test in the next diff adds a test where it otherwise fails

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Aug 24, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/107899

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit b25f1b6 with merge base 0f1a225 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@kimishpatel
Copy link
Contributor Author

@kimishpatel has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@@ -92,6 +92,16 @@ def _maybe_insert_input_observer_for_arg_or_kwarg(
new_obs_node = _insert_obs_or_fq(
arg, arg_as_input_act_obs_or_fq, model, named_modules, model.graph) # type: ignore[arg-type]
new_arg = new_obs_node
# When quantizing two layers with different configs we can have
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a test for this? surprised that this is not caught earlier..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so didnt add separate test because the PR after this one fails for exactly this reason. Also we havent tested quantizing a different layers with different configs (which is what the next diff does). Hence did not catch it.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK sounds good

Summary:
When two layers are quantized differently, observer map update updates
map for key (observed_node, node), whereas it should really be
(original_input, node)

Test Plan:
Test in the next diff adds a test where it otherwise fails

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D48663145](https://our.internmc.facebook.com/intern/diff/D48663145)

[ghstack-poisoned]
Summary:
When two layers are quantized differently, observer map update updates
map for key (observed_node, node), whereas it should really be
(original_input, node)

Test Plan:
Test in the next diff adds a test where it otherwise fails

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D48663145](https://our.internmc.facebook.com/intern/diff/D48663145)

[ghstack-poisoned]
Summary:
When two layers are quantized differently, observer map update updates
map for key (observed_node, node), whereas it should really be
(original_input, node)

Test Plan:
Test in the next diff adds a test where it otherwise fails

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D48663145](https://our.internmc.facebook.com/intern/diff/D48663145)

[ghstack-poisoned]
@kimishpatel
Copy link
Contributor Author

@kimishpatel has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

3 similar comments
@kimishpatel
Copy link
Contributor Author

@kimishpatel has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@kimishpatel
Copy link
Contributor Author

@kimishpatel has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@kimishpatel
Copy link
Contributor Author

@kimishpatel has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Summary:
When two layers are quantized differently, observer map update updates
map for key (observed_node, node), whereas it should really be
(original_input, node)

Test Plan:
Test in the next diff adds a test where it otherwise fails

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D48663145](https://our.internmc.facebook.com/intern/diff/D48663145)

[ghstack-poisoned]
@kimishpatel
Copy link
Contributor Author

@kimishpatel has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@kimishpatel
Copy link
Contributor Author

@kimishpatel has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

pytorchmergebot pushed a commit that referenced this pull request Sep 2, 2023
Summary:
During convert step observers are first replaced by Q-DQ pair. In some
scenarios like following output DQ has a fan out.

                 ---> OP2 -> Q -> DQ
                /
OP -> Q -> DQ -
                \
                 ---> OP3 -> Q -> DQ

If either op OP2 or OP3 are configured to be quantized, then the input
is expected to quantized. In this case quantized equivalent of some
pattern, that quantizer asked to be quantized, should look like:
[DQ -> {pattern} -> Q]. However, in scenario like above where DQ node
is shared between multiple "quantized" patterns, boundary of "quantized"
pattern is not clear because DQ now belongs to multiple quantized
patterns.

This poses challenge for:
- Porting metadata: which "quantized" partition this DQ node belongs
- Quantized representation, equivalently, needs to identify
self-contained quantized pattern that is replaced by its equivalent pattern
that captures compute in the quantized precision.

Test Plan:
test_duplicate_dq_pass

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D48663147](https://our.internmc.facebook.com/intern/diff/D48663147)

Pull Request resolved: #107900
Approved by: https://github.com/jerryzh168, https://github.com/andrewor14, https://github.com/leslie-fang-intel
ghstack dependencies: #107105, #107106, #107899
pytorchmergebot pushed a commit that referenced this pull request Sep 2, 2023
…107107)

Summary:
This diff adds adding metadata to q-dq nodes by inferring the
quatization intent from node annotations. Annotations on the node are
way for user to specify how a node or subgraph is supposed to be
quantized. We continue to use that information to copy metadata on Q/DQ
node from appropriate nodes.

Test Plan:

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: [D48488416](https://our.internmc.facebook.com/intern/diff/D48488416)
Pull Request resolved: #107107
Approved by: https://github.com/jerryzh168
ghstack dependencies: #107105, #107106, #107899, #107900
@facebook-github-bot facebook-github-bot deleted the gh/kimishpatel/176/head branch September 5, 2023 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants