BART metrics.json and validation checkpoint metrics seem to disagree
Author: vikigenius
Pull request: no
Labels: name: wontfix

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->
     
- `transformers` version: 3.1.0
- Platform: Linux 4.14
- Python version:3.7.9
- PyTorch version (GPU?):1.6.0 (True)
- Using GPU in script?: True
- Using distributed or parallel set-up in script?: True

### Who can help
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.
 
 albert, bert, GPT2, XLM: @LysandreJik 
 tokenizers: @mfuntowicz
 Trainer: @sgugger
 Speed and Memory Benchmarks: @patrickvonplaten
 Model Cards: @julien-c
 Translation: @sshleifer
 Summarization: @sshleifer
 TextGeneration: @TevenLeScao 
 examples/distillation: @VictorSanh
 nlp datasets: [different repo](https://github.com/huggingface/nlp)
 rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)
 Text Generation: @TevenLeScao
 blenderbot: @mariamabarham
 Bart: @sshleifer
 Marian: @sshleifer
 T5: @patrickvonplaten
 Longformer/Reformer: @patrickvonplaten
 TransfoXL/XLNet: @TevenLeScao 
 examples/seq2seq: @sshleifer
 examples/bert-loses-patience: @JetRunner
 tensorflow: @jplu
 examples/token-classification: @stefan-it
 documentation: @sgugger
 -->
 examples/seq2seq: @sshleifer 
## Information

Model I am using (BART):

The problem arises when using:
* [*] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [*] my own task or dataset: (give details below)
I am using a small subset of https://github.com/pubmedqa/pubmedqa to generate questions from the given passage.

## To reproduce

Steps to reproduce the behavior:

1. Do distributed training
2. Run the finetune script with appropriate arguments.

The saved checkpoint says:
val_avg_rouge2=13.0975-step_count=4.ckpt

However the metrics.json file says that val_avg_rouge2=6.46015 and there are better step_counts in comparison.

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior

<!-- A clear and concise description of what you would expect to happen. -->
The best metric in metrics.json should be chosen for saving checkpoints.



Comments:
I can replicate in pl 0.8.5 and pl 0.9.0, great catch.

Smaller command to replicate:

```
export MAX_LEN=128
export m=export m=sshleifer/student_marian_en_ro_6_3
python finetune.py \
  --learning_rate=3e-4 \
  --do_train \
  --do_predict \
  --fp16 \
  --val_check_interval 0.25 \
  --data_dir $ENRO_DIR \
  --max_source_length $MAX_LEN --max_target_length $MAX_LEN --val_max_target_length $MAX_LEN --test_max_target_length $MAX_LEN \
  --freeze_encoder --freeze_embeds \
  --train_batch_size=64 --eval_batch_size=64 \
  --tokenizer_name $m --model_name_or_path $m \
  --warmup_steps 500 --sortish_sampler --logger_name wandb \
  --fp16_opt_level=O1 --task translation --num_sanity_val_steps=0 \
  --model_name_or_path $m --gpus 8 --num_train_epochs=1 \
  --data_dir wmt_en_ro --output_dir dmar_pl_only_v2 --save_top_k=10
```

You will only call have 4-5 entries in metrics, but 10 checkpoints.




Every single rank is saving checkpoints.

@sshleifer Wow, so is that like a race condition where the last RANK "wins"? What about the weights of model? Would they be same across all the ranks, or would they be a problem as well?


Posted here https://github.com/PyTorchLightning/pytorch-lightning/issues/3597

Weights will be the same across all ranks. You just have suboptimal checkpoint saving logic. You can kind of workaround by passing --save_top_k=5 and then manually picking which one you like by looking at metrics.json.

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.