[quant] add quantized::batch_norm#39910
[quant] add quantized::batch_norm#39910jerryzh168 wants to merge 8 commits intogh/jerryzh168/345/basefrom
Conversation
Summary: We need this for graph mode quantization, since we only have `aten::batch_norm` the dimension is only known at runtime, we'll need to quantize it to `quantized::batch_norm` Test Plan: Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit cefc65d (more details on the Dr. CI page): 💚 💚 Looks good so far! There are no failures yet. 💚 💚 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 24 times. |
Summary: We need this for graph mode quantization, since we only have `aten::batch_norm` the dimension is only known at runtime, we'll need to quantize it to `quantized::batch_norm` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D22012281](https://our.internmc.facebook.com/intern/diff/D22012281) [ghstack-poisoned]
Summary: We need this for graph mode quantization, since we only have `aten::batch_norm` the dimension is only known at runtime, we'll need to quantize it to `quantized::batch_norm` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D22012281](https://our.internmc.facebook.com/intern/diff/D22012281) [ghstack-poisoned]
Summary: We need this for graph mode quantization, since we only have `aten::batch_norm` the dimension is only known at runtime, we'll need to quantize it to `quantized::batch_norm` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D22012281](https://our.internmc.facebook.com/intern/diff/D22012281) [ghstack-poisoned]
Summary: We need this for graph mode quantization, since we only have `aten::batch_norm` the dimension is only known at runtime, we'll need to quantize it to `quantized::batch_norm` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D22012281](https://our.internmc.facebook.com/intern/diff/D22012281) [ghstack-poisoned]
Summary: We need this for graph mode quantization, since we only have `aten::batch_norm` the dimension is only known at runtime, we'll need to quantize it to `quantized::batch_norm` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D22012281](https://our.internmc.facebook.com/intern/diff/D22012281) [ghstack-poisoned]
Summary: We need this for graph mode quantization, since we only have `aten::batch_norm` the dimension is only known at runtime, we'll need to quantize it to `quantized::batch_norm` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D22012281](https://our.internmc.facebook.com/intern/diff/D22012281) [ghstack-poisoned]
for dimension, are we talking about BatchNorm{1|2|3}d? If so, can we get it from the module, since the majority of users will probably be using the default PT modules? |
| } | ||
|
|
||
| TORCH_LIBRARY_IMPL(quantized, QuantizedCPU, m) { | ||
| m.impl("batch_norm", q_batch_norm_impl<false>); |
There was a problem hiding this comment.
is this function pointing to the 2d/3d implementations, but not supporting the 1d implementation? Not sure if that's super intuitive. Can we add a comment on why this is needed?
There was a problem hiding this comment.
yeah, ideally this should support 1d as well, but there is no support for 1d atm. sure I'll add a comment
yeah, dim refers to batch_norm 1d/2d/3d, this informations is not available in aten ops, it's available only in module. we can't get it from module, we are dealing with aten ops in the IR. |
makes sense for the current implementation. I'm more asking for my own understanding, this info is in the graph before inlining, and we technically could spend eng time to preserve this info through the passes (by adding a new attribute, etc) if we really needed to (not saying we should do this, just trying to understand). Just curious if I understood that correctly. |
Summary: We need this for graph mode quantization, since we only have `aten::batch_norm` the dimension is only known at runtime, we'll need to quantize it to `quantized::batch_norm` Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: [D22012281](https://our.internmc.facebook.com/intern/diff/D22012281) [ghstack-poisoned]
the dimension info is encoded in the check function right now: https://github.com/pytorch/pytorch/blob/master/torch/nn/modules/batchnorm.py#L190, the check function will be different for each module. we'll need to analyze the code to extract this info. Another thing is if people use F.batch_norm(https://github.com/pytorch/pytorch/blob/master/torch/nn/functional.py#L1998), there is no way we can get the dimension info, the dimension is known at runtime. |
|
In general this comes from the discrepancy of the APIs between floating point op and quantized op, we have although in the future I think we should move towards breaking |
oh, I was asking about parsing it from the module type instead, not from the graph of the function calls. I.e. if someone is running a vanilla nn.BatchNorm{1|2|3}d Is that challenging / not possible to capture that from the module graph before any kind of inlining, and then assign it to the correponding aten node in the inlining pass? To clarify, not suggesting it, more just looking to understand curious on if this possible in the future if it's needed. |
This is certainly possible, but I don't think we'll do this in the future. I think you'll get a better idea as you work more on graph mode. We would like to restrict the analysis and transformations locally instead of spreading it out, e.g. you mentioned we need to get this information in module and then "pass" it to aten node, we would only do this when it is absolutely necessary I think, since this can be achieved with a much simpler alternative, as shown in the PR, I don't think it make sense to do it. |
thanks a ton. This is really helpful to understand the past tradeoffs and design principles taken in this codebase. |
|
This pull request has been merged in 1a388da. |
Summary: Pull Request resolved: pytorch#39910 We need this for graph mode quantization, since we only have `aten::batch_norm` the dimension is only known at runtime, we'll need to quantize it to `quantized::batch_norm` Test Plan: Imported from OSS Differential Revision: D22012281 fbshipit-source-id: 2973d86a17a02b7bdc36bd1e703e91584d9139d0
Summary: Pull Request resolved: pytorch#39910 We need this for graph mode quantization, since we only have `aten::batch_norm` the dimension is only known at runtime, we'll need to quantize it to `quantized::batch_norm` Test Plan: Imported from OSS Differential Revision: D22012281 fbshipit-source-id: 2973d86a17a02b7bdc36bd1e703e91584d9139d0
Stack from ghstack:
repeat#39925 [quant][graphmode] Support quantizingrepeatSummary:
We need this for graph mode quantization, since we only have
aten::batch_normthe dimensionis only known at runtime, we'll need to quantize it to
quantized::batch_normTest Plan:
Reviewers:
Subscribers:
Tasks:
Tags:
Differential Revision: D22012281