Skip to content

Conversation

vkuzo
Copy link
Contributor

@vkuzo vkuzo commented Jul 1, 2021

Stack from ghstack:

Summary:

Adds support the comparing fp32 model (without quantization) to a
fp32 model prepared with quantization or a quantized model. The main missing feature was
handling conv-bn fusion, since this fusion for PTQ happens outside
of quantization patterns.

Adds testing for this case for comparing weights and comparing
activations

Adds a TODO for also handling this for shadow activations, we need to
first stop removing observers in graph passes before we can add
this support, will be in a future PR.

Test Plan:

python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2_qat
python test/test_quantization.py TestFXNumericSuiteCoreAPIsModels.test_compare_activations_conv

Reviewers:

Subscribers:

Tasks:

Tags:

Differential Revision: D29520009

Summary:

Adds support the comparing fp32 model (without quantization) to a
fp32 model prepared with quantization. The main missing feature was
handling conv-bn fusion, since this fusion for PTQ happens outside
of quantization patterns.

Adds testing for this case for comparing weights and comparing
activations

Adds a TODO for also handling this for shadow activations, we need to
first stop removing observers in graph passes before we can add
this support, will be in a future PR.

Test Plan:

```
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2_qat
python test/test_quantization.py TestFXNumericSuiteCoreAPIsModels.test_compare_activations_conv
```

Reviewers:

Subscribers:

Tasks:

Tags:

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Jul 1, 2021

💊 CI failures summary and remediations

As of commit b68e341 (more details on the Dr. CI page and at hud.pytorch.org/pr/61129):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


Preview docs built from this PR

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 to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

vkuzo added a commit that referenced this pull request Jul 1, 2021
Summary:

Adds support the comparing fp32 model (without quantization) to a
fp32 model prepared with quantization. The main missing feature was
handling conv-bn fusion, since this fusion for PTQ happens outside
of quantization patterns.

Adds testing for this case for comparing weights and comparing
activations

Adds a TODO for also handling this for shadow activations, we need to
first stop removing observers in graph passes before we can add
this support, will be in a future PR.

Test Plan:

```
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2_qat
python test/test_quantization.py TestFXNumericSuiteCoreAPIsModels.test_compare_activations_conv
```

Reviewers:

Subscribers:

Tasks:

Tags:

ghstack-source-id: 792bbd5
Pull Request resolved: #61129
@vkuzo
Copy link
Contributor Author

vkuzo commented Jul 1, 2021

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

… shadowed"

Summary:

Adds support the comparing fp32 model (without quantization) to a
fp32 model prepared with quantization. The main missing feature was
handling conv-bn fusion, since this fusion for PTQ happens outside
of quantization patterns.

Adds testing for this case for comparing weights and comparing
activations

Adds a TODO for also handling this for shadow activations, we need to
first stop removing observers in graph passes before we can add
this support, will be in a future PR.

Test Plan:

```
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2_qat
python test/test_quantization.py TestFXNumericSuiteCoreAPIsModels.test_compare_activations_conv
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
@vkuzo
Copy link
Contributor Author

vkuzo commented Jul 7, 2021

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

self.assert_ns_compare_dict_valid(results)
# test both m vs mp and mp vs mq
for m1, m2 in ((m, mp), (mp, mq)):
results = extract_weights_fun('a', mp, 'b', mq)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be m1 and m2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, great catch, will fix that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, great catch, will fix that

Copy link

@hx89 hx89 left a comment

Choose a reason for hiding this comment

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

lgtm! Just wonder what would be the use case for comparing fp32 and fp32_prepared? Is it for sanity check to make sure fp32 is numerically the same after prepare and helping debug the implementation of prepare function?

@vkuzo
Copy link
Contributor Author

vkuzo commented Jul 15, 2021

lgtm! Just wonder what would be the use case for comparing fp32 and fp32_prepared? Is it for sanity check to make sure fp32 is numerically the same after prepare and helping debug the implementation of prepare function?

there was a use case discussed during design review to compare fp32 to quantized. This PR implements this functionality (once you can compare A to B and B to C, you can compare A to C). Let me update the summary to say this.

@vkuzo vkuzo changed the title ns for fx: support comparing fp32 vs fp32_prepared, except shadowed ns for fx: support comparing fp32 vs fp32_prepared/int8, except shadowed Jul 15, 2021
…xcept shadowed"


Summary:

Adds support the comparing fp32 model (without quantization) to a
fp32 model prepared with quantization or a quantized model. The main missing feature was
handling conv-bn fusion, since this fusion for PTQ happens outside
of quantization patterns.

Adds testing for this case for comparing weights and comparing
activations

Adds a TODO for also handling this for shadow activations, we need to
first stop removing observers in graph passes before we can add
this support, will be in a future PR.

Test Plan:

```
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2_qat
python test/test_quantization.py TestFXNumericSuiteCoreAPIsModels.test_compare_activations_conv
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
@vkuzo
Copy link
Contributor Author

vkuzo commented Jul 15, 2021

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

…xcept shadowed"


Summary:

Adds support the comparing fp32 model (without quantization) to a
fp32 model prepared with quantization or a quantized model. The main missing feature was
handling conv-bn fusion, since this fusion for PTQ happens outside
of quantization patterns.

Adds testing for this case for comparing weights and comparing
activations

Adds a TODO for also handling this for shadow activations, we need to
first stop removing observers in graph passes before we can add
this support, will be in a future PR.

Test Plan:

```
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2
python test/test_quantization.py TestFXGraphMatcherModels.test_mobilenet_v2_qat
python test/test_quantization.py TestFXNumericSuiteCoreAPIsModels.test_compare_activations_conv
```

Reviewers:

Subscribers:

Tasks:

Tags:

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

[ghstack-poisoned]
@vkuzo
Copy link
Contributor Author

vkuzo commented Jul 17, 2021

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

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in a70505c.

@facebook-github-bot facebook-github-bot deleted the gh/vkuzo/353/head branch July 21, 2021 14:16
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.

4 participants