dotnet / machinelearning

ML.NET is an open source and cross-platform machine learning framework for .NET.
https://dot.net/ml
MIT License
8.94k stars 1.86k forks source link

DirectML support #5240

Open boyedarat opened 4 years ago

boyedarat commented 4 years ago

Are there any plans to support DirectML as an alternative to TF? Have not seen this request in the Issues list.

wangyems commented 4 years ago

@boyedarat Thank you for reaching out! Adding DirectML support for ML.NET is not in our immediate roadmap. We will add it to our list of requested features to be considered when we plan the next release. Can you please share some details about your specific use case that will help us prioritize this feature request?

boyedarat commented 4 years ago

DirectML allows users to utilize hardware that are not limited to nVidia. After moving from TF to ML.Net, it is frustrating to see that even ML.Net is becoming a wrapper around TF. If I wanted to use TF as a backend for my ML work, I would just use TF.Net. I hope that ML.Net will not evolve into just another TF wrapper, like basically most of the tools out there. I believe this would be an incentive for STEM students who are using cheaper non nVidia hardware to learn ML.Net since there are hardly any other options out there for them. Back ends like nGraph and ROCm are Linux exclusive, I do not see a problem with implementing DirectML that is proprietary to Windows, when other players in this space are doing it for Linux and nVidia.

wangyems commented 4 years ago

Hi @boyedarat ,Thanks for your reply! We will discuss this feature request.

harishsk commented 4 years ago

Hi @boyedarat Thank you for the additional detail. One concern around supporting DirectML in ML.NET is that DirectML is its dependency on Direct3D. ML.NET is intended to be a cross platform framework for C# developers and DirectML is currently Windows only. (Though Linux support is now available, but only through WSL).

We are continuing to evaluate multiple options for more deep learning support in ML.NET. But further evaluation of this direction is possible only when DirectML support is more broadly available. We will continue to monitor that and reopen this issue when that changes.

Thank you for your input.

boyedarat commented 4 years ago

@harishsk Odd you would state that, considering that the TensorFlow back-end used by ML.Net limits users to nVidia GPUs for any reasonable acceleration. Why would supporting DirectML as a "back-end" that opens up more hardware choices would be bad for ML.Net? I did not imply that TensorFlow be abandoned and to move to DirectML exclusively. Only that enabling the use of DirectML as an alternative on Windows would help devs, researchers and students alike, to take advantage of GPGPU hardware that is not exclusive to nVidia. How does this not fit in with the goal of ML.Net being a cross platform framework?

FYI, Microsoft has released TensorFlow with DirectML support, on Windows. Can we at least use this as the TensorFlow back-end when on Windows? Note that this is not about running TensorFlow applications on WSL. This is a native port to DirectML on Windows itself. More details here: https://github.com/tensorflow/community/pull/243 and here: https://docs.microsoft.com/en-us/windows/win32/direct3d12/gpu-tensorflow-windows

harishsk commented 4 years ago

@boyedarat, I did not rule out supporting DirectML. I only highlighted the issue that if we were to add DirectML support, it would be only on Windows. Currently all APIs of ML.NET are available on Windows, Mac and Linux. We would not be able to support DirectML on Linux and Mac. It is something we would need to consider in our planning.

Using DirectML as a Tensorflow backend when using Tensorflow through ML.NET is an interesting option. Let me look more into that. Thank you again for your input.

boyedarat commented 4 years ago

@harishsk Thanks. Could we reopen this issue again or should I raise a new one? Would like to track this closely as it stands to benefit many devs like me.

harishsk commented 4 years ago

I have reactivated the issue and will post any updates here. Thanks.

TashaSkyUp commented 3 years ago

I too am amazed that Microsoft ML.NET does not support Microsoft DirectML. Please support DirectML or use it to create you own AMD GPU acceleration for ML.NET. I know, I know.. you want everyone to pay for cloud computing. To bad, that is not realistic. A huge part of the goal of the opensource community is to make the product available for as many people as possible. Right now your denying what like 50% of the hardware out there. And possibly more importantly you are unnecessarily dismissing people with less money to spend... this is not how open source is supposed to work.

saint4eva commented 3 years ago

I too am amazed that Microsoft ML.NET does not support Microsoft DirectML. Please support DirectML or use it to create you own AMD GPU acceleration for ML.NET. I know, I know.. you want everyone to pay for cloud computing. To bad, that is not realistic. A huge part of the goal of the opensource community is to make the product available for as many people as possible. Right now your denying what like 50% of the hardware out there. And possibly more importantly you are unnecessarily dismissing people with less money to spend... this is not how open source is supposed to work.

Don't you think that your comment is not adding any value to this issue?

vishvanathan-k commented 3 years ago

