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] Support lowering of channel shuffle in FX #83731

Closed

Conversation

Xia-Weiwen
Copy link
Collaborator

@Xia-Weiwen Xia-Weiwen commented Aug 19, 2022

Description

Support lowering of channel shuffle in FX by adding its module and functional op to is_copy_node list in torch/ao/quantization/fx/_lower_to_native_backend.py

Validation

UTs added to test

  • correctness of quantized ChannelShuffle module.
  • FX lowering of ChannelShuffle module and functional channel_shuffle.

cc @jerryzh168 @jianyuh @raghuramank100 @jamesr66a @vkuzo @jgong5 @leslie-fang-intel @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10 @ezyang @SherlockNoMad @soumith @EikanWang @wenzhe-nrv

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Aug 19, 2022

🔗 Helpful links

✅ No Failures (0 Pending)

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

Expand to see more

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


This comment was automatically generated by Dr. CI (expand for details).

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

import torch

class ChannelShuffle(torch.nn.ChannelShuffle):
def __init__(self, groups: int):
Copy link
Contributor

Choose a reason for hiding this comment

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

is this constructor needed? since it just passes through the arguments

the base-derived constructor would be sufficient?

and maybe same question about forward impl

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. They are removed.

@mikaylagawarecki mikaylagawarecki added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Aug 19, 2022
@Xia-Weiwen Xia-Weiwen requested review from vadimkantorov and removed request for saketh-are, albanD and jbschlosser August 22, 2022 00:52
@Xia-Weiwen Xia-Weiwen force-pushed the quantized_channel_shuffle branch 2 times, most recently from 7cbcfc8 to 22533a5 Compare August 23, 2022 07:49
@Xia-Weiwen
Copy link
Collaborator Author

@vadimkantorov Please review again. Thanks.

@yanbing-j yanbing-j added intel priority matters to intel architecture from performance wise intel This tag is for PR from Intel labels Aug 24, 2022
@vadimkantorov
Copy link
Contributor

vadimkantorov commented Aug 24, 2022

@Xia-Weiwen I'm not a member of PyTorch team, so a review from someone else is required :)

@Xia-Weiwen
Copy link
Collaborator Author

@Xia-Weiwen I'm not a member of PyTorch team, so a review from someone else is required :)

I see. Thank you anyway.

@Xia-Weiwen
Copy link
Collaborator Author

Hi @jerryzh168 Could you please review this PR? Or could you ask someone else to review? Thanks!

torch.nn.BatchNorm2d,
torch.nn.BatchNorm3d,
torch.nn.ChannelShuffle,
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we have two channel shuffle here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry for the typo. Now they are removed.

@@ -0,0 +1,16 @@
import torch

class ChannelShuffle(torch.nn.ChannelShuffle):
Copy link
Contributor

Choose a reason for hiding this comment

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

if the float version works for quantized inputs as well, I don't think we will need to define an extra quantized module

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK. I have removed them.

@@ -353,6 +353,7 @@ def _get_default_op_configs(dtype_configs: List[DTypeConfig]) -> List[BackendPat
torch.nn.LayerNorm,
torch.nn.Dropout,
torch.nn.PReLU,
torch.nn.ChannelShuffle,
Copy link
Contributor

Choose a reason for hiding this comment

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

should add this to _get_share_qprams_op_backend_config I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have added channel shuffle to copy node list. Is this still needed?

Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

channel shuffle should be categorized as copy node I think, so we don't need to add new quantized modules and configs and lowering need to change as well, please see inline comments for changes

@Xia-Weiwen
Copy link
Collaborator Author

channel shuffle should be categorized as copy node I think, so we don't need to add new quantized modules and configs and lowering need to change as well, please see inline comments for changes

Thanks for reviewing. I have removed most of previous changes. Now I only add it to the is_copy_node list and add two unit tests. Please review again. Thanks.

@Xia-Weiwen Xia-Weiwen requested review from jerryzh168 and removed request for vadimkantorov August 25, 2022 06:26
@Xia-Weiwen Xia-Weiwen force-pushed the quantized_channel_shuffle branch 2 times, most recently from ec6c344 to 874872f Compare October 27, 2022 07:34
Comment on lines 5285 to 5322
models = [M1().eval(), M2().eval(), M3().eval()]
# torch.channel_shuffle is torch.nn.functional.channel_shuffle
expected_nodes = [
ns.call_module(torch.nn.ChannelShuffle),
ns.call_function(torch.channel_shuffle),
ns.call_function(torch.channel_shuffle)
]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: might be better to just write a list of tuple of (model, expected_node) so that it's clearer

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK. It's done. Please take a look.

Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

looks good, please add expected channel shuffle op to node_occurrence as well

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 27, 2022
@Xia-Weiwen
Copy link
Collaborator Author

Hi @jerryzh168 I changed per your comments. All checks have passed. Do you have more comments? Thanks.

@github-actions github-actions bot added the oncall: quantization Quantization support in PyTorch label Nov 4, 2022
@Xia-Weiwen
Copy link
Collaborator Author

Hi @jerryzh168 Do you think it's ok to land this?

Copy link
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

LG, please add a comment in torch/ao/quantization/fx/_lower_to_native_backend.py about why we only need torch.channel_shuffle and not F.channel_shuffle

@Xia-Weiwen
Copy link
Collaborator Author

LG, please add a comment in torch/ao/quantization/fx/_lower_to_native_backend.py about why we only need torch.channel_shuffle and not F.channel_shuffle

Thanks. I will add that comment and land it after all CI checks pass.

@Xia-Weiwen
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@Xia-Weiwen Xia-Weiwen deleted the quantized_channel_shuffle branch December 1, 2022 05:43
kulinseth pushed a commit to kulinseth/pytorch that referenced this pull request Dec 10, 2022
## Description
Support lowering of channel shuffle in FX by adding its module and functional op to `is_copy_node` list in `torch/ao/quantization/fx/_lower_to_native_backend.py`

## Validation
UTs added to test
- correctness of quantized `ChannelShuffle` module.
- FX lowering of `ChannelShuffle` module and functional `channel_shuffle`.

Pull Request resolved: pytorch#83731
Approved by: https://github.com/jerryzh168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/trunk Trigger trunk jobs on your pull request cla signed fx intel priority matters to intel architecture from performance wise intel This tag is for PR from Intel Merged oncall: quantization Quantization support in PyTorch open source release notes: quantization release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

8 participants