transformers icon indicating copy to clipboard operation
transformers copied to clipboard

pre-training a BERT from scratch

Open chiyuzhang94 opened this issue 7 years ago • 29 comments

I am wondering whether I can train a new BERT from scratch with this pytorch BERT.

chiyuzhang94 avatar Mar 17 '19 00:03 chiyuzhang94

We can't now. The code is still incomplete. Is it possible recently? I really want to help but not familiar with tensorflow.

dataaug avatar Mar 18 '19 03:03 dataaug

A related issue is #376.

However, pytorch-pretraned-BERT was mostly designed to provide easy and fast access to pretrained models.

If you want to train a BERT model from scratch you will need a more robust code base for training and data-processing than the simple examples that are provided in this repo.

I would probably advise to move to a more integrated codebase like the nice XLM repo of @glample and @aconneau.

thomwolf avatar Mar 19 '19 09:03 thomwolf

I've been able to use the codebase for this, and didn't see much issues, however I might be overlooking something. If you construct and initialize a new model instead of loading from pretrained, you can use the simple_lm_finetuning script to train on new data.

Thomas, did you have any specific other issues in mind?

mttk avatar Apr 26 '19 12:04 mttk

NVidia recently released TF and PyTorch code to pretrain Bert from scratch. I wrapped it in a script to launch on multiple machines on AWS here. Currently I'm still figuring out why the 64-GPU AWS throughput is 2x worse than what they are getting locally

yaroslavvb avatar Apr 28 '19 00:04 yaroslavvb

Thanks @yaroslavvb!

thomwolf avatar Apr 28 '19 08:04 thomwolf

Thanks! @yaroslavvb

YangWang92 avatar Apr 30 '19 06:04 YangWang92

@yaroslavvb this article explains why cloud computing can have inconsistent throughput. I think it's a great read, and I've been working on setting up my own rig.

I see in the script that you're using 8 GPUs. have long is the pretraining taking with that? I'm not sure whether to go with gcloud TPUs or AWS. the Bert readme said that a single TPU will take up to 2 weeks to finish pretaining..

jrc2139 avatar May 06 '19 09:05 jrc2139

@yaroslavvb hi, did you train bert successfully? I trained it with https://github.com/NVIDIA/Megatron-LM/scripts/pretrain_bert_tfrecords_distributed.sh on 2 machines with 16 GPUS, but when it was sotpped after ' > number of parameters: 336226108' and i got nothing else after that, the GPU-Util is 0%.

MarvinLong avatar May 10 '19 03:05 MarvinLong

@MarvinLong yes, I was able to launch it on multiple machines and observe the model training, and it's about 600ms per step. I did not try training it to completion as the scaling efficiency on p3dn instances on AWS is only about 50% because of NCCL bug currently. I'm wondering if your machines can't communicate to each other on the right ports. @jrc2139 I have not observed inconsistent throughput, I've used this codebase to train imagenet in 19 minutes on 64 GPUs on AWS p3 instances.

yaroslavvb avatar May 23 '19 03:05 yaroslavvb

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 22 '19 04:07 stale[bot]

I've been able to use the codebase for this, and didn't see much issues, however I might be overlooking something. If you construct and initialize a new model instead of loading from pretrained, you can use the simple_lm_finetuning script to train on new data.

Thomas, did you have any specific other issues in mind?

I'm trying to train on my own custom data and I'm a bit confused about how to "construct and initialize a new model"—i.e., when not working with pretrained models. Any help appreciated.

jbmaxwell avatar Jul 23 '19 19:07 jbmaxwell

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 21 '19 21:09 stale[bot]

@yaroslavvb Hi, I can launch Megatron-LM to pretrain bert, but my MLM loss stay around 6.8. How about you? Can you pretrain BERT successfully?

JF-D avatar Apr 21 '20 09:04 JF-D

@yaroslavvb Hi, I can launch Megatron-LM to pretrain bert, but my MLM loss stay around 6.8. How about you? Can you pretrain BERT successfully?

I was able to pre-train using this repo [https://github.com/google-research/bert]. However, even with one million step, the MLM accuracy was 64.69% and it's loss was 2.4. I am eager to know if someone else has pre-trained and got MLM accuracy higher than this.

ibrahimishag avatar Apr 23 '20 05:04 ibrahimishag

@yaroslavvb Hi, I can launch Megatron-LM to pretrain bert, but my MLM loss stay around 6.8. How about you? Can you pretrain BERT successfully?

I was able to pre-train using this repo [https://github.com/google-research/bert]. However, even with one million step, the MLM accuracy was 64.69% and it's loss was 2.4. I am eager to know if someone else has pre-trained and got MLM accuracy higher than this.

According to the pretrian log from gloun-nlphttps://github.com/dmlc/web-data/blob/master/gluonnlp/logs/bert/bert_base_pretrain.log, your MLM accuracy seems right though with a higher loss. I think you can try to check it with fintuning.

JF-D avatar Apr 23 '20 05:04 JF-D

@ibrahimishag I want to know if you pretrain your BERT with Bookscorpus. I cannot find a copy of that. For my pretraining, my bert loss is decreasing so so slowly after removing clip-grad-norm. There must be something wrong with me.

JF-D avatar Apr 23 '20 14:04 JF-D

@JF-D I pre-trained on other domain-specific corpus.

ibrahimishag avatar Apr 27 '20 08:04 ibrahimishag

Can someone please specify why Thomas mention/refers XLM repo from facebook? Is there any fault from huggingface? I thought I would just use hugging face repo without using "pretrained paramater" they generously provided for us.

Just struggling with Facebook repo"span bert" and seems it is hard to even run this due to distributed launch issue. Hope it is ok to use hugging face's one to reproduce paper result

muiPomeranian avatar May 18 '20 23:05 muiPomeranian

Is it possible to train from scratch using the run_language_modeling.py code? does hugging face support training from scratch. I looked at this example https://huggingface.co/blog/how-to-train but this thread is hitting that training from scratch is not currently supported.

kaoutar55 avatar Jun 01 '20 21:06 kaoutar55

Any update on training from scratch BERT-like models with huggingface?

UmarSpa avatar Oct 08 '20 08:10 UmarSpa