Skip to content

Commit e89b9a8

Browse files
authored
CLI -- consume logs from AutoML SDK (dotnet#349)
1 parent a810d8d commit e89b9a8

File tree

5 files changed

+38
-18
lines changed

5 files changed

+38
-18
lines changed

src/Microsoft.ML.Auto/DebugLogger.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ namespace Microsoft.ML.Auto
66
{
77
internal interface IDebugLogger
88
{
9-
void Log(DebugStream stream, string message);
9+
void Log(LogSeverity logLevel, string message);
1010
}
1111

12-
internal enum DebugStream
12+
internal enum LogSeverity
1313
{
14-
Exception,
15-
RunResult
14+
Error,
15+
Debug
1616
}
1717
}

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

+5-9
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public IList<TRunDetails> Execute()
6868
}
6969

7070
// evaluate pipeline
71-
WriteDebugLog(DebugStream.RunResult, $"Evaluating pipeline {pipeline.ToString()}");
71+
Log(LogSeverity.Debug, $"Evaluating pipeline {pipeline.ToString()}");
7272
(SuggestedPipelineRunDetails suggestedPipelineRunDetails, TRunDetails runDetails)
7373
= _runner.Run(pipeline, _modelDirectory, _history.Count + 1);
7474
_history.Add(suggestedPipelineRunDetails);
@@ -128,27 +128,23 @@ private void ReportProgress(TRunDetails iterationResult)
128128
}
129129
catch (Exception ex)
130130
{
131-
WriteDebugLog(DebugStream.Exception, $"Progress report callback reported exception {ex}");
131+
Log(LogSeverity.Error, $"Progress report callback reported exception {ex}");
132132
}
133133
}
134134

135135
private void WriteIterationLog(SuggestedPipeline pipeline, SuggestedPipelineRunDetails runResult, Stopwatch stopwatch)
136136
{
137-
// debug log pipeline result
138-
if (runResult.RunSucceded)
139-
{
140-
WriteDebugLog(DebugStream.RunResult, $"{_history.Count}\t{runResult.Score}\t{stopwatch.Elapsed}\t{pipeline.ToString()}");
141-
}
137+
Log(LogSeverity.Debug, $"{_history.Count}\t{runResult.Score}\t{stopwatch.Elapsed}\t{pipeline.ToString()}");
142138
}
143139

144-
private void WriteDebugLog(DebugStream stream, string message)
140+
private void Log(LogSeverity severity, string message)
145141
{
146142
if(_experimentSettings?.DebugLogger == null)
147143
{
148144
return;
149145
}
150146

151-
_experimentSettings.DebugLogger.Log(stream, message);
147+
_experimentSettings.DebugLogger.Log(severity, message);
152148
}
153149
}
154150
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static (ModelContainer model, TMetrics metrics, Exception exception, doub
4444
}
4545
catch (Exception ex)
4646
{
47-
logger?.Log(DebugStream.Exception, $"Pipeline crashed: {pipeline.ToString()} . Exception: {ex}");
47+
logger?.Log(LogSeverity.Error, $"Pipeline crashed: {pipeline.ToString()} . Exception: {ex}");
4848
return (null, null, ex, double.NaN);
4949
}
5050
}

src/mlnet/AutoML/AutoMLDebugLogger.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using Microsoft.ML.Auto;
6+
using NLog;
7+
8+
namespace Microsoft.ML.CLI.AutoML
9+
{
10+
internal class AutoMLDebugLogger: IDebugLogger
11+
{
12+
public static AutoMLDebugLogger Instance = new AutoMLDebugLogger();
13+
14+
private static Logger logger = LogManager.GetCurrentClassLogger();
15+
16+
public void Log(LogSeverity severity, string message)
17+
{
18+
logger.Log(LogLevel.Trace, message);
19+
}
20+
}
21+
}

src/mlnet/AutoML/AutoMLEngine.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
65
using System.Collections.Generic;
76
using Microsoft.ML.Auto;
7+
using Microsoft.ML.CLI.AutoML;
88
using Microsoft.ML.CLI.Data;
99
using Microsoft.ML.CLI.ShellProgressBar;
1010
using Microsoft.ML.CLI.Utilities;
@@ -53,7 +53,8 @@ IEnumerable<RunDetails<BinaryClassificationMetrics>> IAutoMLEngine.ExploreBinary
5353
{
5454
MaxExperimentTimeInSeconds = settings.MaxExplorationTime,
5555
CacheBeforeTrainer = this.enableCaching,
56-
OptimizingMetric = optimizationMetric
56+
OptimizingMetric = optimizationMetric,
57+
DebugLogger = AutoMLDebugLogger.Instance
5758
})
5859
.Execute(trainData, validationData, columnInformation, progressHandler: progressReporter);
5960
logger.Log(LogLevel.Trace, Strings.RetrieveBestPipeline);
@@ -68,7 +69,8 @@ IEnumerable<RunDetails<RegressionMetrics>> IAutoMLEngine.ExploreRegressionModels
6869
{
6970
MaxExperimentTimeInSeconds = settings.MaxExplorationTime,
7071
OptimizingMetric = optimizationMetric,
71-
CacheBeforeTrainer = this.enableCaching
72+
CacheBeforeTrainer = this.enableCaching,
73+
DebugLogger = AutoMLDebugLogger.Instance
7274
}).Execute(trainData, validationData, columnInformation, progressHandler: progressReporter);
7375
logger.Log(LogLevel.Trace, Strings.RetrieveBestPipeline);
7476
return result;
@@ -82,7 +84,8 @@ IEnumerable<RunDetails<MulticlassClassificationMetrics>> IAutoMLEngine.ExploreMu
8284
{
8385
MaxExperimentTimeInSeconds = settings.MaxExplorationTime,
8486
CacheBeforeTrainer = this.enableCaching,
85-
OptimizingMetric = optimizationMetric
87+
OptimizingMetric = optimizationMetric,
88+
DebugLogger = AutoMLDebugLogger.Instance
8689
}).Execute(trainData, validationData, columnInformation, progressHandler: progressReporter);
8790
logger.Log(LogLevel.Trace, Strings.RetrieveBestPipeline);
8891
return result;

0 commit comments

Comments
 (0)