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

Avoid branching in BasicBlock and Bottleneck #8187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kevinMEH
Copy link

Avoid branching during forward pass in BasicBlock and Bottleneck block for better performance.

Completely backwards compatible; downsampled = nn.Identity(x) is equivalent to downsampled = x

Should be always more performant, unless nn.Identity adds some kind of penalty during backprop.

Avoid branching during forward pass in BasicBlock and Bottleneck block for better performance.
Copy link

pytorch-bot bot commented Dec 23, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/vision/8187

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (10 Unrelated Failures)

As of commit 38fa921 with merge base ae6b134 (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@NicolasHug
Copy link
Member

Thanks for the PR @kevinMEH.

I suspect the performance gain coming from removing a single if in the forward pass of resnet would be minimal. I'm interested in looking at some benchmark results, if you have any.

@kevinMEH
Copy link
Author

kevinMEH commented Jan 1, 2024

Every single block layer has an if removed. I think that the performance gain is pretty substantial, however as of right now I cannot spare any GPU time to test it. I will test it once I regain access to a GPU.

@NicolasHug
Copy link
Member

Thanks, let's wait for benchmarks before moving forward with this then.

We should also remember that this if condition is executed on the CPU, which (hopefully) is running way ahead of the GPU. So, evaluating that if condition is not only crazy cheap but probably doesn't even impact any of the time spent on the GPU - which is what dictates the perf here.

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