Skip to content

Loading old model files is broken. #1290

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 2 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
40 changes: 30 additions & 10 deletions build/Dependencies.props
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
<Project>

<!-- Core Product Dependencies -->
<PropertyGroup>
<GoogleProtobufPackageVersion>3.5.1</GoogleProtobufPackageVersion>
<NewtonsoftJsonPackageVersion>10.0.3</NewtonsoftJsonPackageVersion>
<ParquetDotNetPackageVersion>2.1.3</ParquetDotNetPackageVersion>
<SystemThreadingTasksDataflowPackageVersion>4.8.0</SystemThreadingTasksDataflowPackageVersion>
<SystemCodeDomPackageVersion>4.4.0</SystemCodeDomPackageVersion>
<SystemCollectionsImmutableVersion>1.5.0</SystemCollectionsImmutableVersion>
<SystemMemoryVersion>4.5.1</SystemMemoryVersion>
<SystemReflectionEmitLightweightPackageVersion>4.3.0</SystemReflectionEmitLightweightPackageVersion>
<PublishSymbolsPackageVersion>1.0.0-beta-62824-02</PublishSymbolsPackageVersion>
<SystemThreadingTasksDataflowPackageVersion>4.8.0</SystemThreadingTasksDataflowPackageVersion>
</PropertyGroup>

<!-- Other/Non-Core Product Dependencies -->
<PropertyGroup>
<GoogleProtobufPackageVersion>3.5.1</GoogleProtobufPackageVersion>
<LightGBMPackageVersion>2.2.1.1</LightGBMPackageVersion>
<MicrosoftMLScoring>1.1.0</MicrosoftMLScoring>
<MlNetMklDepsPackageVersion>0.0.0.7</MlNetMklDepsPackageVersion>
<ParquetDotNetPackageVersion>2.1.3</ParquetDotNetPackageVersion>
<SystemDrawingCommonPackageVersion>4.5.0</SystemDrawingCommonPackageVersion>
<BenchmarkDotNetVersion>0.11.1</BenchmarkDotNetVersion>
<SystemIOFileSystemAccessControl>4.5.0</SystemIOFileSystemAccessControl>
<SystemSecurityPrincipalWindows>4.5.0</SystemSecurityPrincipalWindows>
<TensorFlowVersion>1.10.0</TensorFlowVersion>
<SystemCollectionsImmutableVersion>1.5.0</SystemCollectionsImmutableVersion>
<SystemMemoryVersion>4.5.1</SystemMemoryVersion>
</PropertyGroup>

<!-- Code Analyzer Dependencies -->
<PropertyGroup>
<MicrosoftCodeAnalysisCSharpVersion>2.9.0</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftCSharpVersion>4.5.0</MicrosoftCSharpVersion>
<SystemCompositionVersion>1.2.0</SystemCompositionVersion>
<MicrosoftMLScoring>1.1.0</MicrosoftMLScoring>
<SystemIOFileSystemAccessControl>4.5.0</SystemIOFileSystemAccessControl>
<SystemSecurityPrincipalWindows>4.5.0</SystemSecurityPrincipalWindows>
</PropertyGroup>

<!-- Build/infrastructure Dependencies -->
<PropertyGroup>
<PublishSymbolsPackageVersion>1.0.0-beta-62824-02</PublishSymbolsPackageVersion>
</PropertyGroup>

<!-- Test-only Dependencies -->
<PropertyGroup>
<BenchmarkDotNetVersion>0.11.1</BenchmarkDotNetVersion>
<MicrosoftMLTestModelsPackageVersion>0.0.2-test</MicrosoftMLTestModelsPackageVersion>
</PropertyGroup>

</Project>
12 changes: 12 additions & 0 deletions src/Microsoft.ML.Data/Model/ModelHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,18 @@ public static bool TryValidate(ref ModelHeader header, BinaryReader reader, long
{
// No strings.
strings = null;

if (header.VerWritten < VerAssemblyNameSupported)
{
// Before VerAssemblyNameSupported, if there were no strings in the model,
// validation ended here. Specifically the FpTail checks below were skipped.
// There are earlier versions of models that don't have strings, and 'reader' is
// not at FpTail at this point.
// Preserve the previous behavior by returning early here.
loaderAssemblyName = null;
ex = null;
return true;
}
}
else
{
Expand Down
8 changes: 6 additions & 2 deletions test/Microsoft.ML.Core.Tests/Microsoft.ML.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<DefineConstants>CORECLR</DefineConstants>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.ML.HalLearners\Microsoft.ML.HalLearners.csproj" />
<ProjectReference Include="..\..\src\Microsoft.ML.Api\Microsoft.ML.Api.csproj" />
Expand All @@ -22,7 +22,11 @@
<ProjectReference Include="..\..\src\Microsoft.ML.Legacy\Microsoft.ML.Legacy.csproj" />
<ProjectReference Include="..\Microsoft.ML.TestFramework\Microsoft.ML.TestFramework.csproj" />
<ProjectReference Include="..\Microsoft.ML.Tests\Microsoft.ML.Tests.csproj" />
<PackageReference Include="MlNetMklDeps" Version="$(MlNetMklDepsPackageVersion)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="MlNetMklDeps" Version="$(MlNetMklDepsPackageVersion)" />
<PackageReference Include="Microsoft.ML.TestModels" Version="$(MicrosoftMLTestModelsPackageVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
34 changes: 34 additions & 0 deletions test/Microsoft.ML.Core.Tests/UnitTests/TestModelLoad.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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.Data;
using Microsoft.ML.Runtime.Model;
using Microsoft.ML.TestFramework;
using System.IO;
using Xunit;

namespace Microsoft.ML.Runtime.RunTests
{
public class TestModelLoad
{
/// <summary>
/// Tests loading a model file that was saved using an older version still loads correctly.
/// </summary>
[Fact]
public void LoadOriginalBinaryLoaderModel()
{
using (var env = new LocalEnvironment()
.AddStandardComponents())
using (var modelStream = File.OpenRead(Path.Combine("TestModels", "BinaryLoader-v3.11.0.0.zip")))
using (var rep = RepositoryReader.Open(modelStream, env))
{
IDataLoader result = ModelFileUtils.LoadLoader(env, rep, new MultiFileSource(null), true);

Assert.Equal(2, result.Schema.ColumnCount);
Assert.Equal("Image", result.Schema[0].Name);
Assert.Equal("Class", result.Schema[1].Name);
}
}
}
}