Set perplexity to inf in log stats in case of overflow error (#1834)
Set perplexity to inf in log stats in case of overflow error (#1834)

Summary:
# Before submitting

- [x] Was this discussed/approved via a Github issue? (no need for typos, doc improvements)
- [x] Did you read the [contributor guideline](https://github.com/pytorch/fairseq/blob/master/CONTRIBUTING.md)?
- [x] Did you make sure to update the docs?
- [ ] Did you write any new necessary tests?

## What does this PR do?
Fixes https://github.com/pytorch/fairseq/issues/1833

Example output after this update:
```
2020-03-12 15:39:26 | WARNING | root | NaN or Inf found in input tensor.
2020-03-12 15:39:26 | INFO | train | epoch 001 | loss 69041.9 | nll_loss 6820 | wps 12712 | ups 6.53 | wpb 1640 | bsz 162 | num_updates 2 | lr 1e-05 | gnorm 2603.12 | loss_scale 16 | train_wall 1 | ppl inf | wall 1
/SFS/user/wp/prihodad/git/fairseq/fairseq/utils.py:351: RuntimeWarning: overflow encountered in power
  return safe_round(np.power(base, loss), round)
2020-03-12 15:39:26 | WARNING | root | NaN or Inf found in input tensor.
2020-03-12 15:39:26 | INFO | valid | epoch 001 | valid on 'valid' subset | loss 71135.5 | nll_loss 7034 | wps 0 | wpb 1699 | bsz 168 | ppl inf | num_updates 2

```
Pull Request resolved: https://github.com/pytorch/fairseq/pull/1834

Reviewed By: ngoyal2707

Differential Revision: D20490980

Pulled By: myleott

fbshipit-source-id: 320822f9b50185a33fb0346a84b935934b710c98

pytorch/fairseq,pytorch/fairseq,pytorch/fairseq