Menu

How a Browser Trains a Neural Network: Tensors as Textures, Ops as Shaders
📰

How a Browser Trains a Neural Network: Tensors as Textures, Ops as Shaders

DEV Community: tensorflow·ai-spinach lab·8 days ago
#oRAIqMyI
#devtotensorflow#devto#dev#webgl#loss
Reading 0:00
15s threshold

You can open a tab, click a button, and watch an LSTM's loss curve go down. No server, no Python environment, no CUDA. How does that work?

The short answer: the browser borrows your graphics card through WebGL, and a few clever mappings turn a graphics API into a math engine.

Why a GPU at all?

Training a neural network is mostly matrix multiplication: the same simple operation repeated over thousands of numbers. A CPU does a few things at a time very fast. A GPU does thousands of simple things at the same time. That is a good match.

The catch is that WebGL was designed for drawing triangles, not for multiplying matrices.

The trick: tensors become textures, ops become shaders

Libraries like TensorFlow.js use two mappings:

Machine learning WebGL

Tensor (an array of numbers) Texture (an image stored in GPU memory)

Operation (matmul, add, ReLU) Fragment shader (a small program that runs once per pixel)

Think of a texture as a grid of pixels, where each pixel's color channels hold numbers instead of…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.