dotnet / dotnet/machinelearning

ML.NET Containerized GPU Support?

Open
#6,015 0 comments 0 reactions 0 assignees View on GitHub
area-TensorFlow
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

**System Information (please complete the following information):**
- Windows 10 (Insider Program with 21H2 preview per Nvidia instructions)
- Latest WSL2 via Docker Desktop
- .NET 5 with ASP.NET as a web application as well
- ML.NET 1.7
- Visual Studio 2019
- GeForce 1080 GTX GPU
- CUDA 10.1

**Describe the bug**
I want to be able to run my ASP app in a Docker container that also trains models. This works fine for everything using base ML.NET nuget for the CPU. I followed the instructions to setup CUDA 10.1 with Cudnn (https://docs.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/install-gpu-model-builder) and NVIDIA's instructions for WSL2 (https://docs.nvidia.com/cuda/wsl-user-guide/index.html). I also added a reference to the GPU tensorflow package for Linux (assuming WSL2). The NVIDIA CUDA tests work fine when I run their containers, but I can't get my ML.NET container to work/use the GPU. Running nvidia-smi works in the container itself, but training still uses the CPU. I want to train models in the container using the GPU and have passed "--gpus all" in as a docker argument. I've exhausted everything but can't find any documentation or help on achieving this.

How would I go about doing this from Visual Studio 2019?

Below is my DockerFile (using Debug configuration):
```
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM nvidia/cuda:10.1-base as cuda
CMD nvidia-smi

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
WORKDIR /src
COPY ["CoolNET/CoolNET.csproj", "CoolNET/"]
RUN dotnet restore "CoolNET/CoolNET.csproj"
COPY . .
WORKDIR "/src/CoolNET"
RUN dotnet build "CoolNET.csproj" -c Debug -o /app/build

FROM build AS publish
RUN dotnet publish "CoolNET.csproj" -c Debug -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "CoolNET.dll"]
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.