Skip to content

Commit 12122a1

Browse files
committed
fix: add custom loop and docs
Signed-off-by: Mehant Kammakomati <mehant.kammakomati2@ibm.com>
1 parent 919ce6f commit 12122a1

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

plugins/online-data-mixing/artifacts/custom_loop_usage.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ class State:
9191
accelerator.backward(loss)
9292
optimizer.step()
9393
optimizer.zero_grad()
94-
if step_idx % 1 == 0 and accelerator.is_main_process:
94+
loss = accelerator.gather(loss).mean()
95+
if step_idx % 1 == 0:
96+
if torch.isnan(loss):
97+
raise ValueError("loss is nan")
9598
print(f"Step {step_idx} ||| Loss: {loss.item():.4f}")
9699
state.log_history.append(
97100
{"loss": loss.item() if not torch.isnan(loss) else 1e100}

0 commit comments

Comments
 (0)