Safeguards¶
StabilityMonitor ¶
Detects unstable or harmful tuning steps.
A step regresses when its score is NaN/Inf, or falls more than
max_regression (relative) below the best score so far. After patience
consecutive regressing steps, update() returns False and the monitor
enters rollback. For the next cooldown steps no rollback is triggered,
so the controller does not oscillate; those steps are still judged, and
last_step_regressed reports the verdict.
Attributes:
| Name | Type | Description |
|---|---|---|
max_regression |
Relative drop counted as a regression (0.2 = 20%). |
|
patience |
Consecutive regressions before a rollback. |
|
cooldown |
Steps with rollback suppressed after a rollback. |
|
last_step_regressed |
Whether the latest |
Examples:
>>> guard = StabilityMonitor(max_regression=0.2, patience=2, cooldown=3)
>>> guard.update(score=-1.5, best_score=-1.0) # 50% worse: 1st regression
True
>>> guard.update(score=-1.5, best_score=-1.0) # 2nd: roll back
False
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_regression
|
float
|
Relative drop from the best score counted as a regression; 0.2 means a score more than 20% worse. |
0.2
|
patience
|
int
|
Consecutive regressing steps that trigger a rollback. |
2
|
cooldown
|
int
|
Steps after a rollback during which no new rollback is triggered. |
3
|
Source code in src/autotunenet/safeguards/stability.py
in_rollback
property
¶
Whether the last rollback has not yet been followed by an accepted step.
is_regression ¶
Return whether score is more than max_regression below best_score.
The drop is relative to abs(best_score). Always False when
best_score is None.
Source code in src/autotunenet/safeguards/stability.py
update ¶
Judge one step and update the guard's state.
The first step (best_score is None) is always accepted and resets the state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
score
|
float
|
The (smoothed) score of this step; higher is better. |
required |
best_score
|
float | None
|
The best score accepted so far, or |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
After each call, last_step_regressed tells whether this step was a
regression. A step can return True and still have regressed: while
the regression count is below patience, or during cooldown. Such a
step must not become the rollback target.
Source code in src/autotunenet/safeguards/stability.py
force_rollback ¶
exit_rollback ¶
reset ¶
Clear the regression count, cooldown and rollback state.
Rollback ¶
Holds a copy of the last configuration accepted as good.
Only hyperparameters are stored: model weights and optimizer state are not, so a rollback cannot undo divergence that has already happened.