dotnet / dotnet/machinelearning-modelbuilder

Libtorchsharp not found when released to server

Open
#2,773 1 comment 0 reactions 0 assignees View on GitHub
GS Tutorial Stale
Dominant language
Dockerfile
Stars
285
Forks
66
PR merge metrics
No merged PRs in 30d

Description

**System Information (please complete the following information):**
- Model Builder or CLI Version: Microsoft.ML.ModelBuilder.Gallery.Dev17 (preview)
- Visual Studio Version (if applicable): VS 2022 (latest)

**Describe the bug**
- On which page of the tutorial did you run into an issue (URL): Consume (Deploy)
- Clear description of the problem: When consuming the API locally, using debugging in visual studio the API works fine. However, when deploying the WebAPI to my IIS server, which has the ASP.NET Core hosting installed, I get the error when .Predict() is called.

**To Reproduce**
Steps to reproduce the behavior:
1. Create and Train an Object Detection Model locally with CPU.
2. Consume the API locally (works).
3. Publish API to folder (or directly to IIS).
4. Attempt to call API through swagger or Postman.
5. See error

**Expected behavior**
I expected the predict function to work just as it was working in development.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Log File Dump:

info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\inetpub\wwwroot\Barcode Detector\
fail: Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer[2]
Connection ID "18374686489872180643", Request ID "800025a4-0002-ff00-b63f-84710c7967bb": An unhandled exception was thrown by the application.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.DllNotFoundException: Unable to load DLL 'LibTorchSharp' or one of its dependencies: The specified module could not be found. (0x8007007E)
at TorchSharp.PInvoke.LibTorchSharp.THSNN_custom_module(String name, ForwardFunctionC forward, IntPtr& pBoxedModule)
at TorchSharp.torch.nn.Module..ctor(String name)
at TorchSharp.torch.nn.HookableModule`2..ctor(String name)
at TorchSharp.torch.nn.Module`2..ctor(String name)
at Microsoft.ML.TorchSharp.AutoFormerV2.AutoFormerV2..ctor(Int32 numClasses, List`1 embedChannels, List`1 depths, List`1 numHeads, Device device)
at Microsoft.ML.TorchSharp.AutoFormerV2.ObjectDetectionTransformer.Create(IHostEnvironment env, ModelLoadContext ctx)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs)
at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstance(IHostEnvironment env, Object args, Object[] extra)
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.LoadModelOrNull[TRes,TSig](IHostEnvironment env, TRes& result, String name, Object[] extra)
at Microsoft.ML.ModelLoadContext.LoadModel[TRes,TSig](IHostEnvironment env, TRes& result, String name, Object[] extra)
at Microsoft.ML.Data.TransformerChain`1..ctor(IHostEnvironment env, ModelLoadContext ctx)
at Microsoft.ML.Data.TransformerChain.Create(IHostEnvironment env, ModelLoadContext ctx)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstanceCore(Object[] ctorArgs)
at Microsoft.ML.Runtime.ComponentCatalog.LoadableClassInfo.CreateInstance(IHostEnvironment env, Object args, Object[] extra)
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)
at MPBarcodeDetection.CreatePredictEngine() in C:\Users\krb\Documents\Work Repos\MP Barcode Detector\Web Service Core\Barcode_Detector_WebAPI\MPBarcodeDetection_WebAPI\MPBarcodeDetection.consumption.cs:line 67
at MPBarcodeDetection.<>c.<.cctor>b__17_0() in C:\Users\krb\Documents\Work Repos\MP Barcode Detector\Web Service Core\Barcode_Detector_WebAPI\MPBarcodeDetection_WebAPI\MPBarcodeDetection.consumption.cs:line 61
at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy`1.CreateValue()
at MPBarcodeDetection.Predict(ModelInput input) in C:\Users\krb\Documents\Work Repos\MP Barcode Detector\Web Service Core\Barcode_Detector_WebAPI\MPBarcodeDetection_WebAPI\MPBarcodeDetection.consumption.cs:line 78
at MPBarcodeDetection_WebAPI.Repository.BarcodePredictionRepository.GetPrediction(String ImageAsBase64) in C:\Users\krb\Documents\Work Repos\MP Barcode Detector\Web Service Core\Barcode_Detector_WebAPI\MPBarcodeDetection_WebAPI\Repository\BarcodePredictionRepository.cs:line 29
at MPBarcodeDetection_WebAPI.Controllers.BarcodePredictionController.MakeBarcodePrediction(BarcodePredictionParams Params) in C:\Users\krb\Documents\Work Repos\MP Barcode Detector\Web Service Core\Barcode_Detector_WebAPI\MPBarcodeDetection_WebAPI\Controllers\BarcodePredictionController.cs:line 26
at lambda_method3(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()
info: Microsoft.Hosting.Lifetime[0]
Application is shutting down...

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.