-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Enhancement] Change the order of condition to make fx wok #2883
Conversation
tests/test_cnn/test_wrappers.py
Outdated
print(gm_module.code) | ||
for Net in (Linear, ): | ||
net = Net(1, 1) | ||
gm_module = fx.symbolic_trace(net) | ||
print(gm_module.code) | ||
for Net in (Conv2d, ConvTranspose2d, Conv3d, ConvTranspose3d): | ||
net = Net(1, 1, 1) | ||
gm_module = fx.symbolic_trace(net) | ||
print(gm_module.code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to print the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, that's used to supress the unused variable
error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you can replace gm_module = fx.symbolic_trace(net)
with fx.symbolic_trace(net)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in fc883ec.
Motivation
mmcv.cnn.bricks.wrappers
has many forward functions in the form ofif x.numel() == 0 and obsolete_torch_version(TORCH_VERSION, (1, 5))
, where the first conditionx.numel() == 0
would failtorch.fx
. We can take advantage of shortcut evaluation, by changing the order of condition toif obsolete_torch_version(TORCH_VERSION, (1, 5)) and x.numel() == 0
. This way, the torch_version compares first, and will not failtorch.fx
in modern pytorch versions.Modification
Change the order of condition, and add tests for it.
BC-breaking (Optional)
This PR does not break any compatibility.