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

Nano: Add support for channels_last #5103

Merged
merged 15 commits into from
Jul 20, 2022

Conversation

y199387
Copy link
Contributor

@y199387 y199387 commented Jul 14, 2022

Description

This pr Add support for automatically converting model and data's memory_format to channels_last.
If user instantiate nano.pytorch.Tainer with channels_last=True,the model will be converted to channels_last and its hook function on_before_batch_transfer will be replaced at setup stage. The replaced on_before_batch_transfer function will convert every batch to data with memory_format=channels_last.

1. Why the change?

Channels Last improves the throughput of convolution operations in networks for computer vision. Using channels_last and ipex at the same time can get better acceleration effect. It's
necessary to provide user a simple way to apply torch.channels to both of the model object and data.
https://github.com/analytics-zoo/nano/issues/170

2. Summary of the change

3. How to test?

  • Unit test

@y199387 y199387 marked this pull request as draft July 18, 2022 03:04
class ConvModel(torch.nn.Module):
def __init__(self):
super().__init__()
self.conv1 = torch.nn.Conv2d(2, 1, (1, 2), bias=False)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For Convolutional layer with only one channel, the layer.param.is_contiguous() & layer.param.is_contiguous(memory_format=torch.channels_last) is True after the model is converted to channels_last.

@y199387 y199387 marked this pull request as ready for review July 18, 2022 06:17
@yangw1234
Copy link
Contributor

you may also rebase on main since we updated the github actions workflows

@y199387 y199387 force-pushed the add-channel-last-support branch from 9a43814 to edcb900 Compare July 19, 2022 06:17
@yangw1234
Copy link
Contributor

@yangw1234 yangw1234 merged commit 6b3e4d0 into intel-analytics:main Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants