WebNN – AI Comes to Your Browser with DirectML

That’s it, friends, the WebNN API has finally arrived in preview for developers, and believe me, it’s going to totally change the way we run AI in our web browsers! Thanks to this technology, we’ll be able to take advantage of the power of our GPUs and other hardware accelerators directly from our web pages, without needing to install any additional plugins or software.

Specifically, WebNN is a JavaScript API that will allow web applications to execute neural network inference tasks super efficiently, fully exploiting the capabilities of CPUs, GPUs, and other AI processors (the well-known NPUs and TPUs). No more sluggish computations—hello, smooth and responsive performance, even for the most demanding models!

WebNN is completely hardware and model agnostic. No matter what hardware we have under the hood (Intel, AMD, NVIDIA, Qualcomm…) and the model format (ONNX, TensorFlow…), this API will let us make the most of the available resources, all in a transparent way, without having to deal with code specific to each platform.

This API follows a very simple programming model in two main steps:

  • Building the model: we use the MLGraphBuilder API to define our neural network, its operations, its inputs, and outputs. Once that’s done, we can compile it into an executable graph.
  • Running the model: now that we have our optimized graph, we just need to send it our input data, and it will provide its predictions and classifications at full speed!

With WebNN, machine learning inference tasks are accelerated by local hardware, offering improved performance and low latency, even without an internet connection or with an unreliable one. Additionally, data stays on the user’s machine, thus preserving their privacy.

WebNN is designed to work with DirectML on Windows, ensuring optimal performance on various hardware, notably NVIDIA RTX GPUs, Intel Core Ultra with Intel AI Boost, and Copilot+ PCs with Qualcomm Hexagon NPUs. This opens the door to advanced applications of AI generation, image recognition, natural language processing, and many other exciting use cases.

If you want to get started with WebNN right now, I strongly recommend visiting the WebNN Developer Preview repository on GitHub. You’ll find plenty of demos and code examples to familiarize yourself with the API and its features. However, you will need to download the Canary version of Edge and the latest Insider version of Windows 11, then in the URL bar, type edge://flags/ to activate WebNN.

For more details, you can check out the official Microsoft tutorial.

Mohamed SAKHRI
Mohamed SAKHRI

I'm the creator and editor-in-chief of Tech To Geek. Through this little blog, I share with you my passion for technology. I specialize in various operating systems such as Windows, Linux, macOS, and Android, focusing on providing practical and valuable guides.

Articles: 1310

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *