From ed4bbd40aa42f058cdce44ff44266843c4e3a833 Mon Sep 17 00:00:00 2001 From: Matteo Interlandi Date: Mon, 5 Aug 2019 21:44:05 -0700 Subject: [PATCH 1/5] fix test errors in unix machines --- test/Microsoft.ML.Tests/Torch/TorchTests.cs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/test/Microsoft.ML.Tests/Torch/TorchTests.cs b/test/Microsoft.ML.Tests/Torch/TorchTests.cs index 2112a2bcf8..a1967c53fd 100644 --- a/test/Microsoft.ML.Tests/Torch/TorchTests.cs +++ b/test/Microsoft.ML.Tests/Torch/TorchTests.cs @@ -40,10 +40,13 @@ public void TorchScoringReLUTest() .Fit(dataView) .Transform(dataView); - var transformedData = mlContext.Data.CreateEnumerable(output, false).ToArray()[0].Features; - Assert.True(transformedData.Length == 5); - Assert.Equal(transformedData, new float[] { 0, 0, 0, 1, 1 }); - + var transformedData = mlContext.Data.CreateEnumerable(output, false).ToArray()[0].Features; + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.Is64BitProcess) + { + Assert.True(transformedData.Length == 5); + Assert.Equal(transformedData, new float[] { 0, 0, 0, 1, 1 }); + } } [TorchFact] @@ -68,9 +71,13 @@ public void TorchTransformerWorkoutTest() .Transform(dataView); var transformedData = mlContext.Data.CreateEnumerable(output, false).ToArray()[0].Features; - Assert.True(transformedData.Length == 5); - foreach (var elt in transformedData) - Assert.True(elt >= 0); + + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.Is64BitProcess) + { + Assert.True(transformedData.Length == 5); + foreach (var elt in transformedData) + Assert.True(elt >= 0); + } } } } From f684e68c83d83b3e0595341f380ec1efca191043 Mon Sep 17 00:00:00 2001 From: Matteo Interlandi Date: Mon, 5 Aug 2019 22:02:52 -0700 Subject: [PATCH 2/5] Update TorchTests.cs add missing include --- test/Microsoft.ML.Tests/Torch/TorchTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.ML.Tests/Torch/TorchTests.cs b/test/Microsoft.ML.Tests/Torch/TorchTests.cs index a1967c53fd..201071b819 100644 --- a/test/Microsoft.ML.Tests/Torch/TorchTests.cs +++ b/test/Microsoft.ML.Tests/Torch/TorchTests.cs @@ -2,6 +2,7 @@ using System.Linq; using Microsoft.ML.Data; using Microsoft.ML.RunTests; +using Microsoft.ML.Runtime; using Microsoft.ML.TestFramework.Attributes; using TorchSharp.Tensor; using Xunit; From f75a966e7fc0237a4119dc575ef5cd87662d226e Mon Sep 17 00:00:00 2001 From: Matteo Interlandi Date: Mon, 5 Aug 2019 22:27:28 -0700 Subject: [PATCH 3/5] Update TorchTests.cs adding the right include --- test/Microsoft.ML.Tests/Torch/TorchTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.ML.Tests/Torch/TorchTests.cs b/test/Microsoft.ML.Tests/Torch/TorchTests.cs index 201071b819..3158c3b52e 100644 --- a/test/Microsoft.ML.Tests/Torch/TorchTests.cs +++ b/test/Microsoft.ML.Tests/Torch/TorchTests.cs @@ -1,8 +1,8 @@ using System.Collections.Generic; using System.Linq; +using System.Runtime.InteropServices; using Microsoft.ML.Data; using Microsoft.ML.RunTests; -using Microsoft.ML.Runtime; using Microsoft.ML.TestFramework.Attributes; using TorchSharp.Tensor; using Xunit; From 013b58e48e9e2dd58ce4bcf700ad86996990f2ee Mon Sep 17 00:00:00 2001 From: Matteo Interlandi Date: Mon, 5 Aug 2019 22:28:58 -0700 Subject: [PATCH 4/5] Update TorchTests.cs Last missing include --- test/Microsoft.ML.Tests/Torch/TorchTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.ML.Tests/Torch/TorchTests.cs b/test/Microsoft.ML.Tests/Torch/TorchTests.cs index 3158c3b52e..1aad49c351 100644 --- a/test/Microsoft.ML.Tests/Torch/TorchTests.cs +++ b/test/Microsoft.ML.Tests/Torch/TorchTests.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using Microsoft.ML.Data; From dd8f81c35fcd043184f8612ffb018bbda9da86c1 Mon Sep 17 00:00:00 2001 From: Matteo Interlandi Date: Mon, 5 Aug 2019 23:18:25 -0700 Subject: [PATCH 5/5] Update TorchTests.cs Run tests only in windows --- test/Microsoft.ML.Tests/Torch/TorchTests.cs | 62 ++++++++++----------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/test/Microsoft.ML.Tests/Torch/TorchTests.cs b/test/Microsoft.ML.Tests/Torch/TorchTests.cs index 1aad49c351..8cc117b8c3 100644 --- a/test/Microsoft.ML.Tests/Torch/TorchTests.cs +++ b/test/Microsoft.ML.Tests/Torch/TorchTests.cs @@ -26,26 +26,26 @@ private class TestReLUModelData [TorchFact] public void TorchScoringReLUTest() { - var mlContext = new MLContext(); - var tensor = new float[] { -1, -1, 0, 1, 1 }.ToTorchTensor(dimensions: new long[] { 5 }); - var data = new TestReLUModelData + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - Features = tensor.Data().ToArray() - }; - var dataPoint = new List() { data }; + var mlContext = new MLContext(); + var tensor = new float[] { -1, -1, 0, 1, 1 }.ToTorchTensor(dimensions: new long[] { 5 }); + var data = new TestReLUModelData + { + Features = tensor.Data().ToArray() + }; + var dataPoint = new List() { data }; - var dataView = mlContext.Data.LoadFromEnumerable(dataPoint); + var dataView = mlContext.Data.LoadFromEnumerable(dataPoint); - var output = mlContext.Model - .LoadTorchModel(GetDataPath("Torch/relu.pt")) - .ScoreTorchModel("Features", new long[] { 5 }) - .Fit(dataView) - .Transform(dataView); + var output = mlContext.Model + .LoadTorchModel(GetDataPath("Torch/relu.pt")) + .ScoreTorchModel("Features", new long[] { 5 }) + .Fit(dataView) + .Transform(dataView); + + var transformedData = mlContext.Data.CreateEnumerable(output, false).ToArray()[0].Features; - var transformedData = mlContext.Data.CreateEnumerable(output, false).ToArray()[0].Features; - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.Is64BitProcess) - { Assert.True(transformedData.Length == 5); Assert.Equal(transformedData, new float[] { 0, 0, 0, 1, 1 }); } @@ -54,28 +54,28 @@ public void TorchScoringReLUTest() [TorchFact] public void TorchTransformerWorkoutTest() { - var mlContext = new MLContext(); - var tensorData = FloatTensor.Random(new long[] { 5 }); - var datapoint = new TestReLUModelData + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - Features = tensorData.Data().ToArray() - }; - var data = new List() { datapoint, datapoint, datapoint, datapoint, datapoint }; + var mlContext = new MLContext(); + var tensorData = FloatTensor.Random(new long[] { 5 }); + var datapoint = new TestReLUModelData + { + Features = tensorData.Data().ToArray() + }; + var data = new List() { datapoint, datapoint, datapoint, datapoint, datapoint }; - var dataView = mlContext.Data.LoadFromEnumerable(data); + var dataView = mlContext.Data.LoadFromEnumerable(data); - var estimator = mlContext.Model.LoadTorchModel(GetDataPath("Torch/relu.pt")) - .ScoreTorchModel("TorchOutput", new long[] { 5 }, "Features"); + var estimator = mlContext.Model.LoadTorchModel(GetDataPath("Torch/relu.pt")) + .ScoreTorchModel("TorchOutput", new long[] { 5 }, "Features"); - TestEstimatorCore(estimator, dataView); + TestEstimatorCore(estimator, dataView); - var output = estimator.Fit(dataView) - .Transform(dataView); + var output = estimator.Fit(dataView) + .Transform(dataView); - var transformedData = mlContext.Data.CreateEnumerable(output, false).ToArray()[0].Features; + var transformedData = mlContext.Data.CreateEnumerable(output, false).ToArray()[0].Features; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Environment.Is64BitProcess) - { Assert.True(transformedData.Length == 5); foreach (var elt in transformedData) Assert.True(elt >= 0);