"tests/models/vscode:/vscode.git/clone" did not exist on "fb3b22c3b932cfbaffa217f1d036ab3ce668add2"
Unverified Commit 77770ec7 authored by Yanming Wang's avatar Yanming Wang Committed by GitHub
Browse files

Fix trainer logging_nan_inf_filter in torch_xla mode (#13896)



* Fix logging_nan_inf_filter in torch_xla mode

* Update src/transformers/trainer.py
Co-authored-by: default avatarSylvain Gugger <35901082+sgugger@users.noreply.github.com>

* Fix format
Co-authored-by: default avatarSylvain Gugger <35901082+sgugger@users.noreply.github.com>
parent aea7c5b0
......@@ -1311,7 +1311,8 @@ class Trainer:
else:
tr_loss_step = self.training_step(model, inputs)
if args.logging_nan_inf_filter and (torch.isnan(tr_loss_step) or torch.isinf(tr_loss_step)):
if args.logging_nan_inf_filter and not is_torch_tpu_available():
if torch.isnan(tr_loss_step) or torch.isinf(tr_loss_step):
# if loss is nan or inf simply add the average of previous logged losses
tr_loss += tr_loss / (1 + self.state.global_step - self._globalstep_last_logged)
else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment