Skip to content

Commit

Permalink
Explicit example loop
Browse files Browse the repository at this point in the history
  • Loading branch information
muellerzr committed Sep 12, 2023
1 parent 9efdf59 commit 535ad35
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions docs/source/concept_guides/deferring_execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,14 @@ for doing so can include situations such as using early stopping and monitoring
Call [`Accelerator.set_trigger`] when your condition has been met, and [`Accelerator.check_trigger`] when checking if that condition has been met in any process:

```python
# Assume `should_do_early_stopping` is a custom defined function that returns a conditional
if should_do_early_stopping(loss):
accelerator.set_trigger()

# Later in the training script when we need to check for the breakpoint
if accelerator.check_trigger():
break
for (x,y) in data_loader:
logits = model(x)
loss = loss_func(logits, y)
# Assume `should_do_early_stopping` is a custom defined function that returns a conditional
if should_do_early_stopping(loss):
accelerator.set_trigger()

# Later in the training script when we need to check for the breakpoint
if accelerator.check_trigger():
break
```

0 comments on commit 535ad35

Please sign in to comment.