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

What is the difference between HarDBlock and HarDBlock_v2? #33

Open
DonghweeYoon opened this issue Apr 10, 2020 · 1 comment
Open

What is the difference between HarDBlock and HarDBlock_v2? #33

DonghweeYoon opened this issue Apr 10, 2020 · 1 comment

Comments

@DonghweeYoon
Copy link

In the source code, only 'validate.py' uses HarDBlock_v2.
And the model with HarDBlock_v2 is faster than that with HarDBlock.
I want to know the difference between v1 and v2.

@PingoLH
Copy link
Owner

PingoLH commented Apr 10, 2020

Hi, thank you for the feedback. They are equivalent in math while HarDBlock_v2 reduces the use of concat such that it is a little bit faster. It first decomposes convolutions from "many to one" to "one by one", then merges the convolutions with the same input tensor.
For example:
X = Conv ( Concat( [A, B] ) )
Y = Conv ( Concat( [A, C] ) )

In HarDBlock_v2, it will be like:
Z = Conv ( A ) // the shape of Z is concat([X,Y])
X = Conv ( B )
Y = Conv ( C )
X += Z[ 0 : X.shape(1) ]
Y += Z[ X.shape(1) : ]

The concatenation can be totally reduced while the block level output concat is still required. It can be faster than the original one because the concatenation involves memory copy which is time-consuming. However, this transformation is not free. The "+=" part requires additional memory accesses as well but just minor than the concatenation. Also, the training time for HarDBlock_v2 is slower than the original one. So, we still urge that pytorch and tensorRT to support convolutions for "discontinuous tensor" such that the concat can be just a pointer-wise operation without any memory copy.

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

2 participants