Skip to content

Various pre-trained machine learning models reimplemented to run on browsers through WebGL and WebGPU

License

Notifications You must be signed in to change notification settings

Volcomix/ml-browser-gpu

Repository files navigation

ML Browser GPU

Various pre-trained machine learning models reimplemented to run on browsers through WebGL and WebGPU.

Parallel sum reduction

Ok, this one isn't exactly an ML model but I wanted to experiment first with basic building blocks. This example consists in summing a large number of integers as quickly as possible.

It's quite interesting to note that WebGPU isn't necessarily faster when we can combine WebGL with mipmaps.

This example can be tested locally: http://localhost:5173/sum/.

The source code is available in the directory src/sum.

Result

References

PyTorch Quickstart Tutorial (WebGL)

To start simple, the model described in the PyTorch Quickstart Tutorial has been implemented in WebGL. You can see some details in the notebook.

For now the source code is in main.ts

Here is an overview of the WebGL design:

Result

----------------------------------------------------------------------------------------------------
Output: -2.2995, -2.1135, -1.0424, -1.6524, -0.9015, 2.4404, -1.1452, 2.6658, 1.6956, 3.0893
Predicted: Ankle boot
Time: 14.699999999254942ms
----------------------------------------------------------------------------------------------------
Output: -2.2995, -2.1135, -1.0424, -1.6524, -0.9015, 2.4404, -1.1452, 2.6658, 1.6956, 3.0893
Predicted: Ankle boot
Time: 11.299999998882413ms
----------------------------------------------------------------------------------------------------
Output: -2.2995, -2.1135, -1.0424, -1.6524, -0.9015, 2.4404, -1.1452, 2.6658, 1.6956, 3.0893
Predicted: Ankle boot
Time: 1.099999999627471ms
----------------------------------------------------------------------------------------------------
Output: -2.2995, -2.1135, -1.0424, -1.6524, -0.9015, 2.4404, -1.1452, 2.6658, 1.6956, 3.0893
Predicted: Ankle boot
Time: 0.6999999992549419ms
----------------------------------------------------------------------------------------------------
Output: -2.2995, -2.1135, -1.0424, -1.6524, -0.9015, 2.4404, -1.1452, 2.6658, 1.6956, 3.0893
Predicted: Ankle boot
Time: 0.6999999992549419ms
----------------------------------------------------------------------------------------------------

About

Various pre-trained machine learning models reimplemented to run on browsers through WebGL and WebGPU

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published