NuGet packages with native assets in a notebook
See original GitHub issueDescribe the bug
When using the Microsoft.ML NuGet package in a notebook, you get an exception when ML.NET calls into a native assembly.
Repro
Run the following notebook:
#r "nuget:Microsoft.ML"
using Microsoft.ML;
using Microsoft.ML.Data;
class IrisData
{
public IrisData(float sepalLength, float sepalWidth, float petalLength, float petalWidth)
{
SepalLength = sepalLength;
SepalWidth = sepalWidth;
PetalLength = petalLength;
PetalWidth = petalWidth;
}
public float SepalLength;
public float SepalWidth;
public float PetalLength;
public float PetalWidth;
}
var data = new []
{
new IrisData(1.4f, 1.3f, 2.5f, 4.5f),
new IrisData(2.4f, 0.3f, 9.5f, 3.4f),
new IrisData(3.4f, 4.3f, 1.6f, 7.5f),
new IrisData(3.9f, 5.3f, 1.5f, 6.5f),
};
MLContext mlContext = new MLContext();
var pipeline = mlContext.Transforms
.Concatenate("Features", "SepalLength", "SepalWidth", "PetalLength", "PetalWidth")
.Append(mlContext.Clustering.Trainers.KMeans("Features", numberOfClusters: 2));
try
{
pipeline.Fit(mlContext.Data.LoadFromEnumerable(data));
}
catch (Exception e)
{
Console.WriteLine(e);
}
This shouldn’t throw an exception, but it does:
System.DllNotFoundException: Unable to load shared library 'CpuMathNative' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(libCpuMathNative, 1): image not found
at Microsoft.ML.Internal.CpuMath.Thunk.SumSqU(Single* ps, Int32 c)
at Microsoft.ML.Internal.CpuMath.CpuMathUtils.SumSq(ReadOnlySpan`1 src)
at Microsoft.ML.Numeric.VectorUtils.NormSquared(VBuffer`1& a)
at Microsoft.ML.Trainers.KMeansBarBarInitialization.Initialize(IHost host, Int32 numThreads, IChannel ch, Factory cursorFactory, Int32 k, Int32 dimensionality, VBuffer`1[] centroids, Int64 accelMemBudgetMb, Int64& missingFeatureCount, Int64& totalTrainingInstances)
at Microsoft.ML.Trainers.KMeansTrainer.TrainCore(IChannel ch, RoleMappedData data, Int32 dimensionality)
at Microsoft.ML.Trainers.KMeansTrainer.TrainModelCore(TrainContext context)
at Microsoft.ML.Trainers.TrainerEstimatorBase`2.TrainTransformer(IDataView trainSet, IDataView validationSet, IPredictor initPredictor)
at Microsoft.ML.Trainers.TrainerEstimatorBase`2.Fit(IDataView input)
at Microsoft.ML.Data.EstimatorChain`1.Fit(IDataView input)
at Submission#6.<<Initialize>>d__0.MoveNext()
Did this error occur while using dotnet try
or online?
-
dotnet-try
- online
What kind of error was it?
- User Interface (UI): For example the output never displayed
- Service Error: For example “The service is temporarily unavailable. We are working on it”
- Other:
Screenshots
Please complete the following:
- OS
- Windows 10
- macOS
- Linux (Please specify distro)
- iOS
- Android
- Browser
- Chrome
- Edge
- Safari
Issue Analytics
- State:
- Created 4 years ago
- Comments:17 (17 by maintainers)
Top Results From Across the Web
How to include native assets in Nuget on multiple platforms ...
I'm creating a NuGet package with the following idea: ... The idea isn't to embed the native resources and then extract them but...
Read more >Support for Native Projects - The NuGet Blog
If you're interested in publishing your native libraries via NuGet, you can choose to create the NuGet packages manually. However, there's an ...
Read more >Microsoft.Net.Native.Compiler 2.2.3
NET Native compiler contained in the package, as opposed to any system installed version. ... There are no supported framework assets in this...
Read more >How to make a Nuget package for C++
If you are looking for more examples of nuget packages holding native projects, do a search on nuget.org, and find a project. Browse...
Read more >NuGet packages in the Package Registry
Publish NuGet packages in your project's Package Registry. Then, install the packages whenever you need to use them as a dependency. The Package...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Does dotnet-interactive run a restore on the packages it loads? If it did, it shouldn’t be too much more to generate a deps file for that assembly. According to https://docs.microsoft.com/en-us/dotnet/core/tutorials/creating-app-with-plugin-support#load-plugins
Here’s a quick sample I threw together that produces a deps file for a package.
Yep, that’s the one! That’s how you can get the RID of the current machine. The user shouldn’t need to supply it at all.