Skip to content

Commit a028133

Browse files
committed
benchmarking related changes (dotnet#63)
* Create test.txt * Create test.txt * changes needed for benchmarking * forgot one file * merge conflict fix * fix build break * back out my version of the fix for Label column issue and fix the original fix * bogus file removal * undo SuggestedPipeline change * remove labelCol from pipeline suggester * fix build break
1 parent fd71c47 commit a028133

File tree

8 files changed

+74
-22
lines changed

8 files changed

+74
-22
lines changed

src/AutoML/API/MLContextAutoFitExtensions.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,26 @@ public class IterationResult<T>
141141
public readonly ITransformer Model;
142142
public readonly Exception Exception;
143143
public readonly string TrainerName;
144-
internal readonly Pipeline Pipeline;
144+
public readonly int RuntimeInSeconds;
145145

146-
internal IterationResult(ITransformer model, T metrics, Pipeline pipeline, Exception exception)
146+
internal readonly Pipeline Pipeline;
147+
internal readonly int PipelineInferenceTimeInSeconds;
148+
149+
internal IterationResult(
150+
ITransformer model,
151+
T metrics,
152+
Pipeline pipeline,
153+
Exception exception,
154+
int runtimeInSeconds,
155+
int pipelineInferenceTimeInSeconds)
147156
{
148157
Model = model;
149158
Metrics = metrics;
150159
Pipeline = pipeline;
151160
Exception = exception;
161+
RuntimeInSeconds = runtimeInSeconds;
162+
PipelineInferenceTimeInSeconds = pipelineInferenceTimeInSeconds;
163+
152164
TrainerName = pipeline?.Nodes.Where(n => n.NodeType == PipelineNodeType.Trainer).Last().Name;
153165
}
154166
}

src/AutoML/Assembly.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66

77
[assembly: InternalsVisibleTo("Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]
88
[assembly: InternalsVisibleTo("mlnet, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]
9-
[assembly: InternalsVisibleTo("mlnet.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]
9+
[assembly: InternalsVisibleTo("mlnet.Test, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]
10+
[assembly: InternalsVisibleTo("Benchmark, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]

src/AutoML/AutoFitter/AutoFitter.cs

+42-12
Original file line numberDiff line numberDiff line change
@@ -67,26 +67,52 @@ public IEnumerable<IterationResult<T>> Fit()
6767

6868
do
6969
{
70-
// get next pipeline
71-
var iterationsRemaining = (int)_settings.StoppingCriteria.MaxIterations - _history.Count;
72-
var pipeline = PipelineSuggester.GetNextInferredPipeline(_history, columns, _task, iterationsRemaining, _optimizingMetricInfo.IsMaximizing);
70+
SuggestedPipeline pipeline = null;
71+
SuggestedPipelineResult<T> runResult = null;
7372

74-
// break if no candidates returned, means no valid pipeline available
75-
if (pipeline == null)
73+
try
7674
{
77-
break;
78-
}
75+
var iterationStopwatch = Stopwatch.StartNew();
76+
var getPiplelineStopwatch = Stopwatch.StartNew();
77+
78+
// get next pipeline
79+
var iterationsRemaining = (int)_settings.StoppingCriteria.MaxIterations - _history.Count;
80+
pipeline = PipelineSuggester.GetNextInferredPipeline(_history, columns, _task, iterationsRemaining, _optimizingMetricInfo.IsMaximizing);
81+
82+
getPiplelineStopwatch.Stop();
83+
84+
// break if no candidates returned, means no valid pipeline available
85+
if (pipeline == null)
86+
{
87+
break;
88+
}
89+
90+
// evaluate pipeline
91+
runResult = ProcessPipeline(pipeline);
7992

80-
// evaluate pipeline
81-
SuggestedPipelineResult<T> runResult = ProcessPipeline(pipeline);
93+
if (preprocessorTransform != null)
94+
{
95+
runResult.Model = preprocessorTransform.Append(runResult.Model);
96+
}
8297

83-
if (preprocessorTransform != null)
98+
runResult.RuntimeInSeconds = (int)iterationStopwatch.Elapsed.TotalSeconds;
99+
runResult.GetPipelineTimeInSeconds = (int)getPiplelineStopwatch.Elapsed.TotalSeconds;
100+
}
101+
catch (Exception ex)
84102
{
85-
runResult.Model = preprocessorTransform.Append(runResult.Model);
103+
WriteDebugLog(DebugStream.Exception, $"{pipeline?.Trainer} Crashed {ex}");
104+
105+
if (runResult == null)
106+
{
107+
runResult = new SuggestedPipelineResult<T>(null, null, pipeline, -1, ex);
108+
}
109+
else
110+
{
111+
runResult = new SuggestedPipelineResult<T>(runResult.EvaluatedMetrics, runResult.Model, runResult.Pipeline, runResult.Score, ex);
112+
}
86113
}
87114

88115
yield return runResult.ToIterationResult();
89-
90116
} while (_history.Count < _settings.StoppingCriteria.MaxIterations &&
91117
stopwatch.Elapsed.TotalMinutes < _settings.StoppingCriteria.TimeOutInMinutes);
92118
}
@@ -96,6 +122,10 @@ private SuggestedPipelineResult<T> ProcessPipeline(SuggestedPipeline pipeline)
96122
// run pipeline
97123
var stopwatch = Stopwatch.StartNew();
98124

125+
var commandLineStr = $"{string.Join(" xf=", pipeline.Transforms)} tr={pipeline.Trainer}";
126+
127+
WriteDebugLog(DebugStream.RunResult, $"Processing pipeline {commandLineStr}.");
128+
99129
SuggestedPipelineResult<T> runResult;
100130
try
101131
{

src/AutoML/AutoFitter/SuggestedPipeline.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public SuggestedPipeline(IEnumerable<SuggestedTransform> transforms,
3636
}
3737
}
3838

39-
public override string ToString() => $"{Trainer}+{string.Join("+", Transforms.Select(t => t.ToString()))}";
39+
public override string ToString() => $"{string.Join(" xf=", this.Transforms)} tr={this.Trainer}";
4040

4141
public override bool Equals(object obj)
4242
{

src/AutoML/AutoFitter/SuggestedPipelineResult.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ internal class SuggestedPipelineResult<T> : SuggestedPipelineResult
3737
public ITransformer Model { get; set; }
3838
public Exception Exception { get; set; }
3939

40+
public int RuntimeInSeconds { get; set; }
41+
public int GetPipelineTimeInSeconds { get; set; }
42+
4043
public SuggestedPipelineResult(T evaluatedMetrics, ITransformer model, SuggestedPipeline pipeline, double score, Exception exception)
4144
: base(pipeline, score, exception == null)
4245
{
@@ -47,7 +50,9 @@ public SuggestedPipelineResult(T evaluatedMetrics, ITransformer model, Suggested
4750

4851
public IterationResult<T> ToIterationResult()
4952
{
50-
return new IterationResult<T>(Model, EvaluatedMetrics, Pipeline.ToPipeline(), Exception);
53+
var ir = new IterationResult<T>(Model, EvaluatedMetrics, Pipeline.ToPipeline(), Exception, RuntimeInSeconds, GetPipelineTimeInSeconds);
54+
55+
return ir;
5156
}
5257
}
5358
}

src/AutoML/PipelineSuggesters/PipelineSuggester.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.Linq;
88
using Microsoft.Data.DataView;
9+
using Microsoft.ML.Data;
910

1011
namespace Microsoft.ML.Auto
1112
{
@@ -34,6 +35,7 @@ public static SuggestedPipeline GetNextInferredPipeline(IEnumerable<SuggestedPip
3435

3536
var availableTrainers = RecipeInference.AllowedTrainers(context, task, history.Count() + iterationsRemaining);
3637
var transforms = CalculateTransforms(context, columns, task);
38+
//var transforms = TransformInferenceApi.InferTransforms(context, columns, task);
3739

3840
// if we haven't run all pipelines once
3941
if (history.Count() < availableTrainers.Count())
@@ -209,16 +211,16 @@ private static bool SampleHyperparameters(SuggestedTrainer trainer, IEnumerable<
209211
return true;
210212
}
211213

212-
private static IEnumerable<SuggestedTransform> CalculateTransforms(MLContext context,
214+
private static IEnumerable<SuggestedTransform> CalculateTransforms(
215+
MLContext context,
213216
(string, ColumnType, ColumnPurpose, ColumnDimensions)[] columns,
214217
TaskKind task)
215218
{
216219
var transforms = TransformInferenceApi.InferTransforms(context, columns).ToList();
217220
// this is a work-around for ML.NET bug tracked by https://github.com/dotnet/machinelearning/issues/1969
218221
if (task == TaskKind.MulticlassClassification)
219222
{
220-
var labelCol = columns.First(c => c.Item3 == ColumnPurpose.Label).Item1;
221-
var transform = ValueToKeyMappingExtension.CreateSuggestedTransform(context, labelCol, labelCol);
223+
var transform = ValueToKeyMappingExtension.CreateSuggestedTransform(context, DefaultColumnNames.Label, DefaultColumnNames.Label);
222224
transforms.Add(transform);
223225
}
224226
return transforms;

src/AutoML/TrainerExtensions/TrainerExtensionUtil.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ public static void UpdateFields(object obj, IEnumerable<SweepableParam> sweepPar
173173
}
174174
catch (Exception)
175175
{
176-
throw new InvalidOperationException("cannot set learner parameter");
176+
// TODO: uncomment when this is resolved: https://github.com/dotnet/machinelearning/issues/1983
177+
// making this masked since otherwise we can't use this learner at all
178+
// throw new InvalidOperationException("cannot set learner parameter");
177179
}
178180
}
179181
}

src/AutoML/TransformInference/TransformInference.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public override IEnumerable<SuggestedTransform> Apply(IntermediateColumn[] colum
173173
yield break;
174174

175175
var col = columns[lastLabelColId];
176-
176+
177177
if (col.Type.IsText())
178178
{
179179
yield return ValueToKeyMappingExtension.CreateSuggestedTransform(Context, col.ColumnName, DefaultColumnNames.Label);

0 commit comments

Comments
 (0)