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

skip connection structure #2

Closed
ZhenpengChenCode opened this issue Nov 21, 2018 · 6 comments
Closed

skip connection structure #2

ZhenpengChenCode opened this issue Nov 21, 2018 · 6 comments

Comments

@ZhenpengChenCode
Copy link

It seems that the OpCounter doesn't take into account the skip connection structure.

@ZhenpengChenCode
Copy link
Author

Resnet flops calculated by the OpCOunter is smaller than the value in paper.

@Lyken17
Copy link
Owner

Lyken17 commented Nov 21, 2018

Yes, as pytorch is a dynamic graph library, it is impossible to determine skip-connection structure at nn.Module level.

One quick fix is to write a special judge for inverted residual block. I'll try to provide a more precise one via tracing computational graph.

@Kylin9511
Copy link
Contributor

Kylin9511 commented Jul 21, 2019

@Lyken17 In torch1.1, a new placeholder module is provided for this kind of awkward situation.

See torch.nn.Idnetity

As I can see, you should add this Module into count_hooks.py and profile.py, counting the extra ops for skip connection.

And update your readme for special notice is important as well that one must use the standard module provided by PyTorch for skip connection to get an accurate FLOPs.

@Lyken17
Copy link
Owner

Lyken17 commented Jul 22, 2019

not really. Most existing codebase still defines the identity connection in forward. The real problem, as I mentioned before, is pytorch's define-by-run philosophy. The only way to record all operations is to trace the DAG.

In this case, please have a look at my labmate's project zhijian-liu/onnx-profiler

@Kylin9511
Copy link
Contributor

What you mentioned is quite right. I didn't say it would fix this problem without changing the codes. If someone would like to call your hook based op-counter while considering skip connection, he can represent skip connection with nn.Identity. And by adding this module to your profile we can fix the problem.

It is kind of a patch, not a global solution.

By unify the model to onnx mode is a very interesting idea, I may look deeper into it some time.

@Kylin9511
Copy link
Contributor

It is kind of like a user-defined patch, so I don't think you should update your project.

@Lyken17 Lyken17 closed this as completed Jul 23, 2019
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

No branches or pull requests

3 participants