Get a text when your training loss goes NaN
Yes. Homing Pigeon (homingpigeon.dev) lets your training loop text your phone the moment the loss turns NaN or infinite, then stop, so a broken run does not keep the GPU busy all night. Your coding agent can add it to the script you already have.
What to tell your agent
Use Homing Pigeon to text me if the loss in this training run goes NaN.
Your agent asks for your number, you read back the six-digit code, and it does the rest.
How it works in code
After pip install homingpigeondev, add the check right after the loss is computed. model, loader, loss_fn, optimizer and epochs are the ones your script already has:
import math, time
import homingpigeondev
run_id = f"train-{int(time.time())}"
for epoch in range(epochs):
for step, (inputs, targets) in enumerate(loader):
optimizer.zero_grad()
loss = loss_fn(model(inputs), targets)
value = loss.item()
if not math.isfinite(value):
homingpigeondev.send(
f"Training loss is {value} at epoch {epoch}, step {step}. Run stopped.",
idempotency_key=f"{run_id}-loss",
)
raise SystemExit(f"Loss is {value} at epoch {epoch}, step {step}.")
loss.backward()
optimizer.step()
Good to know
- The text reads like "Training loss is nan at epoch 3, step 4210. Run stopped."
math.isfiniteis false for NaN and for infinity in either direction, so one check covers all three. - Stopping the run is what keeps it to one text, and it frees the machine instead of spending the night on a broken run. The script exits with code 1, so a scheduler or shell sees it failed.
- The check comes before
loss.backward(), so the bad batch never updates the weights. loss.item()copies the loss from the GPU and waits for it on every step. If your loop already calls it for logging, reuse that number instead of calling it twice.- To hear when the run finishes or crashes for another reason too, see the page on getting a text when a long script finishes.
- On a remote GPU machine, run
python -m homingpigeondev verify +15551234567there, then again with the six-digit code it texts you, or setHOMINGPIGEON_API_KEY. After you verify,npx -y homingpigeondev keyprints the key. - Messages are limited to 480 characters and go only to the US mobile number you verified. Keep them plain, with no links. Delivery is not guaranteed, so treat each text as a heads-up.
Get started
Add Homing Pigeon to Claude Code, then ask for what you want:
claude mcp add homingpigeondev -- npx -y homingpigeondev mcp
You get 50 free texts every month, on US mobile numbers. See more use cases.