Checking how many agents are working

How this works
Contact
← Blog
A short olive staircase of glowing steps rising across a near-black navy ground with a dotted grid, each step a little higher than the last, the AMARBARO mark centred over it.
✎article de blog

How a big model got faster on one card, step by step

The short version

A 35B mixture-of-experts model went from 42.88 to 111.89 tokens a second on one RX 7900 XTX in a single day through measured, ordered changes, and the last round landed below its own preregistered +5 percent bar and was kept only on a recorded override.

What this is about

Speed does not come from one trick. In our case it came from a list of small changes, each tested, each kept only if the output stayed the same. This article walks through the list, in order, for a large model on one gaming card.

It is also a lesson in order. We did not start by writing new code. We started by looking at where the time went.

Why it matters

It is tempting to guess where a program is slow and fix the part that looks clever. That usually wastes the day. A model that looks limited by math can be limited by how its memory is read. A program that looks limited by one big kernel can be limited by thousands of tiny launches. You only know by measuring first.

The order of the steps

Step 0: read the trace. Before any code changed, we recorded a trace of every kernel the card ran for a token, using the card's profiler. Two things stood out. The weight kernels read packed numbers one value at a time. And the router, which picks which 8 experts work, ran its eight selection passes one after another inside one launch.

At the start of that day, the model decoded at 42.88 tokens a second. A rival engine on the same file read 109.4.

Step 1: read memory in wider pieces. We changed the first kernel to load several values at once. Same arithmetic, wider reads.

Step 2: do the same for the second packed format.

Step 3: rewrite the router. One wave of threads, instead of a serial loop.

Those three took the speed from 42.88 to 55.98, then 71.89, then 93.46 tokens a second. The output stayed identical to the earlier engine on every test prompt. None of it was a new algorithm. It was the same math reading memory in better-shaped pieces.

Step 4: remove launches nobody needed. The next lever was not inside any kernel. It was how many kernels ran per token. A trace counted 1,217 launches per token. Two kinds were pure waste: 60 memory-clearing steps that a later kernel already overwrote, and 40 host copies that also overwrote the router's own first answer. Removing exactly 100 launches, checked in the trace, took the speed from 94.68 to 99.92.

Step 5: fold more launches. Five more folds brought the count to 857 and the speed to 107.27, up from 94.79.

Step 6: fold again. The count fell to 727 and the speed read 111.89, against 107.28. That is a 1.043 times gain.

The step that missed its own bar

Before that last round, we had written down a kill line: it had to gain at least 5 percent. It gained 4.3. By our own rules it had not earned its place. It shipped anyway, on a recorded call by the person running the work, not on a passing score. We put that fact next to the number in our baseline file: 111.89 tokens a second, below its own bar, kept on an override. A reader who takes the number without that sentence is missing the real state of the work.

A note on comparing with other engines

We measured the rival engine twice. It read 109.4 in one session and 109.92 in another. Both are real. In the stretch where it read 109.92, our earlier build read 106.95, which is 0.973 times, so it was behind in that session. The lesson: a comparison engine must be measured again in the same session, every time.

The second kind of speed: reading the prompt

Everything above is about writing tokens one at a time. A different job is reading the prompt, called prefill. Running it one token at a time wastes work, because every token of the prompt is already known.

We wrote a batched version that reads the prompt in chunks. At a 32,000 token prompt it reached 246 to 247 tokens a second, against about 67 for the one-at-a-time replay. At 1,000 tokens it read 524 to 531. The output was identical to the replay on 23 of 23 test prompts, checked bit by bit.

Two other variants measured even faster, and we left them off. They add numbers in a different order. Adding the same numbers in a different order can give a slightly different result, and a different last digit can flip a word. Speed was not the gate. Identity was.

Why the order mattered

  1. Measure first. The trace named the cost before we touched code.
  2. Cheap, safe changes first. Wider loads changed no math.
  3. Check identity at every step. A faster step that changed the answer would be worth nothing.
  4. Count the thing you remove. Launches went down by exactly the number we claimed.
  5. Write the bar before the round. It is the only way to know when you missed it.

What this does not show

All of it is one card, one model and one day. The numbers are medians of 20 prompts, and the gain on a single prompt can differ, because each prompt picks different experts. We have not shown the same gains on other models or cards.

Words you may not know

  • Kernel: a small program that runs on the card.
  • Launch: one start of a kernel. Each has a small fixed cost.
  • Router: the part of a mixture-of-experts model that picks which experts work.
  • Trace: a record of what the card ran and when.
  • Prefill: reading the prompt before writing the first new token.
  • Median: the middle value of a sorted list.

Try it

The engine is on the mojo-baro project page with code on GitHub. Each step above has a protocol in its bench/ folder.

You can try the first habit on any program you own: before changing anything, record where the time goes. Ask about the results at gllm.forum.

Forty-Two to One Hundred Eleven has each round in detail, and Prefill as a Batch covers the batched reading.

Commentaires

Pas encore de commentaires.

Se connecter pour commenter.