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

[reland][quant] Remove nn.quantized.ReLU module and nn.quantized.functional.relu (#47415) #48038

Closed
wants to merge 5 commits into from

Conversation

jerryzh168
Copy link
Contributor

@jerryzh168 jerryzh168 commented Nov 16, 2020

Stack from ghstack:

Summary:
nn.ReLU works for both float and quantized input, we don't want to define an nn.quantized.ReLU
that does the same thing as nn.ReLU, similarly for nn.quantized.functional.relu

this also removes the numerical inconsistency for models quantizes nn.ReLU independently in qat mode

Test Plan: Imported from OSS

Reviewed By: z-a-f

Differential Revision: D25000462

…tional.relu (#47415)

Summary:
nn.ReLU works for both float and quantized input, we don't want to define an nn.quantized.ReLU
that does the same thing as nn.ReLU, similarly for nn.quantized.functional.relu

this also removes the numerical inconsistency for models quantizes nn.ReLU independently in qat mode

Test Plan: Imported from OSS

Reviewed By: z-a-f

[ghstack-poisoned]
…ntized.functional.relu (#47415)"

Summary:
nn.ReLU works for both float and quantized input, we don't want to define an nn.quantized.ReLU
that does the same thing as nn.ReLU, similarly for nn.quantized.functional.relu

this also removes the numerical inconsistency for models quantizes nn.ReLU independently in qat mode

Test Plan: Imported from OSS

Reviewed By: z-a-f

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

[ghstack-poisoned]
Comment on lines 42 to 45
if type(mod) == torch.nn.intrinsic.qat.ConvBnReLU1d:
mod.weight, mod.bias = fuse_conv_bn_weights(
mod.weight, mod.bias, mod.bn.running_mean, mod.bn.running_var,
mod.bn.eps, mod.bn.weight, mod.bn.bias)
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts about moving this to a separate PR to minimize risk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@@ -21,11 +21,9 @@ def _get_name(self):

@classmethod
def from_float(cls, mod):
activation_post_process = mod.activation_post_process
Copy link
Contributor

Choose a reason for hiding this comment

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

any chance you could expand on the reasoning for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, previous code is relying on the fact the we attach activation_post_process to ReLU inside the sequential, but this PR removes activation_post_process for ReLU, so we changed the insert observer logic to add activation_post_process to sequential directly so we don't need to get activation_post_process from relu any more

activation_post_process = mod[1].activation_post_process	

this is getting activation_post_proceess from relu.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense, thanks! maybe we can add a quick comment to the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will add a comment to the place we attach activation_post_process for _FusedModule (in quantization/quantize.py)

@@ -137,14 +136,18 @@ def insert_activation_post_process(m, special_act_post_process=None):
m._forward_hooks.move_to_end(handle.id, last=False)

for name, child in module.named_children():
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to add a stronger test for this section to help catch future issues? For example, something like a model which has modules going through all of the branches in these if statements, passing some data through it, and verifying that every observer has seen values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we do have tests for each of the branches, although it's probably spread out in different op tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we make an artificial model, not sure it would be runnable or not actually.

Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't have to be this PR (since we are adding an fb-only test), but seems like just increasing integration model coverage for matching numerics between eager and FX would be valuable. It seems like TestQuantizeFxModels has various models commented out, perhaps we can invest in increasing coverage a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I think we should add more e2e tests as well

…ntized.functional.relu (#47415)"

Summary:
nn.ReLU works for both float and quantized input, we don't want to define an nn.quantized.ReLU
that does the same thing as nn.ReLU, similarly for nn.quantized.functional.relu

this also removes the numerical inconsistency for models quantizes nn.ReLU independently in qat mode

Test Plan: Imported from OSS

Reviewed By: z-a-f

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

[ghstack-poisoned]
Copy link
Contributor

@vkuzo vkuzo left a comment

Choose a reason for hiding this comment

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

lg if the fb-only test passes, thanks!

…ntized.functional.relu (#47415)"

Summary:
nn.ReLU works for both float and quantized input, we don't want to define an nn.quantized.ReLU
that does the same thing as nn.ReLU, similarly for nn.quantized.functional.relu

this also removes the numerical inconsistency for models quantizes nn.ReLU independently in qat mode

Test Plan: Imported from OSS

Reviewed By: z-a-f

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

[ghstack-poisoned]
@dr-ci
Copy link

dr-ci bot commented Nov 17, 2020

💊 CI failures summary and remediations

As of commit be090d7 (more details on the Dr. CI page):


  • 2/8 failures possibly* introduced in this PR
    • 2/2 non-CircleCI failure(s)
  • 6/8 broken upstream at merge base fa0acb7 since Nov 16

🚧 6 ongoing upstream failures:

These were probably caused by upstream breakages that are not fixed yet:


ci.pytorch.org: 2 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.

See how this bot performed.

This comment has been revised 9 times.

…ntized.functional.relu (#47415)"

Summary:
nn.ReLU works for both float and quantized input, we don't want to define an nn.quantized.ReLU
that does the same thing as nn.ReLU, similarly for nn.quantized.functional.relu

this also removes the numerical inconsistency for models quantizes nn.ReLU independently in qat mode

Test Plan: Imported from OSS

Reviewed By: z-a-f

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

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

This pull request has been merged in 8aaca4b.

@facebook-github-bot facebook-github-bot deleted the gh/jerryzh168/503/head branch November 21, 2020 15:15
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.

None yet

3 participants