Exploding in WMT14 en-fr
Hello. I've processed my data and set training parameters as the same in pre-trained models/wmt14.en-fr.fconv-py/README.md. However, I get
| [en] dictionary: 43881 types
| [fr] dictionary: 43978 types
| data-bin train 35482842 examples
| data-bin valid 26663 examples
| data-bin test 3003 examples
| using 8 GPUs (with max tokens per GPU = 4000)
| model fconv_wmt_en_fr
Warning! 1 samples are either too short or too long and will be ignored, sample ids=[28743556]
| epoch 001 1000 / 331737 loss=9.57 (10.94), wps=18515, wpb=31259, bsz=861, lr=1.25, clip=100%, gnorm=2.0540
| epoch 001 2000 / 331737 loss=8.61 (9.91), wps=18466, wpb=31229, bsz=877, lr=1.25, clip=100%, gnorm=1.7149
| epoch 001 3000 / 331737 loss=7.50 (9.23), wps=18493, wpb=31226, bsz=871, lr=1.25, clip=100%, gnorm=2.7501
| epoch 001 4000 / 331737 loss=6.87 (8.75), wps=18522, wpb=31231, bsz=873, lr=1.25, clip=100%, gnorm=100615.8788
| epoch 001 5000 / 331737 loss=10405.01 (136.96), wps=18532, wpb=31216, bsz=874, lr=1.25, clip=100%, gnorm=1500459828271.3960
| epoch 001 6000 / 331737 loss=4773454961.36 (92926125.94), wps=18564, wpb=31213, bsz=867, lr=1.25, clip=100%, gnorm=37459419138681.4219
| epoch 001 7000 / 331737 loss=7746569234820.15 (126329286789.38), wps=18577, wpb=31211, bsz=864, lr=1.25, clip=100%, gnorm=inf
| epoch 001 8000 / 331737 loss=18016233617.10 (228909462625.55), wps=18562, wpb=31205, bsz=866, lr=1.25, clip=100%, gnorm=inf
| epoch 001 9000 / 331737 loss=6500325670920.53 (321325856038.58), wps=18597, wpb=31214, bsz=860, lr=1.25, clip=100%, gnorm=inf
| epoch 001 10000 / 331737 loss=11162501170786.86 (715142464195.40), wps=18609, wpb=31219, bsz=858, lr=1.25, clip=100%, gnorm=inf
....
--------------------------ENV---------------------------- P40 8cards
--------------------------DATA PREPROCESSING----------------------------
- normalize-punctuation
- tokenizer
- clean-corpus-n
- shuffle
- learn and apply bpe I've checked en-fr data corresponding relationship after preprocessing.
--------------------------TRAINING PARAMETER----------------------------
fairseq_train_param="-s en -t fr --arch fconv_wmt_en_fr
--dropout 0.1 --lr 1.25 --clip-norm 0.1 --max-tokens 4000 --force-anneal 32"
Can you help me to figure out my problem? Thank you.
@Zrachel does it still happen if you try a smaller learning rate? E.g. 0.5 or 0.25?
I've only tested with lr=0.75.
Warning! 1 samples are either too short or too long and will be ignored,
sample ids=[28743556]
| epoch 001 1000 / 331737 loss=9.65 (10.95), wps=20332, wpb=31259, bsz=861, lr
=1.25, clip=100%, gnorm=2.1003
| epoch 001 2000 / 331737 loss=8.50 (9.92), wps=20474, wpb=31229, bsz=877, lr=
1.25, clip=100%, gnorm=1.6097
| epoch 001 3000 / 331737 loss=7.39 (9.21), wps=20506, wpb=31226, bsz=871, lr=
1.25, clip=100%, gnorm=1.5967
| epoch 001 4000 / 331737 loss=6.47 (8.63), wps=20553, wpb=31231, bsz=873, lr=
1.25, clip=100%, gnorm=16.6729
| epoch 001 5000 / 331737 loss=25310.23 (208.33), wps=20568, wpb=31216, bsz=
874, lr=1.25, clip=100%, gnorm=939137934066.9988
| epoch 001 6000 / 331737 loss=12371541352.98 (189739470.63), wps=20586, wpb=
31213, bsz=867, lr=1.25, clip=100%, gnorm=291234449344740.5000
| epoch 001 7000 / 331737 loss=62938206349384.62 (2600980048200.01), wps=20575
, wpb=31211, bsz=864, lr=1.25, clip=100%, gnorm=inf
| epoch 001 8000 / 331737 loss=715021053854.14 (6580212975093.94), wps=20579,
wpb=31205, bsz=866, lr=1.25, clip=100%, gnorm=inf
| epoch 001 9000 / 331737 loss=8117017248127.47 (6380367564062.83), wps=20598
, wpb=31214, bsz=860, lr=1.25, clip=100%, gnorm=inf
| epoch 001 10000 / 331737 loss=746062258001.61 (6187522885568.29), wps=20599
, wpb=31219, bsz=858, lr=1.25, clip=100%, gnorm=inf
....
Did you have any luck with smaller lr? Otherwise, could you please share your version of the dataset so we can debug this further.
I tested lr = 0.25, no exploding problem until epoch 5, but BLEU improved slowly:
checkpoint1.pt/test.bleu:BLEU4 = 28.26, 57.8/33.8/22.1/14.8 (BP=1.000, ratio=0.992, syslen=81884, reflen=81204)
checkpoint2.pt/test.bleu:BLEU4 = 30.59, 60.1/36.4/24.3/16.5 (BP=1.000, ratio=0.996, syslen=81534, reflen=81204)
checkpoint3.pt/test.bleu:BLEU4 = 30.78, 60.0/36.5/24.5/16.8 (BP=1.000, ratio=0.992, syslen=81857, reflen=81204)
checkpoint4.pt/test.bleu:BLEU4 = 31.41, 60.4/37.2/25.1/17.3 (BP=1.000, ratio=0.989, syslen=82146, reflen=81204)
checkpoint5.pt/test.bleu:BLEU4 = 32.15, 61.1/38.0/25.8/17.9 (BP=1.000, ratio=0.990, syslen=82024, reflen=81204)
Here is my data preprocessing script about training and valid data:
src=en
tgt=fr
vocab_size=40000
TOKENIZER=bin/mosesdecoder/scripts/tokenizer/tokenizer.perl
LOWERCASE=bin/mosesdecoder/scripts/tokenizer/lowercase.perl
CLEAN=bin/mosesdecoder/scripts/training/clean-corpus-n.perl
REMOVER=bin/mosesdecoder/scripts/tokenizer/remove-non-printing-char.perl
if [ ! -d temp ] ; then
mkdir -p temp
fi
datasrc=~/Data/MT/WMT14/wmt14_en-fr_corpus/input/train
cat $datasrc/*.$src > temp/train.merge.$src
cat $datasrc/*.$tgt > temp/train.merge.$tgt
perl bin/normalize-punctuation.perl $src < temp/train.merge.$src | perl $REMOVER > temp/train.norm-punc.$src
perl bin/normalize-punctuation.perl $tgt < temp/train.merge.$tgt | perl $REMOVER > temp/train.norm-punc.$tgt
perl $TOKENIZER -threads 8 -l $src < temp/train.norm-punc.$src > temp/train.token.$src
perl $TOKENIZER -threads 8 -l $tgt < temp/train.norm-punc.$tgt > temp/train.token.$tgt
perl $CLEAN -ratio 1.5 temp/train.token $src $tgt temp/train.clean 1 175
cat temp/train.clean.$src | sed 's/\t/ /g' > temp/train.lc.$src
cat temp/train.clean.$tgt | sed 's/\t/ /g' > temp/train.lc.$tgt
paste -d $'\t' temp/train.lc.$src temp/train.lc.$tgt > temp/train.paste.$src-$tgt
./bin/shuffle < temp/train.paste.$src-$tgt > temp/train.shuffle.$src-$tgt
head -26663 temp/train.shuffle.$src-$tgt > temp/valid.select.$src-$tgt
tail -n +26664 temp/train.shuffle.$src-$tgt > temp/train.select.$src-$tgt
sed 's/\t/ /g' < temp/train.select.$src-$tgt | python bin/subword/learn_bpe.py -s $vocab_size > temp/train.bpe_codes
python bin/subword/apply_bpe_fix.py -c temp/train.bpe_codes < temp/valid.select.$src-$tgt >temp/valid.subword.$src-$tgt 2>temp/valid.dump.$src-$tgt
python bin/subword/apply_bpe_fix.py -c temp/train.bpe_codes < temp/train.select.$src-$tgt >temp/train.subword.$src-$tgt 2>temp/train.dump.$src-$tgt
cut -f 1 temp/valid.subword.$src-$tgt > temp/valid.subword.$src
cut -f 2 temp/valid.subword.$src-$tgt > temp/valid.subword.$tgt
cut -f 1 temp/train.subword.$src-$tgt > temp/train.subword.$src
cut -f 2 temp/train.subword.$src-$tgt > temp/train.subword.$tgt
if [ ! -d temp/subword ] ; then
mkdir -p temp/subword
fi
cp temp/valid.subword.$src temp/subword/valid.$src
cp temp/valid.subword.$tgt temp/subword/valid.$tgt
cp temp/train.subword.$src temp/subword/train.$src
cp temp/train.subword.$tgt temp/subword/train.$tgt
AND
SUBWORD=temp/subword
python ../PyFairseq/preprocess.py -s $src -t $tgt \
--trainpref $SUBWORD/train --validpref $SUBWORD/valid --testpref $SUBWORD/test \
--destdir output
Do I have to upload my binary data? Or is there something else that might lead to the failure of big LR to converge?
Can you please put the train files produced by the script above somewhere accessible, i.e., train.{en,fr}, valid.{en,fr}? Google drive may work for this.
Thanks, I put it here. https://drive.google.com/open?id=0B_jWt3ujEZ88ZWI1LWdVdUFHOHM
Thanks, I used the same training command as you did above and see no overflows. I modified the dictionary loading code to support your file encoding though (encoding="ISO-8859-1"). Are you sure you did not change anything that may have caused the issue?
@Zrachel what system are you running this on? Is it Windows by any chance?
I'm sure I didn't modify the source code. BUT I'm not updating code with git. I'm using the version you originally released. Here is my pyfairseq folder: https://drive.google.com/open?id=0B_jWt3ujEZ88ZkttUFBPTzViMGs
Did you train on 8 cards with lr=1.25? @michaelauli And, after modify the encoding, did you get the dictionary size exactly as I got?
| [en] dictionary: 43881 types
| [fr] dictionary: 43978 types
Centos 6.3 @edunov
Yes, I ran on 8 cards and the settings you posted above. Try with the latest version of the code.
well I'll try, thank you. And, can you show me your bleu score in the generating process? I got the following with lr=0.25,
checkpoint_last.pt/test.bleu:BLEU4 = 28.21, 57.5/33.8/22.1/14.8 (BP=1.000, ratio=0.993, syslen=69305, reflen=68846)
checkpoint1.pt/test.bleu:BLEU4 = 28.26, 57.8/33.8/22.1/14.8 (BP=1.000, ratio=0.992, syslen=81884, reflen=81204)
checkpoint2.pt/test.bleu:BLEU4 = 30.59, 60.1/36.4/24.3/16.5 (BP=1.000, ratio=0.996, syslen=81534, reflen=81204)
checkpoint3.pt/test.bleu:BLEU4 = 30.78, 60.0/36.5/24.5/16.8 (BP=1.000, ratio=0.992, syslen=81857, reflen=81204)
checkpoint4.pt/test.bleu:BLEU4 = 31.41, 60.4/37.2/25.1/17.3 (BP=1.000, ratio=0.989, syslen=82146, reflen=81204)
checkpoint5.pt/test.bleu:BLEU4 = 32.15, 61.1/38.0/25.8/17.9 (BP=1.000, ratio=0.990, syslen=82024, reflen=81204)
checkpoint6.pt/test.bleu:BLEU4 = 32.27, 61.1/38.0/25.9/18.0 (BP=1.000, ratio=0.995, syslen=81643, reflen=81204)
checkpoint7.pt/test.bleu:BLEU4 = 32.35, 61.3/38.1/26.0/18.0 (BP=1.000, ratio=0.993, syslen=81816, reflen=81204)
checkpoint8.pt/test.bleu:BLEU4 = 33.11, 61.8/38.9/26.7/18.7 (BP=1.000, ratio=0.991, syslen=81953, reflen=81204)
checkpoint9.pt/test.bleu:BLEU4 = 33.39, 62.2/39.2/26.9/18.9 (BP=1.000, ratio=0.996, syslen=81525, reflen=81204)
checkpoint10.pt/test.bleu:BLEU4 = 32.93, 61.8/38.8/26.5/18.5 (BP=1.000, ratio=0.994, syslen=81689, reflen=81204)
It seems to have converged, but still have a large gap between the proposed bleu score: 40.51.
@Zrachel we don't measure BLEU score on test set during training, we usually look at validation loss. But I have just scored saved checkpoints for some old run:
checkpoint1.pt: | Generate test with beam=5: BLEU4 = 35.91, 64.4/42.0/29.4/20.9 (BP=1.000, ratio=1.000, syslen=81191, reflen=81194)
checkpoint2.pt: | Generate test with beam=5: BLEU4 = 37.33, 65.4/43.5/30.8/22.2 (BP=1.000, ratio=1.000, syslen=81180, reflen=81194)
checkpoint3.pt: | Generate test with beam=5: BLEU4 = 37.29, 65.3/43.4/30.8/22.2 (BP=1.000, ratio=0.997, syslen=81433, reflen=81194)
checkpoint4.pt: | Generate test with beam=5: BLEU4 = 38.05, 65.9/44.2/31.5/22.8 (BP=1.000, ratio=0.999, syslen=81286, reflen=81194)
checkpoint5.pt: | Generate test with beam=5: BLEU4 = 38.54, 66.0/44.7/32.0/23.3 (BP=1.000, ratio=0.993, syslen=81757, reflen=81194)
checkpoint6.pt: | Generate test with beam=5: BLEU4 = 38.43, 66.0/44.5/31.9/23.3 (BP=1.000, ratio=0.995, syslen=81612, reflen=81194)
checkpoint7.pt: | Generate test with beam=5: BLEU4 = 38.85, 66.4/45.0/32.3/23.5 (BP=1.000, ratio=0.997, syslen=81453, reflen=81194)
checkpoint8.pt: | Generate test with beam=5: BLEU4 = 39.06, 67.0/45.5/32.9/24.1 (BP=0.991, ratio=1.009, syslen=80460, reflen=81194)
checkpoint9.pt: | Generate test with beam=5: BLEU4 = 39.03, 66.5/45.2/32.6/23.8 (BP=0.999, ratio=1.001, syslen=81096, reflen=81194)
checkpoint10.pt: | Generate test with beam=5: BLEU4 = 39.21, 66.7/45.4/32.7/23.9 (BP=1.000, ratio=0.999, syslen=81259, reflen=81194)
checkpoint12.pt: | Generate test with beam=5: BLEU4 = 39.46, 66.6/45.5/33.0/24.2 (BP=1.000, ratio=0.999, syslen=81259, reflen=81194)
checkpoint14.pt: | Generate test with beam=5: BLEU4 = 39.66, 66.8/45.7/33.2/24.4 (BP=1.000, ratio=0.997, syslen=81405, reflen=81194)
checkpoint16.pt: | Generate test with beam=5: BLEU4 = 39.46, 66.8/45.5/33.0/24.2 (BP=1.000, ratio=0.998, syslen=81368, reflen=81194)
checkpoint18.pt: | Generate test with beam=5: BLEU4 = 39.68, 66.8/45.7/33.1/24.5 (BP=1.000, ratio=0.997, syslen=81424, reflen=81194)
checkpoint20.pt: | Generate test with beam=5: BLEU4 = 39.81, 67.1/45.9/33.3/24.5 (BP=1.000, ratio=0.999, syslen=81303, reflen=81194)
This is with learning rate 2.5, but you should have something very similar because of clipping
We recently discovered an issue with recent versions of PyTorch and our multi-GPU training code. The fix is here: https://github.com/facebookresearch/fairseq-py/commit/d7d82715f968097bba08c92416d332d969bd1f06. Can you update your fairseq-py or apply the fix and see if it solves the exploding loss issue?
The problem is fixed after fetching this code. Thank you very much and it's great to see your work and your code.
Using the newest code, the exploding problem is fixed, however I still cannot get a good result on wmt14 en-fr as @edunov shows.
Until epoch 12, this is my result:
valid loss:
| epoch 001 | valid on 'valid' subset | valid loss 1.75 | valid ppl 3.37
| epoch 002 | valid on 'valid' subset | valid loss 1.64 | valid ppl 3.12
| epoch 003 | valid on 'valid' subset | valid loss 1.58 | valid ppl 3
| epoch 004 | valid on 'valid' subset | valid loss 1.55 | valid ppl 2.93
| epoch 005 | valid on 'valid' subset | valid loss 1.53 | valid ppl 2.89
| epoch 006 | valid on 'valid' subset | valid loss 1.51 | valid ppl 2.85
| epoch 007 | valid on 'valid' subset | valid loss 1.49 | valid ppl 2.82
| epoch 008 | valid on 'valid' subset | valid loss 1.48 | valid ppl 2.79
| epoch 009 | valid on 'valid' subset | valid loss 1.47 | valid ppl 2.77
| epoch 010 | valid on 'valid' subset | valid loss 1.46 | valid ppl 2.76
| epoch 011 | valid on 'valid' subset | valid loss 1.46 | valid ppl 2.74
BLEU:
checkpoint1.pt/test.bleu:BLEU4 = 30.11, 59.5/35.8/23.8/16.2 (BP=1.000, ratio=0.975, syslen=83264, reflen=81204)
checkpoint2.pt/test.bleu:BLEU4 = 31.34, 60.4/37.1/25.0/17.2 (BP=1.000, ratio=0.986, syslen=82348, reflen=81204)
checkpoint3.pt/test.bleu:BLEU4 = 32.56, 61.4/38.4/26.1/18.2 (BP=1.000, ratio=0.988, syslen=82230, reflen=81204)
checkpoint4.pt/test.bleu:BLEU4 = 32.71, 61.5/38.5/26.3/18.4 (BP=1.000, ratio=0.989, syslen=82140, reflen=81204)
checkpoint5.pt/test.bleu:BLEU4 = 33.13, 62.0/38.9/26.7/18.7 (BP=1.000, ratio=0.997, syslen=81437, reflen=81204)
checkpoint6.pt/test.bleu:BLEU4 = 33.04, 61.5/38.8/26.7/18.7 (BP=1.000, ratio=0.995, syslen=81632, reflen=81204)
checkpoint7.pt/test.bleu:BLEU4 = 33.01, 61.6/38.8/26.6/18.7 (BP=1.000, ratio=0.987, syslen=82282, reflen=81204)
checkpoint8.pt/test.bleu:BLEU4 = 33.60, 62.2/39.4/27.2/19.1 (BP=1.000, ratio=0.992, syslen=81830, reflen=81204)
checkpoint9.pt/test.bleu:BLEU4 = 33.07, 61.6/38.9/26.7/18.7 (BP=1.000, ratio=0.993, syslen=81783, reflen=81204)
checkpoint10.pt/test.bleu:BLEU4 = 33.39, 62.2/39.3/27.0/19.0 (BP=0.999, ratio=1.001, syslen=81099, reflen=81204)
Although it is with learning rate=1.25(different from @edunov 's 2.5), it seems to have converged. Can you help me to figure out something wrong? Thank you.
Here is the log: https://drive.google.com/file/d/1SHn12H28Nv5-ALm6qJuDoIQy60Ock8KP/view?usp=sharing
And I got the following with lr=2.5:
| epoch 001: 2000 / 331737 loss=5582492.15 (96142.54), wps=16385, wpb=31241, bsz=838, lr=2.5, clip=100%, gnorm=2.60532e+11
| epoch 001: 3000 / 331737 loss=114973483220929.67 (3671800974152.95), wps=16417, wpb=31258, bsz=849, lr=2.5, clip=100%, gnorm=inf
| epoch 001: 4000 / 331737 loss=13999053062340316.00 (29686578871936764.00), wps=16432, wpb=31229, bsz=853, lr=2.5, clip=100%, gnorm=inf
| epoch 001: 5000 / 331737 loss=44017573071892712.00 (29628206376563668.00), wps=16458, wpb=31251, bsz=861, lr=2.5, clip=100%, gnorm=inf
| epoch 001: 6000 / 331737 loss=2935036760889004.00 (30718716650977436.00), wps=16476, wpb=31255, bsz=857, lr=2.5, clip=100%, gnorm=inf
| epoch 001: 7000 / 331737 loss=550775386966620.00 (26360463189405288.00), wps=16496, wpb=31266, bsz=854, lr=2.5, clip=100%, gnorm=inf
| epoch 001: 8000 / 331737 loss=109306521399736.77 (23093548334038104.00), wps=16496, wpb=31252, bsz=852, lr=2.5, clip=100%, gnorm=inf
| epoch 001: 9000 / 331737 loss=8933421048725696.00 (20857194066592980.00), wps=16490, wpb=31241, bsz=852, lr=2.5, clip=100%, gnorm=inf
| epoch 001: 10000 / 331737 loss=2645307052187.05 (18871115849514408.00), wps=16492, wpb=31244, bsz=855, lr=2.5, clip=100%, gnorm=inf
| epoch 001: 11000 / 331737 loss=28603926368389.34 (17161834137035208.00), wps=16496, wpb=31239, bsz=855, lr=2.5, clip=100%, gnorm=inf
| epoch 001: 12000 / 331737 loss=30545126857627.29 (15820716078827976.00), wps=16501, wpb=31240, bsz=855, lr=2.5, clip=100%, gnorm=inf
| epoch 001: 13000 / 331737 loss=nan (nan), wps=16509, wpb=31244, bsz=853, lr=2.5, clip=93%, gnorm=nan
| epoch 001: 14000 / 331737 loss=nan (nan), wps=16510, wpb=31239, bsz=851, lr=2.5, clip=86%, gnorm=nan
| epoch 001: 15000 / 331737 loss=nan (nan), wps=16510, wpb=31236, bsz=852, lr=2.5, clip=81%, gnorm=nan
| epoch 001: 16000 / 331737 loss=nan (nan), wps=16510, wpb=31235, bsz=853, lr=2.5, clip=76%, gnorm=nan
| epoch 001: 17000 / 331737 loss=nan (nan), wps=16510, wpb=31232, bsz=855, lr=2.5, clip=71%, gnorm=nan
| epoch 001: 18000 / 331737 loss=nan (nan), wps=16510, wpb=31228, bsz=855, lr=2.5, clip=67%, gnorm=nan
Closing this, since it's being discussed in the other issue already.
Hi @edunov , I found some difference in our reported results:
Your reported result above is in the format of:
checkpoint1.pt: | Generate test with beam=5: BLEU4 = 35.91, 64.4/42.0/29.4/20.9 (BP=1.000, ratio=1.000, syslen=81191, reflen=81194)
which might be directly calculated by generate.py.
While, mine is in the format of
checkpoint1.pt/test.bleu:BLEU4 = 30.11, 59.5/35.8/23.8/16.2 (BP=1.000, ratio=0.975, syslen=83264, reflen=81204)
It is achieved in this way:
python generate.py $data --path $path > $out/test.out
grep ^H $out/test.out | sed 's/^H-//g' | sort -k1,1n | cut -f 3 | sed 's/@@ //g' > $out/test.trans
grep ^T $out/test.out | sed 's/^T-//g' | sort -k1,1n | cut -f 2 | sed 's/@@ //g' > $out/test.ref
python ../../PyFairseq/score.py --sys $out/test.trans --ref $out/test.ref > $out/test.bleu
Can you paste your result of score.py for reference? Thank you.
@edunov would have been using the --remove-bpe option in generate.py, which is equivalent to the score.py results you report.
Yes, as @myleott said I've been using --remove-bpe in generate.py, which is equivalent to your way of running score.py there is some other reason for the discrepancy
Oh I see, thank you.