@harishsk but isn't it important for windows developer, you can't except every developer to well-off and has latest NVIDIA GPUs or Azure , right. As a student without edu mail id , I can't even get azure for students. It is better if you guys cater our needs of running ML.NET using DirectML

ericstj commented 3 years ago

At the moment we don't have plans to add DirectML support through new bindings, but it's not something we've ruling out. cc @briacht @michaelgsharp

Microsoft has released TensorFlow with DirectML support, on Windows. Can we at least use this as the TensorFlow back-end when on Windows

This is interesting, do you happen to know what prevents ML.NET from using this today? If it's compatible and the modules have the same name it should work. If not then maybe we could consider a proposal that would enable it.

vishvanathan-k commented 3 years ago

hi @ericstj is there a way to use directml from C# because I don't have a clue on how to use it.and there is no docs all docs use C++ or C not C#, Thanks

ericstj commented 3 years ago

I was first referring to the DirectML build of Tensorflow, if that's a full featured cross-compile of TF it should work like other GPU cross-compiles: just provide those binaries to ML.NET instead of the ones we reference in other nuget packages. This is how folks use GPU builds of Tensorflow today. https://github.com/dotnet/machinelearning/blob/2c8afeb64ed92f838e804fc6f4995163a7c92e3f/docs/api-reference/tensorflow-usage.md#usage I can imagine the same thing working for the DirectML build of Tensorflow if that build was produced in a similar manner. I only see a PyPI package: https://blogs.windows.com/windowsdeveloper/2021/01/28/bring-your-ai-to-any-gpu-with-directml/ I wonder if DirectML (or SciSharp) can be convinced to produce a NuGet package that exposes the C-API?

Using DirectML in C# should be possible. It looks to me like they don't currently ship .NET bindings, nor WinRT, but they do have a C API. A C# app could PInvoke to those. The cswin32 project is one that aims to make using win32/C API easier, I haven't checked, but perhaps that would work with DirectML. You can always make a request for the DirectML project to support .NET.

It's not clear to me how DirectML would fit into the current ML.NET offering: we don't currently leverage GPU directly, so it's not as if we have a good place to just pick this up and use it. It would require some more thought and specification for how that framework might be used in an ML.NET pipeline.

ericstj commented 3 years ago

It looks like https://github.com/microsoft/tensorflow-directml/issues/135 might have a nice path forward.

It looks to me like this could be something to try today using https://github.com/microsoft/tensorflow-directml/releases/tag/v1.15.4.dev201216, just replace the tensorflow binaries in an app with those, similar to how is done today with a GPU tensorflow.

edit: I just noticed that @boyedarat opened that issue: thank you for raising this.

vishvanathan-k commented 3 years ago

Hi @ericstj I tried as you told using PInvoke but I don't know how to continue farther. Any help will be be appreciated.And I have another doubt, Is it possible to use Train ML.NET DNNs using DirectML in C++ and the import them into C# UWP

ericstj commented 3 years ago

@vishvanathan-k This repository isn't about providing support for DirectML. I was merely observing that DirectML should be callable from C# since it has a C API. You are better off raising questions about how to use DirectML in https://github.com/microsoft/DirectML.

vishvanathan-k commented 3 years ago

okay sure Thanks I will open an issue

luisquintanilla commented 1 year ago

Hi folks,

Anybody have a non-CUDA GPU that would like to take this for a spin to make sure it works?

Note that this scenario is inferencing only.

https://github.com/luisquintanilla/DirectMLONNXTest

TashaSkyUp commented 1 year ago

yeah I can check it out.

uygary commented 10 months ago

I strongly believe that ML.NET should stick to being platform independent, like most of the .NET ecosystem. The problem raised with TF being tied to a particular vendor is a very real, and very annoying problem. However, tying ML.NET to a particular operating system is not a solution to that. That should be addressed by a pull request into TensorFlow, that would add support for non-CUDA GPU's.

boyedarat commented 10 months ago

I strongly believe that ML.NET should stick to being platform independent, like most of the .NET ecosystem. The problem raised with TF being tied to a particular vendor is a very real, and very annoying problem. However, tying ML.NET to a particular operating system is not a solution to that. That should be addressed by a pull request into TensorFlow, that would add support for non-CUDA GPU's.

There currently isn't support for ML.NET to use TensorFlow plugins that enable hardware backends other than CUDA. Either they adopt multi backend support, like what PyTorch is doing, or provide a means to do this through TensorFlow. Limited to a single AI hardware proprietary platform is a real problem on ML.NET, which should be addressed by the framework. DirectML provides access to all hardware vendors, including Intel, which is currently not available through TensorFlow. Also, TensorFlow only supports plugins through their Python framework, not through their C libraries, which is what is used by ML.NET. At least, this was the case, last I checked.