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

slow BERT MLM evaluation #375

Closed
tstadel opened this issue May 27, 2020 · 4 comments · Fixed by #377
Closed

slow BERT MLM evaluation #375

tstadel opened this issue May 27, 2020 · 4 comments · Fixed by #377
Assignees
Labels
enhancement New feature or request

Comments

@tstadel
Copy link
Member

tstadel commented May 27, 2020

Describe the bug
Evaluation of BERT MLM head takes a lot of time due to unnecessary GPU to CPU overhead. argmax on logits should be called before shifting the tensor to cpu.

Expected behavior
Evaluation of BERT MLM head should be as fast as possible as it delays training.

To Reproduce
run lm_finetuning.py from examplex

System:

  • OS: Ubuntu 18.04
  • GPU/CPU: GPU
  • FARM version: newest
@tstadel tstadel added the bug Something isn't working label May 27, 2020
@tstadel
Copy link
Member Author

tstadel commented May 27, 2020

Besides the GPU to CPU overhead there are list appending for loops in logits_to_preds and prepare_labels. Converting them to list comprehensions also increases evaluation speed as the loop is hit 30k times in case of BERT. However, I assume, this might be a performance vs. understandability issue.

@tstadel
Copy link
Member Author

tstadel commented May 27, 2020

Additionally in Evaluator's eval function there is a seemingly unnecessary casting to numpy and back to list (line 75 and 76):
preds_all[head_num] += list(to_numpy(preds[head_num]))
label_all[head_num] += list(to_numpy(labels[head_num]))

For MLM, NSP and TextClassifiationHeads this is not necessary. Are there any cases, in which we need this?

@tstadel
Copy link
Member Author

tstadel commented May 28, 2020

I quickly ran some tests regarding the two comments: performance is only affected if a debugger is attached.

@tholor tholor added enhancement New feature or request and removed bug Something isn't working labels May 28, 2020
@tholor
Copy link
Member

tholor commented May 28, 2020

Thanks for spotting & fixing this @tstadel ! Highly appreciated :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants