Skip to content

how to use gpu? AddPredictionEnginePool #5985

Open

Description

@xlg-go

System Information (please complete the following information):

  • OS & Version: ubuntu 20.04
  • ML.NET Version: 1.6.0
  • .NET Version: .net core 3.1
  • Microsoft.Extensions.ML version: 1.6.0
  • webapi

Describe the bug
cpu work well, but, how to use gpu?

Screenshots, Code, Sample Projects

Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
   services.AddControllers();
   services.AddPredictionEnginePool<DeNoiseInput, DeNoiseOutput>().FromFile("./mlmodel/denoise_docs.zip");
}

Controller:

public class DocsController : Controller
{
    private readonly PredictionEnginePool<DeNoiseInput, DeNoiseOutput> _denoiseEngine;

    public DocsController(PredictionEnginePool<DeNoiseInput, DeNoiseOutput> denoiseEngine)
    {
        _denoiseEngine = denoiseEngine;
    }
    
    public ActionResult<string> DeNoise([FromBody] DeNoiseRequest request)
    {
         ...
         var outs = _denoiseEngine.Predict(imgExample);
         ...
    }
}

Activity

  1. luisquintanilla commented on Nov 2, 2021

    @luisquintanilla
    Contributor

    Hi @zcgg2zhmm

    Currently using the GPU for inferencing is only supported for ONNX models. When using the ApplyONNX transform as part of your pipeline, you can set the gpuDeviceId parameter. Then, because the pipeline is saved as a .zip file, you don't need to do anything extra with the PredictionEnginePool. Just load it into your app and make predictions as you've shown in your code samples.

  2. xlg-go commented on Nov 10, 2021

    @xlg-go
    Author

    Hi @zcgg2zhmm

    Currently using the GPU for inferencing is only supported for ONNX models. When using the ApplyONNX transform as part of your pipeline, you can set the gpuDeviceId parameter. Then, because the pipeline is saved as a .zip file, you don't need to do anything extra with the PredictionEnginePool. Just load it into your app and make predictions as you've shown in your code samples.

    @luisquintanilla
    Can you provide an example code? please!!
    I want to use it in webapi.
    Thanks a lot~

  3. added this to the ML.NET Future milestone on Oct 10, 2022
  4. added
    area-IntegrationIntegration with external frameworks, tools, and application platforms
    on Sep 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-IntegrationIntegration with external frameworks, tools, and application platformsdocumentationRelated to documentation of ML.NETyellowmaintenance only

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions