Skip to content

Commit

Permalink
Add missing linePragmas to ConsumeModel.tt (dotnet#4401)
Browse files Browse the repository at this point in the history
* Add missing linePragmas to ConsumeModel.tt

Fixes dotnet#4400

rebase commits
  • Loading branch information
maryamariyan authored and frank-dong-ms committed Nov 4, 2019
1 parent de6e5a2 commit 11cdcb7
Show file tree
Hide file tree
Showing 68 changed files with 660 additions and 242 deletions.
2 changes: 1 addition & 1 deletion build/ci/job-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ parameters:
jobs:
- job: ${{ parameters.name }}
${{ if eq(parameters.codeCoverage, 'false') }}:
timeoutInMinutes: 60
timeoutInMinutes: 75
${{ if eq(parameters.codeCoverage, 'true') }}:
timeoutInMinutes: 60
strategy:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
<NativeAssemblyReference Include="MatrixFactorizationNative" />
<NativeAssemblyReference Include="FastTreeNative" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="SciSharp.TensorFlow.Redist" Version="$(TensorFlowVersion)" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions pkg/Microsoft.ML.AutoML/Microsoft.ML.AutoML.nupkgproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<ProjectReference Include="../Microsoft.ML.LightGbm/Microsoft.ML.LightGbm.nupkgproj" />
<ProjectReference Include="../Microsoft.ML.Mkl.Components/Microsoft.ML.Mkl.Components.nupkgproj" />
<ProjectReference Include="../Microsoft.ML.Recommender/Microsoft.ML.Recommender.nupkgproj" />
<ProjectReference Include="../Microsoft.ML/Microsoft.ML.Dnn.nupkgproj" />
<ProjectReference Include="../Microsoft.ML/Microsoft.ML.ImageAnalytics.nupkgproj" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions src/Microsoft.ML.AutoML/API/ColumnInference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,20 @@ public sealed class ColumnInformation
/// <value>The default value is a new, empty <see cref="Collection{String}"/>.</value>
public ICollection<string> IgnoredColumnNames { get; }

/// <summary>
/// The dataset columns that are image paths.
/// </summary>
/// <value>The default value is a new, empty <see cref="Collection{String}"/>.</value>
public ICollection<string> ImagePathColumnNames { get; }

public ColumnInformation()
{
LabelColumnName = DefaultColumnNames.Label;
CategoricalColumnNames = new Collection<string>();
NumericColumnNames = new Collection<string>();
TextColumnNames = new Collection<string>();
IgnoredColumnNames = new Collection<string>();
ImagePathColumnNames = new Collection<string>();
}
}
}
9 changes: 6 additions & 3 deletions src/Microsoft.ML.AutoML/API/ExperimentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public ExperimentResult<TMetrics> Execute(IDataView trainData, ColumnInformation
const int crossValRowCountThreshold = 15000;

var rowCount = DatasetDimensionsUtil.CountRows(trainData, crossValRowCountThreshold);

if (rowCount < crossValRowCountThreshold)
{
const int numCrossValFolds = 10;
Expand Down Expand Up @@ -160,7 +159,9 @@ public ExperimentResult<TMetrics> Execute(IDataView trainData, IDataView validat
/// <remarks>
/// Depending on the size of your data, the AutoML experiment could take a long time to execute.
/// </remarks>
public ExperimentResult<TMetrics> Execute(IDataView trainData, IDataView validationData, ColumnInformation columnInformation, IEstimator<ITransformer> preFeaturizer = null, IProgress<RunDetail<TMetrics>> progressHandler = null)
public ExperimentResult<TMetrics> Execute(IDataView trainData, IDataView validationData,
ColumnInformation columnInformation, IEstimator<ITransformer> preFeaturizer = null,
IProgress<RunDetail<TMetrics>> progressHandler = null)
{
if (validationData == null)
{
Expand Down Expand Up @@ -188,7 +189,9 @@ public ExperimentResult<TMetrics> Execute(IDataView trainData, IDataView validat
/// <remarks>
/// Depending on the size of your data, the AutoML experiment could take a long time to execute.
/// </remarks>
public CrossValidationExperimentResult<TMetrics> Execute(IDataView trainData, uint numberOfCVFolds, ColumnInformation columnInformation = null, IEstimator<ITransformer> preFeaturizer = null, IProgress<CrossValidationRunDetail<TMetrics>> progressHandler = null)
public CrossValidationExperimentResult<TMetrics> Execute(IDataView trainData, uint numberOfCVFolds,
ColumnInformation columnInformation = null, IEstimator<ITransformer> preFeaturizer = null,
IProgress<CrossValidationRunDetail<TMetrics>> progressHandler = null)
{
UserInputValidationUtil.ValidateNumberOfCVFoldsArg(numberOfCVFolds);
var splitResult = SplitUtil.CrossValSplit(Context, trainData, numberOfCVFolds, columnInformation?.SamplingKeyColumnName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ internal static class ColumnInformationUtil
return ColumnPurpose.ItemId;
}

if (columnInfo.ImagePathColumnNames.Contains(columnName))
{
return ColumnPurpose.ImagePath;
}

return null;
}

Expand Down Expand Up @@ -94,6 +99,9 @@ internal static ColumnInformation BuildColumnInfo(IEnumerable<(string name, Colu
case ColumnPurpose.TextFeature:
columnInfo.TextColumnNames.Add(column.name);
break;
case ColumnPurpose.ImagePath:
columnInfo.ImagePathColumnNames.Add(column.name);
break;
}
}

Expand Down Expand Up @@ -121,6 +129,7 @@ public static IEnumerable<string> GetColumnNames(ColumnInformation columnInforma
AddStringsToListIfNotNull(columnNames, columnInformation.IgnoredColumnNames);
AddStringsToListIfNotNull(columnNames, columnInformation.NumericColumnNames);
AddStringsToListIfNotNull(columnNames, columnInformation.TextColumnNames);
AddStringsToListIfNotNull(columnNames, columnInformation.ImagePathColumnNames);
return columnNames;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ public static PurposeInference.Column[] InferPurposes(MLContext context, IDataVi
ColumnInformation columnInfo)
{
data = context.Data.TakeRows(data, MaxRowsToRead);

var allColumns = new List<IntermediateColumn>();
var columnsToInfer = new List<IntermediateColumn>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ internal enum EstimatorName
OneHotHashEncoding,
TextFeaturizing,
TypeConverting,
ValueToKeyMapping
ValueToKeyMapping,
ImageLoading
}

internal class EstimatorExtensionCatalog
Expand All @@ -38,6 +39,7 @@ internal class EstimatorExtensionCatalog
{ EstimatorName.TextFeaturizing, typeof(TextFeaturizingExtension) },
{ EstimatorName.TypeConverting, typeof(TypeConvertingExtension) },
{ EstimatorName.ValueToKeyMapping, typeof(ValueToKeyMappingExtension) },
{ EstimatorName.ImageLoading, typeof(ImageLoadingExtension) }
};

public static IEstimatorExtension GetExtension(EstimatorName estimatorName)
Expand Down
27 changes: 27 additions & 0 deletions src/Microsoft.ML.AutoML/EstimatorExtensions/EstimatorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using Microsoft.ML.Data;
using Microsoft.ML.Transforms;

Expand Down Expand Up @@ -260,6 +261,7 @@ public static SuggestedTransform CreateSuggestedTransform(MLContext context, str
{
var pipelineNode = new PipelineNode(EstimatorName.ValueToKeyMapping.ToString(),
PipelineNodeType.Transform, inColumn, outColumn);

var estimator = CreateInstance(context, inColumn, outColumn);
return new SuggestedTransform(pipelineNode, estimator);
}
Expand All @@ -269,4 +271,29 @@ private static IEstimator<ITransformer> CreateInstance(MLContext context, string
return context.Transforms.Conversion.MapValueToKey(outColumn, inColumn);
}
}

internal class ImageLoadingExtension : IEstimatorExtension
{
public static string ImageFolder { private get; set; }
public IEstimator<ITransformer> CreateInstance(MLContext context, PipelineNode pipelineNode)
{
return CreateInstance(context, pipelineNode.InColumns[0], pipelineNode.OutColumns[0]);
}

public static SuggestedTransform CreateSuggestedTransform(MLContext context, string inColumn, string outColumn)
{
var pipelineNodeProperty = new Dictionary<string, object>()
{
{ "imageFolder", ImageFolder },
};
var pipelineNode = new PipelineNode(EstimatorName.ImageLoading.ToString(), PipelineNodeType.Transform, inColumn, outColumn, pipelineNodeProperty);
var estimator = CreateInstance(context, inColumn, outColumn);
return new SuggestedTransform(pipelineNode, estimator);
}

private static IEstimator<ITransformer> CreateInstance(MLContext context, string inColumn, string outColumn)
{
return context.Transforms.LoadRawImageBytes(outColumn, ImageFolder, inColumn);
}
}
}
5 changes: 4 additions & 1 deletion src/Microsoft.ML.AutoML/Experiment/Experiment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public IList<TRunDetail> Execute()

// get next pipeline
var getPiplelineStopwatch = Stopwatch.StartNew();
var pipeline = PipelineSuggester.GetNextInferredPipeline(_context, _history, _datasetColumnInfo, _task, _optimizingMetricInfo.IsMaximizing, _experimentSettings.CacheBeforeTrainer, _trainerWhitelist);
var pipeline = PipelineSuggester.GetNextInferredPipeline(_context, _history, _datasetColumnInfo, _task,
_optimizingMetricInfo.IsMaximizing, _experimentSettings.CacheBeforeTrainer, _trainerWhitelist);

var pipelineInferenceTimeInSeconds = getPiplelineStopwatch.Elapsed.TotalSeconds;

// break if no candidates returned, means no valid pipeline available
Expand All @@ -75,6 +77,7 @@ public IList<TRunDetail> Execute()
_logger.Trace($"Evaluating pipeline {pipeline.ToString()}");
(SuggestedPipelineRunDetail suggestedPipelineRunDetail, TRunDetail runDetail)
= _runner.Run(pipeline, _modelDirectory, _history.Count + 1);

_history.Add(suggestedPipelineRunDetail);
WriteIterationLog(pipeline, suggestedPipelineRunDetail, iterationStopwatch);

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.AutoML/Experiment/RecipeInference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal static class RecipeInference
public static IEnumerable<SuggestedTrainer> AllowedTrainers(MLContext mlContext, TaskKind task,
ColumnInformation columnInfo, IEnumerable<TrainerName> trainerWhitelist)
{
var trainerExtensions = TrainerExtensionCatalog.GetTrainers(task, trainerWhitelist);
var trainerExtensions = TrainerExtensionCatalog.GetTrainers(task, trainerWhitelist, columnInfo);

var trainers = new List<SuggestedTrainer>();
foreach (var trainerExtension in trainerExtensions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.ML.AutoML/Experiment/Runners/RunnerUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static (ModelContainer model, TMetrics metrics, Exception exception, doub
{
try
{
var estimator = pipeline.ToEstimator();
var estimator = pipeline.ToEstimator(trainData, validData);
var model = estimator.Fit(trainData);

var scoredData = model.Transform(validData);
Expand Down
18 changes: 12 additions & 6 deletions src/Microsoft.ML.AutoML/Experiment/SuggestedPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public SuggestedPipeline(IEnumerable<SuggestedTransform> transforms,
public override bool Equals(object obj)
{
var pipeline = obj as SuggestedPipeline;
if(pipeline == null)
if (pipeline == null)
{
return false;
}
Expand All @@ -55,7 +55,7 @@ public override int GetHashCode()
public Pipeline ToPipeline()
{
var pipelineElements = new List<PipelineNode>();
foreach(var transform in Transforms)
foreach (var transform in Transforms)
{
pipelineElements.Add(transform.PipelineNode);
}
Expand All @@ -74,9 +74,9 @@ public static SuggestedPipeline FromPipeline(MLContext context, Pipeline pipelin
SuggestedTrainer trainer = null;

var trainerEncountered = false;
foreach(var pipelineNode in pipeline.Nodes)
foreach (var pipelineNode in pipeline.Nodes)
{
if(pipelineNode.NodeType == PipelineNodeType.Trainer)
if (pipelineNode.NodeType == PipelineNodeType.Trainer)
{
var trainerName = (TrainerName)Enum.Parse(typeof(TrainerName), pipelineNode.Name);
var trainerExtension = TrainerExtensionCatalog.GetTrainerExtension(trainerName);
Expand Down Expand Up @@ -105,7 +105,8 @@ public static SuggestedPipeline FromPipeline(MLContext context, Pipeline pipelin
return new SuggestedPipeline(transforms, transformsPostTrainer, trainer, context, pipeline.CacheBeforeTrainer);
}

public IEstimator<ITransformer> ToEstimator()
public IEstimator<ITransformer> ToEstimator(IDataView trainset = null,
IDataView validationSet = null)
{
IEstimator<ITransformer> pipeline = new EstimatorChain<ITransformer>();

Expand All @@ -118,8 +119,13 @@ public IEstimator<ITransformer> ToEstimator()
}
}

if (validationSet != null)
{
validationSet = pipeline.Fit(validationSet).Transform(validationSet);
}

// Get learner
var learner = Trainer.BuildTrainer();
var learner = Trainer.BuildTrainer(validationSet);

if (_cacheBeforeTrainer)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Microsoft.ML.AutoML/Experiment/SuggestedTrainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.ML.Trainers;
Expand Down Expand Up @@ -41,14 +42,14 @@ public SuggestedTrainer Clone()
return new SuggestedTrainer(_mlContext, _trainerExtension, _columnInfo, HyperParamSet?.Clone());
}

public ITrainerEstimator<IPredictionTransformer<object>, object> BuildTrainer()
public ITrainerEstimator<IPredictionTransformer<object>, object> BuildTrainer(IDataView validationSet = null)
{
IEnumerable<SweepableParam> sweepParams = null;
if (HyperParamSet != null)
{
sweepParams = SweepParams;
}
return _trainerExtension.CreateInstance(_mlContext, sweepParams, _columnInfo);
return _trainerExtension.CreateInstance(_mlContext, sweepParams, _columnInfo, validationSet);
}

public override string ToString()
Expand All @@ -63,7 +64,7 @@ public override string ToString()

public PipelineNode ToPipelineNode()
{
var sweepParams = SweepParams.Where(p => p.RawValue != null);
var sweepParams = SweepParams?.Where(p => p.RawValue != null);
return _trainerExtension.CreatePipelineNode(sweepParams, _columnInfo);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.ML.AutoML/Microsoft.ML.AutoML.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.ML.Core\Microsoft.ML.Core.csproj" />
<ProjectReference Include="..\Microsoft.ML.CpuMath\Microsoft.ML.CpuMath.csproj" />
<ProjectReference Include="..\Microsoft.ML.Dnn\Microsoft.ML.Dnn.csproj" />
<ProjectReference Include="..\Microsoft.ML.ImageAnalytics\Microsoft.ML.ImageAnalytics.csproj" />
<ProjectReference Include="..\Microsoft.ML.LightGbm\Microsoft.ML.LightGbm.csproj" />
<ProjectReference Include="..\Microsoft.ML.Mkl.Components\Microsoft.ML.Mkl.Components.csproj" />
<ProjectReference Include="..\Microsoft.ML.Recommender\Microsoft.ML.Recommender.csproj" />
Expand Down
Loading

0 comments on commit 11cdcb7

Please sign in to comment.