HealthMonitorCallback<T>
Models & Types · AiDotNet.TrainingMonitoring
A ready-to-use ITrainingCallback that watches training health and
aborts automatically when it detects a run that has gone wrong.
Implements: ITrainingCallback<T>
For Beginners
Long training runs sometimes “explode” — the loss turns into
NaN or starts climbing instead of falling — and every remaining epoch is then wasted. Add
this callback and it plays the role of a safety cut-off: it watches the loss after each
epoch and, the moment things look unhealthy, it returns false so the trainer stops
early and hands you back the model as it was before the blow-up. You can tune how sensitive
it is with lossRisePercent and windowSize.
How It Works
The callback stops training when any of the following holds at the end of an epoch:
When it aborts, the reason is recorded in AbortReason and, when a monitor
and session id are supplied, also logged to that monitor as an error message.
Register it with AiModelBuilder.ConfigureTrainingCallback(new HealthMonitorCallback<T>(...));
its thresholds (lossRisePercent, windowSize) and optional monitor integration are
user-configurable, and AbortReason is readable after training.
Constructors
| Constructor | Summary |
|---|---|
HealthMonitorCallback(double lossRisePercent, int windowSize, ITrainingMonitor<T> monitor, string monitorSessionId) |
Initializes a new HealthMonitorCallback. |
Properties
| Property | Summary |
|---|---|
string AbortReason { get; set; } |
Gets the human-readable reason training was aborted, or null if this callback has not requested an abort. |
Methods
| Method | Summary |
|---|---|
bool OnEpochEnd(TrainingProgress<T> progress) |
|
void OnTrainBegin(TrainingProgress<T> progress) |
|
void OnTrainEnd(TrainingProgress<T> progress) |