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

Adding more ConvNeXt variants + Speed optimizations #5253

Merged
merged 19 commits into from
Feb 1, 2022

Conversation

datumbox
Copy link
Contributor

@datumbox datumbox commented Jan 21, 2022

Adding convnext_small, convnext_base and convnext_large.

Small

torchrun --nproc_per_node=1 train.py --test-only --prototype --weights ConvNeXt_Small_Weights.IMAGENET1K_V1 --model convnext_small -b 1
Acc@1 83.616 Acc@5 96.650

Base

torchrun --nproc_per_node=1 train.py --test-only --prototype --weights ConvNeXt_Base_Weights.IMAGENET1K_V1 --model convnext_base -b 1
Acc@1 84.062 Acc@5 96.870

Large

torchrun --nproc_per_node=1 train.py --test-only --prototype --weights ConvNeXt_Large_Weights.IMAGENET1K_V1 --model convnext_large -b 1
Acc@1 84.414 Acc@5 96.976

Also switch from channels first + Conv1x1 to channels last + Linear layers as it gets a 20% speed boost.

@facebook-github-bot
Copy link

facebook-github-bot commented Jan 21, 2022

💊 CI failures summary and remediations

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


  • 2/2 failures introduced in this PR

🕵️ 1 new failure recognized by patterns

The following CI failures do not appear to be due to upstream breakages:

See GitHub Actions build CodeQL / build (1/1)

Step: "Build TorchVision" (full log | diagnosis details | 🔁 rerun)

2022-02-01T12:52:57.2791929Z ##[error]Process completed with exit code 1.
2022-02-01T12:52:57.1309743Z     self.finalize_options()
2022-02-01T12:52:57.1310807Z   File "/home/runner/.local/lib/python3.8/site-packages/setuptools/command/develop.py", line 52, in finalize_options
2022-02-01T12:52:57.1311252Z     easy_install.finalize_options(self)
2022-02-01T12:52:57.1312152Z   File "/home/runner/.local/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 276, in finalize_options
2022-02-01T12:52:57.1312603Z     self._fix_install_dir_for_user_site()
2022-02-01T12:52:57.1313539Z   File "/home/runner/.local/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 382, in _fix_install_dir_for_user_site
2022-02-01T12:52:57.1313999Z     self.create_home_path()
2022-02-01T12:52:57.1315068Z   File "/home/runner/.local/lib/python3.8/site-packages/setuptools/command/easy_install.py", line 1338, in create_home_path
2022-02-01T12:52:57.1315590Z     if path.startswith(home) and not os.path.isdir(path):
2022-02-01T12:52:57.1316096Z AttributeError: 'int' object has no attribute 'startswith'
2022-02-01T12:52:57.2791929Z ##[error]Process completed with exit code 1.
2022-02-01T12:52:57.2848483Z Post job cleanup.
2022-02-01T12:52:57.4203399Z [command]/usr/bin/git version
2022-02-01T12:52:57.4259234Z git version 2.34.1
2022-02-01T12:52:57.4302184Z [command]/usr/bin/git config --local --name-only --get-regexp core\.sshCommand
2022-02-01T12:52:57.4349471Z [command]/usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp 'core\.sshCommand' && git config --local --unset-all 'core.sshCommand' || :
2022-02-01T12:52:57.4733281Z [command]/usr/bin/git config --local --name-only --get-regexp http\.https\:\/\/github\.com\/\.extraheader
2022-02-01T12:52:57.4761732Z http.https://github.com/.extraheader
2022-02-01T12:52:57.4771586Z [command]/usr/bin/git config --local --unset-all http.https://github.com/.extraheader
2022-02-01T12:52:57.4831437Z [command]/usr/bin/git submodule foreach --recursive git config --local --name-only --get-regexp 'http\.https\:\/\/github\.com\/\.extraheader' && git config --local --unset-all 'http.https://github.com/.extraheader' || :
2022-02-01T12:52:57.5538642Z Cleaning up orphan processes

1 failure not recognized by patterns:

Job Step Action
CircleCI cmake_macos_cpu curl -o conda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
sh conda.sh -b
source $HOME/miniconda3/bin/activate
conda install -yq conda-build cmake
packaging/build_cmake.sh
🔁 rerun

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.

@datumbox
Copy link
Contributor Author

datumbox commented Jan 31, 2022

image

@s9xie @liuzhuang13 as discussed at #5197 (comment) here are some benchmarks on our side. This is the speed of TorchVision's current implementation 2bbb112 VS after applying this patch 290440b. I understand that your numbers were different but I acknowledge that my benchmarks focus only on a specific batch-size and hardware combination. The difference is big but I was hoping that we could fix the speed difference by optimizing the underlying kernel and avoid needing workarounds on TorchVision. Have you spoken with Core about it? Overall what are your thoughts?

@liuzhuang13
Copy link

@datumbox Thanks! It seems after your patch our implementations are really similar, both using permuting and linear layers. If I understand your results correctly, yours is 15~20% faster than ours somehow. Any idea why? We will benchmark your current patched version against ours too.

@datumbox
Copy link
Contributor Author

datumbox commented Feb 1, 2022

@liuzhuang13 I've assumed it's because I don't use a custom LayerNorm. I would love to know if you can confirm the above with your benchmarks. I've also notified the PyTorch performance team to see if that's something known and work on or something worth improving on the future (I've tagged you and Saining to the post for FYI).

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks @datumbox

@datumbox
Copy link
Contributor Author

datumbox commented Feb 1, 2022

Thanks for the review @NicolasHug. I'm going to move now the class to main TorchVision so that we can include it in the upcoming release.

Edit: On second thought, I'll move the graduation to core area on a separate PR.

@datumbox datumbox marked this pull request as ready for review February 1, 2022 12:42
@datumbox datumbox changed the title [WIP] Adding more ConvNeXt variants Adding more ConvNeXt variants + Speed optimizations Feb 1, 2022
@datumbox datumbox merged commit 82929ae into pytorch:main Feb 1, 2022
@datumbox datumbox deleted the models/convnext_variants branch February 1, 2022 12:51
facebook-github-bot pushed a commit that referenced this pull request Feb 3, 2022
Summary:
* Refactor model builder

* Add 3 more convnext variants.

* Adding weights for convnext_small.

* Fix minor bug.

* Fix number of parameters for small model.

* Adding weights for the base variant.

* Adding weights for the large variant.

* Simplify LayerNorm2d implementation.

* Optimize speed of CNBlock.

* Repackage weights.

Reviewed By: kazhang

Differential Revision: D33927490

fbshipit-source-id: 569d9f752b1c5d5ba6f9a8f9721b4f91fac6663d
@datumbox datumbox mentioned this pull request Feb 11, 2022
24 tasks
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