Skip to content

Error loading LightGBM model #4917

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

Closed
tomasfalt opened this issue Mar 4, 2020 · 4 comments
Closed

Error loading LightGBM model #4917

tomasfalt opened this issue Mar 4, 2020 · 4 comments
Assignees
Labels
need info This issue needs more info before triage

Comments

@tomasfalt
Copy link

System information

  • OS version/distro: Windows 10
  • .NET Version (eg., dotnet --info): .Net Standard 2.0
  • ML.Net version: 1.4

Issue

  • What did you do?
    Build and trained a model with FastTree, saved it and finally load it and all worked. Changed to LightGBM and got an error when I try to load it.

The error is following:
InvalidOperationException: Can't load type Microsoft.ML.IPredictorProducing`1[System.Single], because it has both create and constructor methods with the same visibility. Please indicate which one should be used by changing either the signature or the visibility of one of them.

Source code / logs

InvalidOperationException: Can't load type Microsoft.ML.IPredictorProducing`1[System.Single], because it has both create and constructor methods with the same visibility. Please indicate which one should be used by changing either the signature or the visibility of one of them.

System.InvalidOperationException
HResult=0x80131509
Message=Error during class instantiation
Source=Microsoft.ML.Core
StackTrace:
at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs)
at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes](IHostEnvironment env, Type signatureType, TRes& result, String name, String options, Object[] extra)
at Microsoft.ML.Runtime.ComponentCatalog.TryCreateInstance[TRes,TSig](IHostEnvironment env, TRes& result, String name, String options, Object[] extra)
at Microsoft.ML.ModelLoadContext.TryLoadModelCore[TRes,TSig](IHostEnvironment env, TRes& result, Object[] extra)
at Microsoft.ML.ModelLoadContext.TryLoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, Entry ent, String dir, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, RepositoryReader rep, String dir, Object[] extra)
at Microsoft.ML.ModelOperationsCatalog.Load(Stream stream, DataViewSchema& inputSchema)
at Microsoft.ML.ModelOperationsCatalog.Load(String filePath, DataViewSchema& inputSchema)

This exception was originally thrown at this call stack:
Microsoft.ML.Runtime.ComponentCatalog.TryGetIniters(System.Type, System.Type, System.Type[], out System.Reflection.MethodInfo, out System.Reflection.ConstructorInfo, out System.Reflection.MethodInfo, out bool)
Microsoft.ML.Runtime.ComponentCatalog.RegisterAssembly(System.Reflection.Assembly, bool)
Microsoft.ML.ModelLoadContext.EnsureLoaderAssemblyIsRegistered(Microsoft.ML.Runtime.ComponentCatalog)
Microsoft.ML.ModelLoadContext.TryLoadModelCore<TRes, TSig>(Microsoft.ML.Runtime.IHostEnvironment, out TRes, object[])
Microsoft.ML.ModelLoadContext.TryLoadModel<TRes, TSig>(Microsoft.ML.Runtime.IHostEnvironment, out TRes, Microsoft.ML.RepositoryReader, Microsoft.ML.Repository.Entry, string, object[])
Microsoft.ML.ModelLoadContext.LoadModel<TRes, TSig>(Microsoft.ML.Runtime.IHostEnvironment, out TRes, Microsoft.ML.RepositoryReader, Microsoft.ML.Repository.Entry, string, object[])
Microsoft.ML.ModelLoadContext.LoadModelOrNull<TRes, TSig>(Microsoft.ML.Runtime.IHostEnvironment, out TRes, Microsoft.ML.RepositoryReader, string, object[])

Inner Exception 1:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 2:
InvalidOperationException: Error during class instantiation

Inner Exception 3:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 4:
InvalidOperationException: Error during class instantiation

Inner Exception 5:
TargetInvocationException: Exception has been thrown by the target of an invocation.

Inner Exception 6:
InvalidOperationException: Can't load type Microsoft.ML.IPredictorProducing`1[System.Single], because it has both create and constructor methods with the same visibility. Please indicate which one should be used by changing either the signature or the visibility of one of them.

@antoniovs1029 antoniovs1029 self-assigned this Mar 4, 2020
@antoniovs1029
Copy link
Member

antoniovs1029 commented Mar 4, 2020

Can you please share your code and dataset to reproduce your problem? thanks

Also, what version of Microsoft.ML.LightGbm are you using along with Microsoft.ML 1.4?

@antoniovs1029 antoniovs1029 added the need info This issue needs more info before triage label Mar 4, 2020
@tomasfalt
Copy link
Author

Sadly not, since it business critical data I can't disclose it. About the code I just use the default settings but I do an OneHotEncoding on one field.

I'm using the 1.4.0 version of the Microsoft.ML.LightGbm.

Please contact me directly through [email protected] and I will send you the code and the dataset for testing purposes

@antoniovs1029
Copy link
Member

antoniovs1029 commented Mar 5, 2020

I wouldn't expect the OneHotEncoding to be related. Can you please list all the Microsoft.ML nugets you're using along with their versions? Recently another user had the same problem, and it was caused because he was combining ML.NET nugets from different releases.

Another thing that makes me think you might be using nugets from another release, is because the error message you're seeing (InvalidOperationException: Can't load type Microsoft.ML.IPredictorProducing1[System.Single], because it has both create and constructor methods with the same visibility.) was written on PR #4385 which got merged on November 27 and was included in ML.NET 1.5.0-preview released on December. Whereas the ML.NET 1.4 stable nugets got released on November 4.

Also, what kind of LightGBM is it? Binary, multiclass, regression...?
Thanks!

@tomasfalt
Copy link
Author

I tried different things to minimize code and nuget reference and finally I was down to just ML.Net, ML.Net.FastTree and ML.Net.LightGBM and it still didn't work. But when I changed to the ML.Net 1.5.0-preview version it worked perfectly. So it's probably solved by PR #4385.

It's a binary LightGBM btw.

Thanks for the help!

@ghost ghost locked as resolved and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need info This issue needs more info before triage
Projects
None yet
Development

No branches or pull requests

2 participants