Skip to content
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

Replace ConditionalFact usages with custom facts #2402

Merged
merged 6 commits into from
Feb 11, 2019

Conversation

mareklinka
Copy link
Contributor

@mareklinka mareklinka commented Feb 4, 2019

As proposed in #1220, this PR replaces all usages of ConditionalFact in tests with custom-tailored, environment-specific facts.

These specific facts all inherit from a single base EnvironmentSpecificFactAttribute. Several of the facts check the same condition (e.g. TensorFlow, Onnx, and X64 - they all simply check for X64 process) but I decided not to merge them - they might check the same thing now but I expect they might branch out later on. I consider the small duplication of code not worth the mental overhead of inheritance or composition here.

Together with this I also removed some now-obsolete checking of platform in Onnx-related tests (they were all Windows-only anyway) and removed the old OnnxFact.

Fixes #1220.

@mareklinka mareklinka force-pushed the feature/1220_ConditionalFactCleanup branch from e5e4ecb to f013125 Compare February 4, 2019 17:48
@mareklinka
Copy link
Contributor Author

Ok, so it seems I stumbled upon an interesting problem here. It seems tests marked with ConditionalAttribute were not running at all under full framework. Now that I migrated them to custom attributes, they are being run and fail.

Specifically, the failing Onnx tests are looking for the model files in the wrong directory. Debugging into it, this is the path is returned in the ResNet18 extension method:

C:\Users\Marek\AppData\Local\Temp\4e765c63-f6ab-4125-b0da-31d31f556eb7\4e765c63-f6ab-4125-b0da-31d31f556eb7\assembly\dl3\dd76d9c2\39935ac9_c0bcd401\DnnImageModels

This feels like some kind of shadow copy is going on here.

I'm still looking into the tensorflow and MacOS fail.

@mareklinka
Copy link
Contributor Author

mareklinka commented Feb 4, 2019

The TensorFlow failure seems to be of the same root cause - it was not running under full framework, now it runs. However, the directory Maml.MainWithProgress looks at is wrong:

C:\Users\Marek\AppData\Local\Temp\bd281e66-574e-4cfc-b712-1768a003416c\bd281e66-574e-4cfc-b712-1768a003416c\assembly\dl3\c6759ee3\bfbd336c_c7bcd401

I have half a mind to make EnvironmentSpecificFactAttribute always return false #if NETFRAMEWORK to emulate the old behavior (not running these tests on full framework). Disabling shadow copying might be an option here but I'm unfamiliar with the build setup so I don't know where to look.

Could someone point me in the right direction, @tannergooding, @eerhardt?

@eerhardt eerhardt requested a review from Anipik February 4, 2019 20:34
@eerhardt
Copy link
Member

eerhardt commented Feb 4, 2019

@Anipik has been looking in this same space. Adding him to comment.

@TomFinley
Copy link
Contributor

Yes. Also given the subject area (TensorFlow components) I would also invite @jignparm to possibly share his thoughts.

@Anipik
Copy link
Contributor

Anipik commented Feb 4, 2019

I have half a mind to make EnvironmentSpecificFactAttribute always return false #if NETFRAMEWORK to emulate the old behavior (not running these tests on full framework)

I would prefer to disable these (failing onnx test) tests just on fullFramework, using notFullFrameworkFact or NotFullFrameworkAndx64. As most of the tests are passing using conditional Fact are passing on fullFramework.

@Anipik
Copy link
Contributor

Anipik commented Feb 5, 2019

I am able to fix all the resnet failures in #2411

@mareklinka
Copy link
Contributor Author

Awesome news on the test fixes, @Anipik. I'll wait until your PRs are merged and then rebase my branch onto the latest master.

I did some small refactorings (e.g. bring the attribute class names in line and add AttributeUsage) and also replaced the usages of ConditionalTheory. The LessThanNetCore30OrNotNetCoreFactAttribute now requires a skip message so it's obvious at usage that this is something that's non-standard and should be fixed down the line.

@codecov
Copy link

codecov bot commented Feb 5, 2019

Codecov Report

Merging #2402 into master will increase coverage by <.01%.
The diff coverage is 94.33%.

@@            Coverage Diff             @@
##           master    #2402      +/-   ##
==========================================
+ Coverage   71.24%   71.24%   +<.01%     
==========================================
  Files         788      797       +9     
  Lines      141131   141162      +31     
  Branches    16115    16111       -4     
==========================================
+ Hits       100545   100572      +27     
- Misses      36121    36127       +6     
+ Partials     4465     4463       -2
Flag Coverage Δ
#Debug 71.24% <94.33%> (ø) ⬆️
#production 67.57% <ø> (ø) ⬆️
#test 85.35% <94.33%> (-0.01%) ⬇️

@mareklinka
Copy link
Contributor Author

mareklinka commented Feb 5, 2019

Now the Core 3.0 Debug intrinsics build failed. Looking into it, it tried to run the benchmarks in DEBUG build, which should not have happened - the BenchmarkTheoryAttribute uses the same #if directives as the original - it should skip #if DEBUG. It looks like the DEBUG constant was not emitted during compilation of the test project?

Copy link
Contributor

@Anipik Anipik left a comment

Choose a reason for hiding this comment

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

@@ -1313,7 +1314,7 @@ public void EntryPointMulticlassPipelineEnsemble()
}
}

