Skip to content

fix tensorflow test hanging issue #4997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
take comments
  • Loading branch information
frank-dong-ms-zz committed Apr 3, 2020
commit 0f8668f37837cb945ce3dfcfcdc65db9647a0f1c
18 changes: 10 additions & 8 deletions src/Microsoft.ML.Core/Utilities/ResourceManagerUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,18 @@ private Exception DownloadResource(IHostEnvironment env, IChannel ch, WebClient
var buffer = new byte[blockSize];
long total = 0;

var task = s.ReadAsync(buffer, 0, blockSize);
task.Wait(ct);
int count = task.Result;
// REVIEW: use a progress channel instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you need to check the result after the first call, you can change the loop to a do{} loop instead of a while() loop. If you still want to have a while loop, you can change the loop to a while(true) loop and move this inside the while loop. In either case you won't need to have these three lines repeated twice.

while (count > 0)
while (true)
{
var task = s.ReadAsync(buffer, 0, blockSize, ct);
task.Wait();
int count = task.Result;

if(count <= 0)
{
break;
}

ws.Write(buffer, 0, count);
total += count;
if ((total - (total / printFreq) * printFreq) <= blockSize)
Expand All @@ -296,10 +302,6 @@ private Exception DownloadResource(IHostEnvironment env, IChannel ch, WebClient
ch.Error($"{fileName}: Download timed out");
return ch.Except("Download timed out");
}

task = s.ReadAsync(buffer, 0, blockSize);
task.Wait(ct);
count = task.Result;
}
}
File.Move(tempPath, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public TestResourceDownload(ITestOutputHelper helper)
public async Task TestDownloadError()
{
var envVarOld = Environment.GetEnvironmentVariable(ResourceManagerUtils.CustomResourcesUrlEnvVariable);
var timeoutVarOld = Environment.GetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable);
var resourcePathVarOld = Environment.GetEnvironmentVariable(Utils.CustomSearchDirEnvVariable);
Environment.SetEnvironmentVariable(Utils.CustomSearchDirEnvVariable, null);

Expand Down Expand Up @@ -134,7 +133,6 @@ public async Task TestDownloadError()
{
// Set environment variable back to its old value.
Environment.SetEnvironmentVariable(ResourceManagerUtils.CustomResourcesUrlEnvVariable, envVarOld);
Environment.SetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable, timeoutVarOld);
Environment.SetEnvironmentVariable(Utils.CustomSearchDirEnvVariable, resourcePathVarOld);
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/Microsoft.ML.TestFramework/BaseTestClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System.Threading;
using Microsoft.ML.Internal.Internallearn.Test;
using Microsoft.ML.Internal.Utilities;
using Microsoft.ML.Runtime;
using Microsoft.ML.TestFrameworkCommon;
using Microsoft.ML.TestFrameworkCommon.Attributes;
Expand Down Expand Up @@ -79,16 +80,23 @@ void IDisposable.Dispose()

protected virtual void Initialize()
{
// set timeout to 3 minutes, download sometimes will stuck so set smaller timeout to fail fast and retry download
_timeOutOldValue = Environment.GetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable);
Environment.SetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable, (3 * 60 * 1000).ToString());
}

protected virtual void Cleanup()
{
// set back timeout value
Environment.SetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable, _timeOutOldValue);
}

protected static string RootDir { get; }
protected string OutDir { get; }
protected static string DataDir { get; }

private string _timeOutOldValue;

protected ITestOutputHelper Output { get; }

public static string GetDataPath(string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1265,10 +1265,6 @@ public void TensorFlowStringTest()
[TensorFlowFact]
public void TensorFlowImageClassificationDefault()
{
// set timeout to 3 minutes, download sometimes will stuck so set smaller timeout to retry download
string timoOutOldValue = Environment.GetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable);
Environment.SetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable, (3 * 60 * 1000).ToString());

MLContext mlContext = new MLContext(seed: 1);

//Load all the original images info
Expand Down Expand Up @@ -1312,9 +1308,6 @@ public void TensorFlowImageClassificationDefault()
Assert.InRange(metrics.MacroAccuracy, 0.8, 1);

(loadedModel as IDisposable)?.Dispose();

// set back timeout value
Environment.SetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable, timoOutOldValue);
}

internal bool ShouldReuse(string workspacePath, string trainSetBottleneckCachedValuesFileName, string validationSetBottleneckCachedValuesFileName)
Expand Down Expand Up @@ -1348,10 +1341,6 @@ internal bool ShouldReuse(string workspacePath, string trainSetBottleneckCachedV
[InlineData(ImageClassificationTrainer.Architecture.InceptionV3)]
public void TensorFlowImageClassification(ImageClassificationTrainer.Architecture arch)
{
// set timeout to 3 minutes, download sometimes will stuck so set smaller timeout to retry download
string timoOutOldValue = Environment.GetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable);
Environment.SetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable, (3 * 60 * 1000).ToString());

MLContext mlContext = new MLContext(seed: 1);

//Load all the original images info
Expand Down Expand Up @@ -1469,9 +1458,6 @@ public void TensorFlowImageClassification(ImageClassificationTrainer.Architectur
Assert.True(Array.IndexOf(labels, predictionSecond.PredictedLabel) > -1);

(loadedModel as IDisposable)?.Dispose();

// set back timeout value
Environment.SetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable, timoOutOldValue);
}

[TensorFlowFact]
Expand Down Expand Up @@ -1619,10 +1605,6 @@ internal void TensorFlowImageClassificationWithLRScheduling(LearningRateSchedule
[InlineData(ImageClassificationTrainer.EarlyStoppingMetric.Loss)]
public void TensorFlowImageClassificationEarlyStopping(ImageClassificationTrainer.EarlyStoppingMetric earlyStoppingMetric)
{
// set timeout to 3 minutes, download sometimes will stuck so set smaller timeout to retry download
string timoOutOldValue = Environment.GetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable);
Environment.SetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable, (3 * 60 * 1000).ToString());

MLContext mlContext = new MLContext(seed: 1);

//Load all the original images info
Expand Down Expand Up @@ -1699,9 +1681,6 @@ public void TensorFlowImageClassificationEarlyStopping(ImageClassificationTraine
Assert.InRange(lastEpoch, 1, 49);

(loadedModel as IDisposable)?.Dispose();

// set back timeout value
Environment.SetEnvironmentVariable(ResourceManagerUtils.TimeoutEnvVariable, timoOutOldValue);
}

[TensorFlowFact]
Expand Down