Skip to content

Commit 1430ebf

Browse files
authored
[AutoML] If first three iterations all fail, short-circuit AutoML experiment (#3591)
1 parent 4d3416e commit 1430ebf

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

src/Microsoft.ML.Auto/Experiment/Experiment.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ public IList<TRunDetail> Execute()
8989
break;
9090
}
9191

92+
// If after third run, all runs have failed so far, throw exception
93+
if (_history.Count() == 3 && _history.All(r => !r.RunSucceded))
94+
{
95+
throw new InvalidOperationException($"Training failed with the exception: {_history.Last().Exception}");
96+
}
97+
9298
} while (_history.Count < _experimentSettings.MaxModels &&
9399
!_experimentSettings.CancellationToken.IsCancellationRequested &&
94100
stopwatch.Elapsed.TotalSeconds < _experimentSettings.MaxExperimentTimeInSeconds);

src/Microsoft.ML.Auto/Experiment/SuggestedPipelineRunDetails/SuggestedPipelineCrossValRunDetail.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ internal SuggestedPipelineCrossValRunDetail(SuggestedPipeline pipeline,
4242
IEnumerable<SuggestedPipelineTrainResult<TMetrics>> results) : base(pipeline, score, runSucceeded)
4343
{
4444
Results = results;
45+
Exception = Results.Select(r => r.Exception).FirstOrDefault(e => e != null);
4546
}
4647

4748
public CrossValidationRunDetail<TMetrics> ToIterationResult(IEstimator<ITransformer> preFeaturizer)

src/Microsoft.ML.Auto/Experiment/SuggestedPipelineRunDetails/SuggestedPipelineRunDetail.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ internal class SuggestedPipelineRunDetail
1212
public readonly bool RunSucceded;
1313
public readonly double Score;
1414

15+
public Exception Exception { get; set; }
16+
1517
public SuggestedPipelineRunDetail(SuggestedPipeline pipeline, double score, bool runSucceeded)
1618
{
1719
Pipeline = pipeline;
@@ -34,7 +36,6 @@ internal class SuggestedPipelineRunDetail<TMetrics> : SuggestedPipelineRunDetail
3436
{
3537
public readonly TMetrics ValidationMetrics;
3638
public readonly ModelContainer ModelContainer;
37-
public readonly Exception Exception;
3839

3940
internal SuggestedPipelineRunDetail(SuggestedPipeline pipeline,
4041
double score,

0 commit comments

Comments
 (0)