-
Notifications
You must be signed in to change notification settings - Fork 528
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
Add transformer counter to profile #149
base: master
Are you sure you want to change the base?
Conversation
HaoKang-Timmy
commented
Oct 7, 2021
•
edited
Loading
edited
- add transformer counter to rnn_hooks.py
- provide evaluate_transformer.py as an example
count_Transformer for nn.Transformer
The answer is 2.76945964418343e+25 44151808.0.
no embeding ** 2
For one word, about 25G flops and 44M parameters
benchmark/evaluate_transformer.py
Outdated
src = torch.rand((1, 1, 10)) # S,N,x | ||
|
||
|
||
class Model_transformer(nn.Module): |
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.
Class name should be CamelCased.
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
thop/profile.py
Outdated
@@ -67,7 +67,7 @@ def prYellow(skk): fprint("\033[93m{}\033[00m".format(skk)) | |||
nn.RNN: count_rnn, | |||
nn.GRU: count_gru, | |||
nn.LSTM: count_lstm, | |||
|
|||
nn.Transformer: count_Transformer, |
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.
function name should be lower case.
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
thop/rnn_hooks.py
Outdated
@@ -196,3 +196,84 @@ def count_lstm(m: nn.LSTM, x, y): | |||
total_ops *= batch_size | |||
|
|||
m.total_ops += torch.DoubleTensor([int(total_ops)]) | |||
|
|||
|
|||
def count_Transformer(m: nn.Transformer, x, y): |
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.
same issue here.
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, also changed its subfunction, sorry for forgeting changing it after learning camelcase
why not merge this pull? It is very necessary to calculate the flops and prams of transformer. |
Is there any update now |