Skip to content

A TTS that fits in your CPU (and pocket)

Python

Stop training on a non-finite gradient (#262)

manu-lm559729d0bd0c
diff --git a/training/train.py b/training/train.py
index c14477c..4494f2d 100644
--- a/training/train.py
+++ b/training/train.py
@@ -218,6 +218,10 @@ def main(config_path: str) -> None:
else:
scaled.backward()
grad_norm = torch.nn.utils.clip_grad_norm_(model.parameters(), args.optim.max_norm)
+ if not torch.isfinite(grad_norm):
+ # Stop before the NaN reaches the weights: the run would otherwise
+ # keep training and checkpointing garbage, and auto-resume reloads it.
+ raise SystemExit(f"non-finite gradient at step {step}")
optimizer.step()
if ema is not None:
ema.update(model)