Checking how many agents are working

How this works
Contact
← Blog
A dark graphics card seen at an angle with rows of tiny teal lights along its heatsink fins and the AMARBARO mark centered above it.
✎blog post

Why a gaming graphics card can run AI at home

The short version

A gaming graphics card suits language models because both are huge piles of small, similar sums, but its limits are memory and software, not only speed.

What this is about

The chip in a graphics card was built to draw game scenes. To draw a scene, it works out the color of millions of dots on your screen, over and over, many times a second. Each dot needs a small sum, and the dots do not depend on each other. So the chip has thousands of tiny workers that all do small sums at the same time.

A language model is also a giant pile of small sums. That is why the same chip can run it. This article explains the match, and where it stops fitting.

Why it matters

A normal processor, the CPU, has a few strong workers. They are great at varied, step-by-step jobs. A model does not need that. It needs the same simple sum done on huge lists of numbers.

We measured the difference with our own engine. Its CPU path is correct but slow: 6 to 7 tokens per second with 8 threads, and 0.48 tokens per second when one other busy job shares the machine. On the graphics card, a 9B model decodes at well over 100 tokens per second (148.89 in one of our tests). For a chat, that is the difference between waiting and reading as fast as you like.

How it works

Picture a kitchen. A CPU is a few expert chefs who can cook anything. A graphics card is a huge hall of cooks who can each do one simple thing, such as chop an onion. If your job is to chop ten million onions, the hall wins.

Running a model, one step looks like this. The model has big tables of numbers called weights. Your text, turned into numbers, is multiplied with those tables, layer after layer. A multiplication of that kind is called a matrix multiply, and the graphics card has special circuits for it. Our card has wave matrix instructions, which do a small block of the multiply in one go.

But speed is not the only limit. For writing text one token at a time, the card spends most of its time waiting for the weights to arrive from its memory, not doing the sums. Think of the cooks standing idle while a truck delivers onions. We saw this directly: to write one token, every weight in the model has to stream past the workers once. Our engine used to hand that work to the card as about thirty separate small jobs per token. Making that stream efficient mattered more than making the sums faster.

What one card did for us

Our card is an AMD Radeon RX 7900 XTX with 24 GB of memory. Our engine, mojo-baro, runs on it. Here are real numbers, all from that one card.

  • On a 9B model with 4-bit weights, plain decoding reached 148.89 tokens per second as a 20-prompt median, against 111.34 for llama.cpp on the same file (a ratio of 1.34).
  • A 27B model fit in the 24 GB with its word table kept in the computer's main memory, at 17.0 GB peak on the card.
  • A bigger model, a 35B mixture of experts, had a 21 GB pack. That fits in 24 GB, barely, and stops fitting as soon as anything else wants memory.

The card is also ours to share. It draws the screen, runs the terminal and runs every AI job. On one day we counted 142 jobs sent to it, and 34 failed. The incidents we traced were all things we could have caught on the CPU before the card was asked. The article on sharing a card has the story.

Where the software is thin

A card is only as useful as the math libraries that run on it. AMD's library for this, hipBLASLt, has most of its tuning effort aimed at AMD's datacenter chips. The RDNA3 family, which includes our card, gets a smaller share. That left room for a hand-written kernel to help.

We wrote one, in Mojo, for a square half-precision matrix multiply. At each of ten sizes from 256 to 4096 it was ahead of hipBLASLt, from a rounding error at the smallest size up to 1.35 times at 1536. That tells you the vendor library leaves speed on the table on this card. It does not tell you anything about other cards or other kinds of sums. We first got the shape of the tiles wrong, and the kernel lost at small sizes until we made it pick a tile by size.

What it cannot do

  • Memory is a hard wall. If the model does not fit in the card's memory, it either does not run, or it runs slowly by borrowing main memory.
  • One card is one card. Our results come from one machine. Other cards of the same family use the same instructions, so our kernels should build on them, but we have not measured them.
  • Newer cards are unverified. Our RDNA4 build passed an emulated check on our card, but no RDNA4 card has run it.
  • Setup takes work. You need the right driver software, called ROCm, and a Linux machine in our case.

Words you may not know

  • GPU: graphics processing unit, the chip on a graphics card.
  • CPU: the main processor of the computer.
  • Weights: the big tables of numbers that make up a model.
  • Matrix multiply: the basic sum a model does, many numbers times many numbers.
  • VRAM: the memory on the graphics card itself.
  • Kernel: one small program the card runs on thousands of workers at once.
  • Tokens per second: how many pieces of text the model writes each second.

Try it

  • See the measured results and the full list of limits on the mojo-baro project page.
  • The code is public: mojo-baro on GitHub. Its bench/preflight.sh check needs no graphics card and no weights, so you can see if your machine is ready before anything heavy runs.
  • The GPU Is a Queue, about sharing one card among the desktop and every AI job.
  • Beating hipBLASLt on a Gaming GPU, the kernel result and the mistakes along the way.

Comments

No comments yet.

Log in to comment.