[ConditionalFact(typeof(BaseTestBaseline), nameof(BaseTestBaseline.LessThanNetCore30OrNotNetCore))]
[LessThanNetCore30OrNotNetCoreFact("netcore3.0 output differs from Baseline")]
Copy link
Member

@eerhardt eerhardt Feb 7, 2019

Choose a reason for hiding this comment

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

netcore3.0 => netcoreapp3.0. We should use the real TFM here, so we don't confuse people.

Repeated for all uses.

@Anipik
Copy link
Contributor

Anipik commented Feb 8, 2019

@eerhardt I tried to debug the benchmarkTheory failure. For some reason Debug Constant is not working in this PR. I checked the Binlog and it is getting defined.

Property reassignment: $(DefineConstants)=";DEBUG;" (previous value: ";DEBUG") at C:\Program Files\dotnet\sdk\3.0.100-preview-010184\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.CSharp.props (22,5)

I tried adding it to the project as well but it didn't work. any suggestions why ?

@mareklinka
Copy link
Contributor Author

mareklinka commented Feb 8, 2019

can you also remove this https://github.com/dotnet/machinelearning/blob/master/test/Directory.Build.props#L32 ?

The issue with this is that that particular nuget also contains the definition of TestCategory. I can get rid of that but we would need to replace the TestCategory with XUnit's own Trait:

[TestCategory(Cat)]
[Fact(Skip = "Need CoreTLC specific baseline update")]
public void CommandCrossValidation()
{ ... }

would become

[Trait("Category", Cat)]
[Fact(Skip = "Need CoreTLC specific baseline update")]
public void CommandCrossValidation()
{ ... }

Alternatively, we could use the XUnit.Categories nuget and end up with something cleaner:

[Category(Cat)]
[Fact(Skip = "Need CoreTLC specific baseline update")]
public void CommandCrossValidation()
{ ... }

This nuget also contains some other useful attributes, like Feature, Bug, Work Item etc. What do you think, @Anipik, @eerhardt?

@eerhardt
Copy link
Member

eerhardt commented Feb 8, 2019

This nuget also contains some other useful attributes, like Feature, Bug, Work Item etc. What do you think, @Anipik, @eerhardt?

Let's keep using the Microsoft.DotNet.XUnitExtensions package. It still provides value.

@eerhardt
Copy link
Member

eerhardt commented Feb 8, 2019

I tried adding it to the project as well but it didn't work. any suggestions why ?

The #if DEBUG check is now happening in the Microsoft.ML.TestFramework project. Which means you have to look to see what defines are being used when building that project.

Looking at the .csproj, when we do things like this:

That will completely override anything that is set earlier in a .props file. The correct line here is:

<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>

But even better would be if we deleted this line from the .csproj all together and removed any dead code that is behind #if !CORECLR in this project.

@mareklinka
Copy link
Contributor Author

But even better would be if we deleted this line from the .csproj all together and removed any dead code that is behind #if !CORECLR in this project.

Sounds good. I'll take a look at this over the weekend, see what falls out. To clarify, we are talking specifically the Microsoft.ML.TestFramework project here, right?

@eerhardt
Copy link
Member

eerhardt commented Feb 8, 2019

To clarify, we are talking specifically the Microsoft.ML.TestFramework project here, right?

Yes. The DEBUG define is not working in that project apparently. Just that project needs to be fixed now. I'm sure others have the same problems, but let's only do this one for now.

@mareklinka mareklinka force-pushed the feature/1220_ConditionalFactCleanup branch from b1c8011 to bc7b87b Compare February 10, 2019 14:49
@@ -1096,23 +1096,6 @@ protected Func<bool> GetColumnComparer(Row r1, Row r2, int col, ColumnType type,
return GetComparerVec<RowId>(r1, r2, col, size, (x, y) => x.Equals(y));
}

#if !CORECLR // REVIEW: Port Picture type to CoreTLC.
if (type is PictureType)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this could have been ported from PictureType to ImageType, if I understand the problem correctly? Would require a reference to ImageAnalytics, though.

Copy link
Member

Choose a reason for hiding this comment

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

Currently we are only building the project with CORECLR defined. So this is dead code that can be deleted.

Let's just delete it for now. If @Ivanidzo4ka thinks this is important, we can open a new issue to add image support here. Thoughts @Ivanidzo4ka?

Copy link
Contributor

Choose a reason for hiding this comment

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

Feel free to delete. Some legacy code which we don't care about anymore

/// <summary>
/// A fact for tests requiring full .NET Framework.
/// </summary>
public sealed class NotFullFrameworkFactAttribute : EnvironmentSpecificFactAttribute
Copy link
Member

Choose a reason for hiding this comment

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

Is this used? I don't see any usages doing a simple search.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

Just one comment on a class that doesn't appear to be used. Other than that, this looks good. Thanks for tackling this - I think it really cleans the tests up nicely.

@mareklinka
Copy link
Contributor Author

Just one comment on a class that doesn't appear to be used. Other than that, this looks good. Thanks for tackling this - I think it really cleans the tests up nicely.

Got rid of the unused attribute. Glad to be of help 😄

Copy link
Contributor

@Anipik Anipik left a comment

Choose a reason for hiding this comment

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

LGTM

@Anipik Anipik merged commit 8444a5a into dotnet:master Feb 11, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants