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

ML.NET v1.4 doesn't work on Azure Functions with .NET Core 2.1 #5187

Closed
eerhardt opened this issue Oct 31, 2019 · 1 comment · Fixed by #5193
Closed

ML.NET v1.4 doesn't work on Azure Functions with .NET Core 2.1 #5187

eerhardt opened this issue Oct 31, 2019 · 1 comment · Fixed by #5193
Assignees

Comments

@eerhardt
Copy link
Member

When creating an Azure Function on netcoreapp2.1 and using ML.NET v1.4, it is failing to load the CpuMathNative library.

Between ML.NET 1.3. and 1.4 we’ve updated our “CpuMath” package in order to support .NET Core 3.0. We are now taking advantage of the new C# Hardware Intrinsics (SIMD) APIs in .NET Core 3.0. In order to make that change, we had to refactor our NuGet package a bit, and that refactoring seems to break Azure Functions.

In 1.4, our native assembly has moved inside the NuGet package.

Before

runtimes\win-x64\native\CpuMathNative.dll

After

runtimes\win-x64\nativeassets\netstandard2.0\CpuMathNative.dll

This change was needed because we don’t need the native assembly when running on netcoreapp3.0. So taking advantage of the runtimes\{RID}\nativeassets\{TFM} functionality in NuGet allowed us to not ship an unnecessary native binary in the customer’s app. For more information on this support in NuGet, see NuGet/Home#2782.

When running an Azure Functions app, it isn’t handling the nativeassets folder correctly. Thus, the CpuMathNative assembly isn’t loaded, and the Azure Function fails.

Repro steps

Provide the steps required to reproduce the problem:

  1. Clone and check out https://github.com/dotnet/machinelearning-samples/tree/46fb968a9af744f0f97741a0c1556f708bfb277d/samples/csharp/end-to-end-apps/ScalableMLModelOnAzureFunction.
  2. Load the Azure Function project.
  3. F5
  4. From Powershell: Invoke-RestMethod "http://localhost:7071/api/AnalyzeSentiment" -Method Post -Body (@{SentimentText="This is a very bad steak"} | ConvertTo-Json) -ContentType "application/json"

Expected behavior

The app should work and the function should return "Negative" since bad steak is a negative sentiment.

Actual behavior

Invoke-RestMethod : The remote server returned an error: (500) Internal Server Error.
At line:1 char:1
+ Invoke-RestMethod "http://localhost:7071/api/AnalyzeSentiment" -Metho ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

From Debugging in Visual Studio the exception is:

System.DllNotFoundException: 'Unable to load DLL 'CpuMathNative' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)'

Known workarounds

The only workaround I know of is to use ML.NET 1.3.

Related information

I played locally with a change to the Azure Function native assembly loading code, and I was able to get this fixed when the function.deps.json file is present. If you want to take a look, my change is here.

@eerhardt
Copy link
Member Author

eerhardt commented Nov 1, 2019

@fabiocav - I'd like to take a stab at fixing this. Can you assign it to me?

eerhardt added a commit to eerhardt/azure-functions-host that referenced this issue Nov 1, 2019
This allows for probing of more locations for native libraries instead of just the "runtimes\{rid}\native" folder. For example, native assets can also live in a "runtimes\{rid}\nativeassets\{tfm}" folder.

Fix Azure#5187
fabiocav pushed a commit that referenced this issue Nov 1, 2019
This allows for probing of more locations for native libraries instead of just the "runtimes\{rid}\native" folder. For example, native assets can also live in a "runtimes\{rid}\nativeassets\{tfm}" folder.

Fix #5187
@ghost ghost locked as resolved and limited conversation to collaborators Dec 31, 2019
fabiocav pushed a commit that referenced this issue Apr 22, 2020
This allows for probing of more locations for native libraries instead of just the "runtimes\{rid}\native" folder. For example, native assets can also live in a "runtimes\{rid}\nativeassets\{tfm}" folder.

Fix #5187
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 a pull request may close this issue.

2 participants