From 52ee74a633340aa6cabe494501273d44330923f5 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 27 Sep 2018 14:09:01 -0500 Subject: [PATCH 1/7] Add a workaround for the tests hanging while loading MKL. The workaround is to ensure the MKL library is loaded very early in the test process, so it doesn't cause the deadlock. Also moving the test queue back to the hosted windows pool. Workaround #1073 --- .vsts-dotnet-ci.yml | 2 +- test/Microsoft.ML.TestFramework/GlobalBase.cs | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.vsts-dotnet-ci.yml b/.vsts-dotnet-ci.yml index 0a721add5f..1f9d585e97 100644 --- a/.vsts-dotnet-ci.yml +++ b/.vsts-dotnet-ci.yml @@ -10,7 +10,7 @@ phases: name: Windows_NT buildScript: build.cmd queue: - name: DotNetCore-Windows + name: Hosted VS2017 - template: /build/ci/phase-template.yml parameters: diff --git a/test/Microsoft.ML.TestFramework/GlobalBase.cs b/test/Microsoft.ML.TestFramework/GlobalBase.cs index 8ecdb24b36..ecb185b625 100644 --- a/test/Microsoft.ML.TestFramework/GlobalBase.cs +++ b/test/Microsoft.ML.TestFramework/GlobalBase.cs @@ -11,6 +11,7 @@ // } using System; +using System.Runtime.InteropServices; using Xunit; namespace Microsoft.ML.Runtime.Internal.Internallearn.Test @@ -22,6 +23,28 @@ public static void AssemblyInit() System.Diagnostics.Debug.WriteLine("*** Setting test assertion handler"); var prev = Contracts.SetAssertHandler(AssertHandler); Contracts.Check(prev == null, "Expected to replace null assertion handler!"); + + // HACK: ensure MklImports is loaded very early in the tests so it doesn't deadlock while loading it later. + // See https://github.com/dotnet/machinelearning/issues/1073 + Mkl.PptrfInternal(Mkl.Layout.RowMajor, Mkl.UpLo.Up, 0, Array.Empty()); + } + + private static class Mkl + { + public enum Layout + { + RowMajor = 101, + ColMajor = 102 + } + + public enum UpLo : byte + { + Up = (byte)'U', + Lo = (byte)'L' + } + + [DllImport("MklImports", EntryPoint = "LAPACKE_dpptrf")] + public static extern int PptrfInternal(Layout layout, UpLo uplo, int n, double[] ap); } public static void AssemblyCleanup() From a2ccdaac98c17cd92fb43bc4a48494b97a8203c5 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 27 Sep 2018 19:13:30 -0500 Subject: [PATCH 2/7] try to add some logging to see what is going on --- .../TestPipelineSweeper.cs | 4 +- .../TestPredictors.cs | 4 +- .../BaseTestBaseline.cs | 52 +++++-------------- .../BaseTestClass.cs | 28 +++++++++- .../DataPipe/Parquet.cs | 4 +- test/Microsoft.ML.TestFramework/GlobalBase.cs | 36 +++++++++++++ .../Microsoft.ML.TestFramework.csproj | 2 + 7 files changed, 85 insertions(+), 45 deletions(-) diff --git a/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs b/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs index e3f144b215..09f694d71f 100644 --- a/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs +++ b/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs @@ -22,9 +22,9 @@ public TestPipelineSweeper(ITestOutputHelper helper) { } - protected override void InitializeCore() + protected override void Initialize() { - base.InitializeCore(); + base.Initialize(); Env.ComponentCatalog.RegisterAssembly(typeof(AutoInference).Assembly); } diff --git a/test/Microsoft.ML.Predictor.Tests/TestPredictors.cs b/test/Microsoft.ML.Predictor.Tests/TestPredictors.cs index fdf2f50168..44667f2dd3 100644 --- a/test/Microsoft.ML.Predictor.Tests/TestPredictors.cs +++ b/test/Microsoft.ML.Predictor.Tests/TestPredictors.cs @@ -28,9 +28,9 @@ namespace Microsoft.ML.Runtime.RunTests /// public sealed partial class TestPredictors : BaseTestPredictors { - protected override void InitializeCore() + protected override void Initialize() { - base.InitializeCore(); + base.Initialize(); InitializeEnvironment(Env); } diff --git a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs index e4ce5fac50..86708d445a 100644 --- a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs +++ b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs @@ -9,7 +9,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; @@ -24,20 +23,8 @@ namespace Microsoft.ML.Runtime.RunTests /// public abstract partial class BaseTestBaseline : BaseTestClass, IDisposable { - private readonly ITestOutputHelper _output; - - protected BaseTestBaseline(ITestOutputHelper helper) : base(helper) - { - _output = helper; - ITest test = (ITest)helper.GetType().GetField("test", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(helper); - FullTestName = test.TestCase.TestMethod.TestClass.Class.Name + "." + test.TestCase.TestMethod.Method.Name; - TestName = test.TestCase.TestMethod.Method.Name; - Init(); - } - - void IDisposable.Dispose() + protected BaseTestBaseline(ITestOutputHelper output) : base(output) { - Cleanup(); } internal const string RawSuffix = ".raw"; @@ -92,11 +79,10 @@ void IDisposable.Dispose() private bool _normal; private bool _passed; - public string TestName { get; set; } - public string FullTestName { get; set; } - - public void Init() + protected override void Initialize() { + base.Initialize(); + // Create the output and log directories. Contracts.Check(Directory.Exists(Path.Combine(RootDir, TestDir, "BaselineOutput"))); string logDir = Path.Combine(OutDir, _logRootRelPath); @@ -110,15 +96,17 @@ public void Init() _passed = true; Env = new ConsoleEnvironment(42, outWriter: LogWriter, errWriter: LogWriter) .AddStandardComponents(); - InitializeCore(); } - public void Cleanup() + // This method is used by subclass to dispose of disposable objects + // such as LocalEnvironment. + // It is called as a first step in test clean up. + protected override void Cleanup() { - // REVIEW: Is there a way to determine whether the test completed normally? - // Requiring tests to call Done() is hokey. + if (Env != null) + Env.Dispose(); + Env = null; - CleanupCore(); Contracts.Assert(IsActive); Log("Test {0}: {1}: {2}", TestName, _normal ? "completed normally" : "aborted", @@ -127,20 +115,8 @@ public void Cleanup() Contracts.AssertValue(LogWriter); LogWriter.Dispose(); LogWriter = null; - } - - protected virtual void InitializeCore() - { - } - // This method is used by subclass to dispose of disposable objects - // such as LocalEnvironment. - // It is called as a first step in test clean up. - protected virtual void CleanupCore() - { - if (Env != null) - Env.Dispose(); - Env = null; + base.Cleanup(); } protected bool IsActive { get { return LogWriter != null; } } @@ -209,7 +185,7 @@ protected void Log(string msg) Contracts.Assert(IsActive); Contracts.AssertValue(LogWriter); LogWriter.WriteLine(msg); - _output.WriteLine(msg); + Output.WriteLine(msg); } protected void Log(string fmt, params object[] args) @@ -217,7 +193,7 @@ protected void Log(string fmt, params object[] args) Contracts.Assert(IsActive); Contracts.AssertValue(LogWriter); LogWriter.WriteLine(fmt, args); - _output.WriteLine(fmt, args); + Output.WriteLine(fmt, args); } protected string GetBaselineDir(string subDir) diff --git a/test/Microsoft.ML.TestFramework/BaseTestClass.cs b/test/Microsoft.ML.TestFramework/BaseTestClass.cs index b5d7a23db3..cdeeabf864 100644 --- a/test/Microsoft.ML.TestFramework/BaseTestClass.cs +++ b/test/Microsoft.ML.TestFramework/BaseTestClass.cs @@ -3,19 +3,24 @@ // See the LICENSE file in the project root for more information. using Microsoft.ML.Runtime.Internal.Internallearn.Test; +using System; using System.Globalization; using System.IO; +using System.Reflection; using System.Threading; using Xunit.Abstractions; namespace Microsoft.ML.TestFramework { - public class BaseTestClass + public class BaseTestClass : IDisposable { private readonly string _rootDir; private readonly string _outDir; private readonly string _dataRoot; + public string TestName { get; set; } + public string FullTestName { get; set; } + static BaseTestClass() => GlobalBase.AssemblyInit(); public BaseTestClass(ITestOutputHelper output) @@ -31,6 +36,27 @@ public BaseTestClass(ITestOutputHelper output) Directory.CreateDirectory(_outDir); _dataRoot = Path.Combine(_rootDir, "test", "data"); Output = output; + + ITest test = (ITest)output.GetType().GetField("test", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(output); + FullTestName = test.TestCase.TestMethod.TestClass.Class.Name + "." + test.TestCase.TestMethod.Method.Name; + TestName = test.TestCase.TestMethod.Method.Name; + + Console.WriteLine($"Starting test: {FullTestName}"); + Initialize(); + } + + void IDisposable.Dispose() + { + Cleanup(); + Console.WriteLine($"Finished test: {FullTestName}"); + } + + protected virtual void Initialize() + { + } + + protected virtual void Cleanup() + { } protected string RootDir => _rootDir; diff --git a/test/Microsoft.ML.TestFramework/DataPipe/Parquet.cs b/test/Microsoft.ML.TestFramework/DataPipe/Parquet.cs index b3b68c5a8a..eeebdaf6d7 100644 --- a/test/Microsoft.ML.TestFramework/DataPipe/Parquet.cs +++ b/test/Microsoft.ML.TestFramework/DataPipe/Parquet.cs @@ -10,9 +10,9 @@ namespace Microsoft.ML.Runtime.RunTests { public sealed partial class TestParquet : TestDataPipeBase { - protected override void InitializeCore() + protected override void Initialize() { - base.InitializeCore(); + base.Initialize(); Env.ComponentCatalog.RegisterAssembly(typeof(ParquetLoader).Assembly); } diff --git a/test/Microsoft.ML.TestFramework/GlobalBase.cs b/test/Microsoft.ML.TestFramework/GlobalBase.cs index ecb185b625..79639bb0d6 100644 --- a/test/Microsoft.ML.TestFramework/GlobalBase.cs +++ b/test/Microsoft.ML.TestFramework/GlobalBase.cs @@ -11,6 +11,7 @@ // } using System; +using System.Management; using System.Runtime.InteropServices; using Xunit; @@ -27,6 +28,41 @@ public static void AssemblyInit() // HACK: ensure MklImports is loaded very early in the tests so it doesn't deadlock while loading it later. // See https://github.com/dotnet/machinelearning/issues/1073 Mkl.PptrfInternal(Mkl.Layout.RowMajor, Mkl.UpLo.Up, 0, Array.Empty()); + + PrintCpuInfo(); + } + + private static void PrintCpuInfo() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + ManagementClass clsMgtClass = new ManagementClass("Win32_Processor"); + ManagementObjectCollection colMgtObjCol = clsMgtClass.GetInstances(); + + foreach (ManagementObject objMgtObj in colMgtObjCol) + { + foreach (var property in objMgtObj.Properties) + { + Console.WriteLine("CPU Property " + property.Name + " = " + property.Value); + + } + } + + double totalCapacity = 0; + ObjectQuery objectQuery = new ObjectQuery("select * from Win32_PhysicalMemory"); + ManagementObjectSearcher searcher = new ManagementObjectSearcher(objectQuery); + ManagementObjectCollection vals = searcher.Get(); + + foreach (ManagementObject val in vals) + { + totalCapacity += System.Convert.ToDouble(val.GetPropertyValue("Capacity")); + } + + Console.WriteLine("Total Machine Memory = " + totalCapacity.ToString() + " Bytes"); + Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1024) + " KiloBytes"); + Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1048576) + " MegaBytes"); + Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1073741824) + " GigaBytes"); + } } private static class Mkl diff --git a/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj b/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj index b191c08a91..248012cef2 100644 --- a/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj +++ b/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj @@ -16,6 +16,8 @@ + + From f446dc7678924ed3402ee7080ac255ed0e1af49c Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 27 Sep 2018 20:28:46 -0500 Subject: [PATCH 3/7] CI trigger From 4929cabf12961b55d784e4eb4a28b0883601df3b Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 27 Sep 2018 21:14:11 -0500 Subject: [PATCH 4/7] Remove unused field --- test/Microsoft.ML.TestFramework/BaseTestBaseline.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs index 71c694c962..6cfcc16876 100644 --- a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs +++ b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs @@ -24,7 +24,6 @@ namespace Microsoft.ML.Runtime.RunTests public abstract partial class BaseTestBaseline : BaseTestClass, IDisposable { public const decimal Tolerance = 10_000_000; - private readonly ITestOutputHelper _output; protected BaseTestBaseline(ITestOutputHelper output) : base(output) { @@ -876,4 +875,4 @@ public void TestTimeRegex() Done(); } } -} \ No newline at end of file +} From 8283b7c43ada3648f18b2498e82eeda777cac7b0 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Thu, 27 Sep 2018 23:09:20 -0500 Subject: [PATCH 5/7] Don't create so many ConsoleEnvironments --- .../AutoInference.cs | 6 ++--- .../ColumnTypeInference.cs | 2 +- .../InferenceUtils.cs | 11 +++------ .../PurposeInference.cs | 2 +- .../RecipeInference.cs | 2 +- .../TextFileContents.cs | 2 +- .../TransformInference.cs | 6 ++--- .../TestPipelineSweeper.cs | 24 +++++++++---------- 8 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/Microsoft.ML.PipelineInference/AutoInference.cs b/src/Microsoft.ML.PipelineInference/AutoInference.cs index 54e95e595d..852efb05de 100644 --- a/src/Microsoft.ML.PipelineInference/AutoInference.cs +++ b/src/Microsoft.ML.PipelineInference/AutoInference.cs @@ -235,7 +235,7 @@ private void ProcessPipeline(Sweeper.Algorithms.SweeperProbabilityUtils utils, S // Run pipeline, and time how long it takes stopwatch.Restart(); - candidate.RunTrainTestExperiment(_trainData.Take(randomizedNumberOfRows), + candidate.RunTrainTestExperiment(_trainData.Take(randomizedNumberOfRows, _env), _testData, Metric, TrainerKind, out var testMetricVal, out var trainMetricVal); stopwatch.Stop(); @@ -500,7 +500,7 @@ public static AutoMlMlState InferPipelines(IHostEnvironment env, PipelineOptimiz #pragma warning restore 0618 var splitOutput = TrainTestSplit.Split(env, new TrainTestSplit.Input { Data = data, Fraction = 0.8f }); AutoMlMlState amls = new AutoMlMlState(env, metric, autoMlEngine, terminator, trainerKind, - splitOutput.TrainData.Take(numOfSampleRows), splitOutput.TestData.Take(numOfSampleRows)); + splitOutput.TrainData.Take(numOfSampleRows, env), splitOutput.TestData.Take(numOfSampleRows, env)); bestPipeline = amls.InferPipelines(numTransformLevels, batchSize, numOfSampleRows); return amls; } @@ -514,7 +514,7 @@ public static AutoMlMlState InferPipelines(IHostEnvironment env, PipelineOptimiz var splitOutput = TrainTestSplit.Split(env, new TrainTestSplit.Input { Data = data, Fraction = 0.8f }); AutoMlMlState amls = new AutoMlMlState(env, metric, autoMlEngine, terminator, trainerKind, - splitOutput.TrainData.Take(numOfSampleRows), splitOutput.TestData.Take(numOfSampleRows)); + splitOutput.TrainData.Take(numOfSampleRows, env), splitOutput.TestData.Take(numOfSampleRows, env)); bestPipeline = amls.InferPipelines(numTransformLevels, batchSize, numOfSampleRows); return amls; } diff --git a/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs b/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs index 5c589c50bf..d553dfae1f 100644 --- a/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs +++ b/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs @@ -261,7 +261,7 @@ private static InferenceResult InferTextFileColumnTypesCore(IHostEnvironment env AllowQuoting = args.AllowQuote, }; var idv = TextLoader.ReadFile(env, textLoaderArgs, fileSource); - idv = idv.Take(args.MaxRowsToRead); + idv = idv.Take(args.MaxRowsToRead, env); // Read all the data into memory. // List items are rows of the dataset. diff --git a/src/Microsoft.ML.PipelineInference/InferenceUtils.cs b/src/Microsoft.ML.PipelineInference/InferenceUtils.cs index 478e732b9f..320a1c81ea 100644 --- a/src/Microsoft.ML.PipelineInference/InferenceUtils.cs +++ b/src/Microsoft.ML.PipelineInference/InferenceUtils.cs @@ -5,21 +5,16 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; -using Microsoft.ML.Runtime.Data.Conversion; using Microsoft.ML.Runtime.Internal.Utilities; namespace Microsoft.ML.Runtime.PipelineInference { public static class InferenceUtils { - public static IDataView Take(this IDataView data, int count) + public static IDataView Take(this IDataView data, int count, IHostEnvironment env) { Contracts.CheckValue(data, nameof(data)); - // REVIEW: This should take an env as a parameter, not create one. - var env = new ConsoleEnvironment(0); var take = SkipTakeFilter.Create(env, new SkipTakeFilter.TakeArguments { Count = count }, data); return CacheCore(take, env); } @@ -38,7 +33,7 @@ private static IDataView CacheCore(IDataView data, IHostEnvironment env) return new CacheDataView(env, data, Utils.GetIdentityPermutation(data.Schema.ColumnCount)); } - public static Type InferPredictorCategoryType(IDataView data, PurposeInference.Column[] columns) + public static Type InferPredictorCategoryType(IDataView data, PurposeInference.Column[] columns, IHostEnvironment env) { List labels = columns.Where(col => col.Purpose == ColumnPurpose.Label).ToList(); if (labels.Count == 0) @@ -49,7 +44,7 @@ public static Type InferPredictorCategoryType(IDataView data, PurposeInference.C PurposeInference.Column label = labels.First(); HashSet uniqueLabelValues = new HashSet(); - data = data.Take(1000); + data = data.Take(1000, env); using (var cursor = data.GetRowCursor(index => index == label.ColumnIndex)) { ValueGetter> getter = DataViewUtils.PopulateGetterArray(cursor, new List { label.ColumnIndex })[0]; diff --git a/src/Microsoft.ML.PipelineInference/PurposeInference.cs b/src/Microsoft.ML.PipelineInference/PurposeInference.cs index b2f57328a8..e5a6482bfe 100644 --- a/src/Microsoft.ML.PipelineInference/PurposeInference.cs +++ b/src/Microsoft.ML.PipelineInference/PurposeInference.cs @@ -332,7 +332,7 @@ public static InferenceResult InferPurposes(IHostEnvironment env, IDataView data InferenceResult result; using (var ch = host.Start("InferPurposes")) { - var takenData = data.Take(args.MaxRowsToRead); + var takenData = data.Take(args.MaxRowsToRead, env); var cols = columnIndices.Select(x => new IntermediateColumn(takenData, x)).ToList(); data = takenData; diff --git a/src/Microsoft.ML.PipelineInference/RecipeInference.cs b/src/Microsoft.ML.PipelineInference/RecipeInference.cs index c19fabb251..39d36a929f 100644 --- a/src/Microsoft.ML.PipelineInference/RecipeInference.cs +++ b/src/Microsoft.ML.PipelineInference/RecipeInference.cs @@ -449,7 +449,7 @@ public static SuggestedRecipe[] InferRecipesFromData(IHostEnvironment env, strin ExcludeFeaturesConcatTransforms = excludeFeaturesConcatTransforms } ); - predictorType = InferenceUtils.InferPredictorCategoryType(cached, purposeColumns); + predictorType = InferenceUtils.InferPredictorCategoryType(cached, purposeColumns, env); var recipeInferenceResult = InferRecipes(h, transformInferenceResult, predictorType); ch.Done(); diff --git a/src/Microsoft.ML.PipelineInference/TextFileContents.cs b/src/Microsoft.ML.PipelineInference/TextFileContents.cs index 2ba5e23d0b..167fe536e7 100644 --- a/src/Microsoft.ML.PipelineInference/TextFileContents.cs +++ b/src/Microsoft.ML.PipelineInference/TextFileContents.cs @@ -123,7 +123,7 @@ private static bool TryParseFile(IChannel ch, TextLoader.Arguments args, IMultiS { messages.Add(msg); }); - var idv = TextLoader.ReadFile(loaderEnv, args, source).Take(1000); + var idv = TextLoader.ReadFile(loaderEnv, args, source).Take(1000, loaderEnv); var columnCounts = new List(); int columnIndex; bool found = idv.Schema.TryGetColumnIndex("C", out columnIndex); diff --git a/src/Microsoft.ML.PipelineInference/TransformInference.cs b/src/Microsoft.ML.PipelineInference/TransformInference.cs index 2eca74ed5c..3f0cfaf6d6 100644 --- a/src/Microsoft.ML.PipelineInference/TransformInference.cs +++ b/src/Microsoft.ML.PipelineInference/TransformInference.cs @@ -1539,7 +1539,7 @@ public static InferenceResult InferTransforms(IHostEnvironment env, IDataView da h.CheckValue(args, nameof(args)); h.Check(args.EstimatedSampleFraction > 0); - data = data.Take(MaxRowsToRead); + data = data.Take(MaxRowsToRead, env); var cols = purposes.Where(x => !data.Schema.IsHidden(x.ColumnIndex)).Select(x => new IntermediateColumn(data, x)).ToArray(); using (var rootCh = h.Start("InferTransforms")) { @@ -1587,7 +1587,7 @@ public static SuggestedTransform[] InferTransforms(IHostEnvironment env, IDataVi var availableTransforms = env.ComponentCatalog.AllEntryPoints() .Where(x => x.InputKinds?.FirstOrDefault(i => i == typeof(CommonInputs.ITransformInput)) != null && x.InputKinds?.Any(i => i == typeof(CommonInputs.ICalibratorInput)) != true); - var dataSample = data.Take(MaxRowsToRead); + var dataSample = data.Take(MaxRowsToRead, env); // Infer column purposes from data sample. var piArgs = new PurposeInference.Arguments { MaxRowsToRead = MaxRowsToRead }; @@ -1619,7 +1619,7 @@ public static SuggestedTransform[] InferConcatNumericFeatures(IHostEnvironment e h.CheckValue(args, nameof(args)); h.Check(args.EstimatedSampleFraction > 0); - data = data.Take(MaxRowsToRead); + data = data.Take(MaxRowsToRead, env); // Infer column purposes from data sample. var piArgs = new PurposeInference.Arguments { MaxRowsToRead = MaxRowsToRead }; diff --git a/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs b/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs index 09f694d71f..0d6698351f 100644 --- a/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs +++ b/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs @@ -39,10 +39,10 @@ public void PipelineSweeperBasic() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTrain }).Data.Take(numOfSampleRows, Env); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTest }).Data.Take(numOfSampleRows, Env); #pragma warning restore 0618 // Define entrypoint graph string inputGraph = @" @@ -115,10 +115,10 @@ public void PipelineSweeperNoTransforms() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); #pragma warning restore 0618 const int batchSize = 5; const int numIterations = 20; @@ -176,10 +176,10 @@ public void PipelineSweeperSerialization() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); #pragma warning restore 0618 // Define entrypoint graph @@ -249,10 +249,10 @@ public void PipelineSweeperRoles() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); #pragma warning restore 0618 // Define entrypoint graph @@ -422,10 +422,10 @@ public void PipelineSweeperRocketEngine() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); #pragma warning restore 0618 // Define entrypoint graph string inputGraph = @" @@ -501,10 +501,10 @@ public void PipelineSweeperRequestedLearners() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows); + new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); var requestedLearners = new[] { $"LogisticRegressionBinaryClassifier", $"FastTreeBinaryClassifier" }; #pragma warning restore 0618 // Define entrypoint graph From 65325c5283ab598b2117c2e42bcc7b58f90fe666 Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 28 Sep 2018 08:43:02 -0500 Subject: [PATCH 6/7] Don't allow TestAutoInference and TestPipelineSweeper to run at the same time. --- test/Microsoft.ML.Predictor.Tests/TestAutoInference.cs | 1 + test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/test/Microsoft.ML.Predictor.Tests/TestAutoInference.cs b/test/Microsoft.ML.Predictor.Tests/TestAutoInference.cs index 9d0af99420..8face5f7bf 100644 --- a/test/Microsoft.ML.Predictor.Tests/TestAutoInference.cs +++ b/test/Microsoft.ML.Predictor.Tests/TestAutoInference.cs @@ -16,6 +16,7 @@ namespace Microsoft.ML.Runtime.RunTests { + [Collection("TestPipelineSweeper and TestAutoInference should not be run at the same time")] public sealed class TestAutoInference : BaseTestBaseline { public TestAutoInference(ITestOutputHelper helper) diff --git a/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs b/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs index 0d6698351f..578dd81e8e 100644 --- a/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs +++ b/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs @@ -15,6 +15,7 @@ namespace Microsoft.ML.Runtime.RunTests { + [Collection("TestPipelineSweeper and TestAutoInference should not be run at the same time")] public sealed class TestPipelineSweeper : BaseTestBaseline { public TestPipelineSweeper(ITestOutputHelper helper) From 9cdc07910a2e1945d1d2de8f5f79245b43a309fc Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 28 Sep 2018 17:34:33 -0500 Subject: [PATCH 7/7] clean up the code --- .../AutoInference.cs | 6 ++-- .../ColumnTypeInference.cs | 20 +++++------ .../InferenceUtils.cs | 11 ++++-- .../PurposeInference.cs | 4 +-- .../RecipeInference.cs | 4 +-- .../TextFileContents.cs | 2 +- .../TransformInference.cs | 6 ++-- test/Microsoft.ML.Predictor.Tests/Global.cs | 8 +++-- .../TestAutoInference.cs | 2 +- .../TestPipelineSweeper.cs | 26 +++++++------- .../BaseTestBaseline.cs | 2 +- .../BaseTestClass.cs | 1 + test/Microsoft.ML.TestFramework/GlobalBase.cs | 36 ------------------- .../Microsoft.ML.TestFramework.csproj | 2 -- 14 files changed, 51 insertions(+), 79 deletions(-) diff --git a/src/Microsoft.ML.PipelineInference/AutoInference.cs b/src/Microsoft.ML.PipelineInference/AutoInference.cs index 852efb05de..54e95e595d 100644 --- a/src/Microsoft.ML.PipelineInference/AutoInference.cs +++ b/src/Microsoft.ML.PipelineInference/AutoInference.cs @@ -235,7 +235,7 @@ private void ProcessPipeline(Sweeper.Algorithms.SweeperProbabilityUtils utils, S // Run pipeline, and time how long it takes stopwatch.Restart(); - candidate.RunTrainTestExperiment(_trainData.Take(randomizedNumberOfRows, _env), + candidate.RunTrainTestExperiment(_trainData.Take(randomizedNumberOfRows), _testData, Metric, TrainerKind, out var testMetricVal, out var trainMetricVal); stopwatch.Stop(); @@ -500,7 +500,7 @@ public static AutoMlMlState InferPipelines(IHostEnvironment env, PipelineOptimiz #pragma warning restore 0618 var splitOutput = TrainTestSplit.Split(env, new TrainTestSplit.Input { Data = data, Fraction = 0.8f }); AutoMlMlState amls = new AutoMlMlState(env, metric, autoMlEngine, terminator, trainerKind, - splitOutput.TrainData.Take(numOfSampleRows, env), splitOutput.TestData.Take(numOfSampleRows, env)); + splitOutput.TrainData.Take(numOfSampleRows), splitOutput.TestData.Take(numOfSampleRows)); bestPipeline = amls.InferPipelines(numTransformLevels, batchSize, numOfSampleRows); return amls; } @@ -514,7 +514,7 @@ public static AutoMlMlState InferPipelines(IHostEnvironment env, PipelineOptimiz var splitOutput = TrainTestSplit.Split(env, new TrainTestSplit.Input { Data = data, Fraction = 0.8f }); AutoMlMlState amls = new AutoMlMlState(env, metric, autoMlEngine, terminator, trainerKind, - splitOutput.TrainData.Take(numOfSampleRows, env), splitOutput.TestData.Take(numOfSampleRows, env)); + splitOutput.TrainData.Take(numOfSampleRows), splitOutput.TestData.Take(numOfSampleRows)); bestPipeline = amls.InferPipelines(numTransformLevels, batchSize, numOfSampleRows); return amls; } diff --git a/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs b/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs index d553dfae1f..03aca5c19b 100644 --- a/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs +++ b/src/Microsoft.ML.PipelineInference/ColumnTypeInference.cs @@ -132,10 +132,10 @@ public void Apply(IntermediateColumn[] columns) { if (!col.RawData.Skip(1) .All(x => - { - bool value; - return Conversions.Instance.TryParse(ref x, out value); - }) + { + bool value; + return Conversions.Instance.TryParse(ref x, out value); + }) ) { continue; @@ -157,10 +157,10 @@ public void Apply(IntermediateColumn[] columns) { if (!col.RawData.Skip(1) .All(x => - { - Single value; - return Conversions.Instance.TryParse(ref x, out value); - }) + { + Single value; + return Conversions.Instance.TryParse(ref x, out value); + }) ) { continue; @@ -240,7 +240,7 @@ private static InferenceResult InferTextFileColumnTypesCore(IHostEnvironment env ch.AssertValue(fileSource); ch.AssertValue(args); - if (args.ColumnCount==0) + if (args.ColumnCount == 0) { ch.Error("Too many empty columns for automatic inference."); return InferenceResult.Fail(); @@ -261,7 +261,7 @@ private static InferenceResult InferTextFileColumnTypesCore(IHostEnvironment env AllowQuoting = args.AllowQuote, }; var idv = TextLoader.ReadFile(env, textLoaderArgs, fileSource); - idv = idv.Take(args.MaxRowsToRead, env); + idv = idv.Take(args.MaxRowsToRead); // Read all the data into memory. // List items are rows of the dataset. diff --git a/src/Microsoft.ML.PipelineInference/InferenceUtils.cs b/src/Microsoft.ML.PipelineInference/InferenceUtils.cs index 320a1c81ea..478e732b9f 100644 --- a/src/Microsoft.ML.PipelineInference/InferenceUtils.cs +++ b/src/Microsoft.ML.PipelineInference/InferenceUtils.cs @@ -5,16 +5,21 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; +using Microsoft.ML.Runtime; using Microsoft.ML.Runtime.Data; +using Microsoft.ML.Runtime.Data.Conversion; using Microsoft.ML.Runtime.Internal.Utilities; namespace Microsoft.ML.Runtime.PipelineInference { public static class InferenceUtils { - public static IDataView Take(this IDataView data, int count, IHostEnvironment env) + public static IDataView Take(this IDataView data, int count) { Contracts.CheckValue(data, nameof(data)); + // REVIEW: This should take an env as a parameter, not create one. + var env = new ConsoleEnvironment(0); var take = SkipTakeFilter.Create(env, new SkipTakeFilter.TakeArguments { Count = count }, data); return CacheCore(take, env); } @@ -33,7 +38,7 @@ private static IDataView CacheCore(IDataView data, IHostEnvironment env) return new CacheDataView(env, data, Utils.GetIdentityPermutation(data.Schema.ColumnCount)); } - public static Type InferPredictorCategoryType(IDataView data, PurposeInference.Column[] columns, IHostEnvironment env) + public static Type InferPredictorCategoryType(IDataView data, PurposeInference.Column[] columns) { List labels = columns.Where(col => col.Purpose == ColumnPurpose.Label).ToList(); if (labels.Count == 0) @@ -44,7 +49,7 @@ public static Type InferPredictorCategoryType(IDataView data, PurposeInference.C PurposeInference.Column label = labels.First(); HashSet uniqueLabelValues = new HashSet(); - data = data.Take(1000, env); + data = data.Take(1000); using (var cursor = data.GetRowCursor(index => index == label.ColumnIndex)) { ValueGetter> getter = DataViewUtils.PopulateGetterArray(cursor, new List { label.ColumnIndex })[0]; diff --git a/src/Microsoft.ML.PipelineInference/PurposeInference.cs b/src/Microsoft.ML.PipelineInference/PurposeInference.cs index e5a6482bfe..7ea19127a4 100644 --- a/src/Microsoft.ML.PipelineInference/PurposeInference.cs +++ b/src/Microsoft.ML.PipelineInference/PurposeInference.cs @@ -332,14 +332,14 @@ public static InferenceResult InferPurposes(IHostEnvironment env, IDataView data InferenceResult result; using (var ch = host.Start("InferPurposes")) { - var takenData = data.Take(args.MaxRowsToRead, env); + var takenData = data.Take(args.MaxRowsToRead); var cols = columnIndices.Select(x => new IntermediateColumn(takenData, x)).ToList(); data = takenData; if (dataRoles != null) { var items = dataRoles.Schema.GetColumnRoles(); - foreach(var item in items) + foreach (var item in items) { Enum.TryParse(item.Key.Value, out ColumnPurpose purpose); var col = cols.Find(x => x.ColumnName == item.Value.Name); diff --git a/src/Microsoft.ML.PipelineInference/RecipeInference.cs b/src/Microsoft.ML.PipelineInference/RecipeInference.cs index 39d36a929f..65c44c6c6e 100644 --- a/src/Microsoft.ML.PipelineInference/RecipeInference.cs +++ b/src/Microsoft.ML.PipelineInference/RecipeInference.cs @@ -449,7 +449,7 @@ public static SuggestedRecipe[] InferRecipesFromData(IHostEnvironment env, strin ExcludeFeaturesConcatTransforms = excludeFeaturesConcatTransforms } ); - predictorType = InferenceUtils.InferPredictorCategoryType(cached, purposeColumns, env); + predictorType = InferenceUtils.InferPredictorCategoryType(cached, purposeColumns); var recipeInferenceResult = InferRecipes(h, transformInferenceResult, predictorType); ch.Done(); @@ -547,7 +547,7 @@ public static SuggestedRecipe.SuggestedLearner[] AllowedLearners(IHostEnvironmen LearnerName = tt.Name }; - if (sl.PipelineNode != null && availableLearnersList.FirstOrDefault(l=> l.Name.Equals(sl.PipelineNode.GetEpName())) != null) + if (sl.PipelineNode != null && availableLearnersList.FirstOrDefault(l => l.Name.Equals(sl.PipelineNode.GetEpName())) != null) learners.Add(sl); } diff --git a/src/Microsoft.ML.PipelineInference/TextFileContents.cs b/src/Microsoft.ML.PipelineInference/TextFileContents.cs index 167fe536e7..2ba5e23d0b 100644 --- a/src/Microsoft.ML.PipelineInference/TextFileContents.cs +++ b/src/Microsoft.ML.PipelineInference/TextFileContents.cs @@ -123,7 +123,7 @@ private static bool TryParseFile(IChannel ch, TextLoader.Arguments args, IMultiS { messages.Add(msg); }); - var idv = TextLoader.ReadFile(loaderEnv, args, source).Take(1000, loaderEnv); + var idv = TextLoader.ReadFile(loaderEnv, args, source).Take(1000); var columnCounts = new List(); int columnIndex; bool found = idv.Schema.TryGetColumnIndex("C", out columnIndex); diff --git a/src/Microsoft.ML.PipelineInference/TransformInference.cs b/src/Microsoft.ML.PipelineInference/TransformInference.cs index 3f0cfaf6d6..2eca74ed5c 100644 --- a/src/Microsoft.ML.PipelineInference/TransformInference.cs +++ b/src/Microsoft.ML.PipelineInference/TransformInference.cs @@ -1539,7 +1539,7 @@ public static InferenceResult InferTransforms(IHostEnvironment env, IDataView da h.CheckValue(args, nameof(args)); h.Check(args.EstimatedSampleFraction > 0); - data = data.Take(MaxRowsToRead, env); + data = data.Take(MaxRowsToRead); var cols = purposes.Where(x => !data.Schema.IsHidden(x.ColumnIndex)).Select(x => new IntermediateColumn(data, x)).ToArray(); using (var rootCh = h.Start("InferTransforms")) { @@ -1587,7 +1587,7 @@ public static SuggestedTransform[] InferTransforms(IHostEnvironment env, IDataVi var availableTransforms = env.ComponentCatalog.AllEntryPoints() .Where(x => x.InputKinds?.FirstOrDefault(i => i == typeof(CommonInputs.ITransformInput)) != null && x.InputKinds?.Any(i => i == typeof(CommonInputs.ICalibratorInput)) != true); - var dataSample = data.Take(MaxRowsToRead, env); + var dataSample = data.Take(MaxRowsToRead); // Infer column purposes from data sample. var piArgs = new PurposeInference.Arguments { MaxRowsToRead = MaxRowsToRead }; @@ -1619,7 +1619,7 @@ public static SuggestedTransform[] InferConcatNumericFeatures(IHostEnvironment e h.CheckValue(args, nameof(args)); h.Check(args.EstimatedSampleFraction > 0); - data = data.Take(MaxRowsToRead, env); + data = data.Take(MaxRowsToRead); // Infer column purposes from data sample. var piArgs = new PurposeInference.Arguments { MaxRowsToRead = MaxRowsToRead }; diff --git a/test/Microsoft.ML.Predictor.Tests/Global.cs b/test/Microsoft.ML.Predictor.Tests/Global.cs index 39f92e9762..af4292e6a9 100644 --- a/test/Microsoft.ML.Predictor.Tests/Global.cs +++ b/test/Microsoft.ML.Predictor.Tests/Global.cs @@ -2,12 +2,16 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.ML.Runtime.Internal.Internallearn.Test; using Xunit; -namespace Microsoft.ML.Runtime.Internal.Internallearn.Test +namespace Microsoft.ML.Runtime.RunTests { - public sealed class GlobalRT + public sealed class Global { + // See https://github.com/dotnet/machinelearning/issues/1095 + public const string AutoInferenceAndPipelineSweeperTestCollectionName = "TestPipelineSweeper and TestAutoInference should not be run at the same time since it causes deadlocks"; + [Fact(Skip = "Disabled")] public void AssertHandlerTest() { diff --git a/test/Microsoft.ML.Predictor.Tests/TestAutoInference.cs b/test/Microsoft.ML.Predictor.Tests/TestAutoInference.cs index 8face5f7bf..6a6a9409ef 100644 --- a/test/Microsoft.ML.Predictor.Tests/TestAutoInference.cs +++ b/test/Microsoft.ML.Predictor.Tests/TestAutoInference.cs @@ -16,7 +16,7 @@ namespace Microsoft.ML.Runtime.RunTests { - [Collection("TestPipelineSweeper and TestAutoInference should not be run at the same time")] + [Collection(Global.AutoInferenceAndPipelineSweeperTestCollectionName)] public sealed class TestAutoInference : BaseTestBaseline { public TestAutoInference(ITestOutputHelper helper) diff --git a/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs b/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs index 578dd81e8e..f5a527a91e 100644 --- a/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs +++ b/test/Microsoft.ML.Predictor.Tests/TestPipelineSweeper.cs @@ -15,7 +15,7 @@ namespace Microsoft.ML.Runtime.RunTests { - [Collection("TestPipelineSweeper and TestAutoInference should not be run at the same time")] + [Collection(Global.AutoInferenceAndPipelineSweeperTestCollectionName)] public sealed class TestPipelineSweeper : BaseTestBaseline { public TestPipelineSweeper(ITestOutputHelper helper) @@ -40,10 +40,10 @@ public void PipelineSweeperBasic() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTrain }).Data.Take(numOfSampleRows); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTest }).Data.Take(numOfSampleRows); #pragma warning restore 0618 // Define entrypoint graph string inputGraph = @" @@ -116,10 +116,10 @@ public void PipelineSweeperNoTransforms() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows); #pragma warning restore 0618 const int batchSize = 5; const int numIterations = 20; @@ -177,10 +177,10 @@ public void PipelineSweeperSerialization() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows); #pragma warning restore 0618 // Define entrypoint graph @@ -250,10 +250,10 @@ public void PipelineSweeperRoles() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows); #pragma warning restore 0618 // Define entrypoint graph @@ -423,10 +423,10 @@ public void PipelineSweeperRocketEngine() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows); #pragma warning restore 0618 // Define entrypoint graph string inputGraph = @" @@ -502,10 +502,10 @@ public void PipelineSweeperRequestedLearners() var inputFileTrain = new SimpleFileHandle(Env, pathData, false, false); #pragma warning disable 0618 var datasetTrain = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTrain, CustomSchema = schema }).Data.Take(numOfSampleRows); var inputFileTest = new SimpleFileHandle(Env, pathDataTest, false, false); var datasetTest = ImportTextData.ImportText(Env, - new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows, Env); + new ImportTextData.Input { InputFile = inputFileTest, CustomSchema = schema }).Data.Take(numOfSampleRows); var requestedLearners = new[] { $"LogisticRegressionBinaryClassifier", $"FastTreeBinaryClassifier" }; #pragma warning restore 0618 // Define entrypoint graph diff --git a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs index 6cfcc16876..ad077a85d3 100644 --- a/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs +++ b/test/Microsoft.ML.TestFramework/BaseTestBaseline.cs @@ -21,7 +21,7 @@ namespace Microsoft.ML.Runtime.RunTests /// /// This is a base test class designed to support baseline comparison. /// - public abstract partial class BaseTestBaseline : BaseTestClass, IDisposable + public abstract partial class BaseTestBaseline : BaseTestClass { public const decimal Tolerance = 10_000_000; diff --git a/test/Microsoft.ML.TestFramework/BaseTestClass.cs b/test/Microsoft.ML.TestFramework/BaseTestClass.cs index cdeeabf864..034565592e 100644 --- a/test/Microsoft.ML.TestFramework/BaseTestClass.cs +++ b/test/Microsoft.ML.TestFramework/BaseTestClass.cs @@ -41,6 +41,7 @@ public BaseTestClass(ITestOutputHelper output) FullTestName = test.TestCase.TestMethod.TestClass.Class.Name + "." + test.TestCase.TestMethod.Method.Name; TestName = test.TestCase.TestMethod.Method.Name; + // write to the console when a test starts and stops so we can identify any test hangs/deadlocks in CI Console.WriteLine($"Starting test: {FullTestName}"); Initialize(); } diff --git a/test/Microsoft.ML.TestFramework/GlobalBase.cs b/test/Microsoft.ML.TestFramework/GlobalBase.cs index 79639bb0d6..ecb185b625 100644 --- a/test/Microsoft.ML.TestFramework/GlobalBase.cs +++ b/test/Microsoft.ML.TestFramework/GlobalBase.cs @@ -11,7 +11,6 @@ // } using System; -using System.Management; using System.Runtime.InteropServices; using Xunit; @@ -28,41 +27,6 @@ public static void AssemblyInit() // HACK: ensure MklImports is loaded very early in the tests so it doesn't deadlock while loading it later. // See https://github.com/dotnet/machinelearning/issues/1073 Mkl.PptrfInternal(Mkl.Layout.RowMajor, Mkl.UpLo.Up, 0, Array.Empty()); - - PrintCpuInfo(); - } - - private static void PrintCpuInfo() - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - ManagementClass clsMgtClass = new ManagementClass("Win32_Processor"); - ManagementObjectCollection colMgtObjCol = clsMgtClass.GetInstances(); - - foreach (ManagementObject objMgtObj in colMgtObjCol) - { - foreach (var property in objMgtObj.Properties) - { - Console.WriteLine("CPU Property " + property.Name + " = " + property.Value); - - } - } - - double totalCapacity = 0; - ObjectQuery objectQuery = new ObjectQuery("select * from Win32_PhysicalMemory"); - ManagementObjectSearcher searcher = new ManagementObjectSearcher(objectQuery); - ManagementObjectCollection vals = searcher.Get(); - - foreach (ManagementObject val in vals) - { - totalCapacity += System.Convert.ToDouble(val.GetPropertyValue("Capacity")); - } - - Console.WriteLine("Total Machine Memory = " + totalCapacity.ToString() + " Bytes"); - Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1024) + " KiloBytes"); - Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1048576) + " MegaBytes"); - Console.WriteLine("Total Machine Memory = " + (totalCapacity / 1073741824) + " GigaBytes"); - } } private static class Mkl diff --git a/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj b/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj index 248012cef2..b191c08a91 100644 --- a/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj +++ b/test/Microsoft.ML.TestFramework/Microsoft.ML.TestFramework.csproj @@ -16,8 +16,6 @@ - -