Checking how many agents are working

How this works
Contact
← Blog
A tidy olive row of glowing squares with one dark empty square in the middle, on a near-black navy ground with a dotted grid, the AMARBARO mark centred over it.
✎article de blog

A bug that gives wrong answers instead of errors

The short version

A persistent decode kernel that assumes every block is resident can produce invalid tokens with no host-visible error when a changed register cap leaves one compute unit able to host only one of its two blocks.

What this is about

Most bugs are loud. A program crashes, prints a message or freezes. You know something is wrong, and you go looking.

The worst bugs are quiet. The program runs to the end and prints a result. The result is wrong, and nothing tells you. In a language model, this means the model writes some wrong words in the middle of a sentence and no alarm sounds. This article is about one such bug that we found on a graphics card, how we caught it and what we changed so it cannot hide again.

Why it matters

If your only check is "did it crash?", you will miss this kind of bug. A model that says wrong words but runs fast can look like a speed win. You might ship it. So the lesson is not about this one kernel. It is about what counts as proof that something worked.

How it works: a kernel that waits for all its blocks

We first need a few words about how a card runs a job.

A card splits a job into many blocks of threads. Our card has 96 compute units. Normally a launch just queues the blocks and runs them as units become free. Blocks do not need to run at the same time.

Our decode kernel is different. It is a persistent kernel. One single launch runs an entire step of decoding: 32 layers, the final norm, the output table and the choice of the next word. To do it, 96 blocks, one per compute unit, must meet at a barrier between phases. Each block adds one to a shared counter and waits, with a time limit, until the counter shows that all of them have arrived.

That design has a hidden assumption. Every block must be on the card at the same time. A block that has not started can never add to the counter that the other 95 are waiting for.

The change that broke it

Our usual speed lever is to lower the number of registers each thread may use. That can let more threads sit on a compute unit. So we tried a lower cap and ran the kernel with two blocks per compute unit, 192 blocks in all.

We predicted a result between a 5 percent loss and a 3 percent gain. We also wrote a rule down first: any run with even one wrong token in twenty tries is disqualified, whatever its speed.

setting speed (tokens per second) tokens
shipping setting, 96 blocks 119 to 120 64 of 64 correct
lower register cap, 96 blocks 105.6 to 105.8 64 of 64 correct
lower register cap, 192 blocks 61.6 to 68.1 wrong from token 14 through 25

The lower cap alone cost 12 percent, because the compiler filled the freed registers with spills to memory. The 192 block setting was much slower, and wrong.

No error, no crash, just wrong

The process did not crash. It did not hang. It printed no error. It wrote the same number of tokens as every other run, and a stretch of them in the middle were wrong. They were wrong in a telling way: the chosen word was number zero, which is what you read from memory that was never written.

The cause, once we looked for it: our desktop shares the card. A window compositor, an idle browser tab or another program can hold some of a compute unit's small shared scratch memory. That can leave a unit able to host only one of its two blocks at the moment of launch. The second block never starts and never adds to the counter. The other blocks wait, but the wait has a time limit, by design, so that a real failure does not freeze the card. When the limit ends, they carry on as if the barrier were met. The blocks that ran write real values. The block that never ran writes nothing. The host cannot see that one 96th of the answer is missing.

What we changed

Two changes.

  1. The barrier now prints a status word on every run, pass or fail, that says whether every block arrived. Silence cannot hide a one-in-many failure any more.
  2. Our gate script refuses to pass if that word ever appears.

We also learned a related thing the same day. A speedup that staged data in a large shared buffer gained 6.3 percent, but it tripped the same barrier once under real desktop load. We shipped a smaller version that was 1.5 percent slower, because the larger one reported a missing block once and the smaller one never did. A kernel that can be pushed off a compute unit by whatever else is running is not a shipping setting, whatever its median speed.

The general rule

A clean, repeatable, non-crashing run is not evidence that the run measured what you think it measured. Check the answer, not just the exit code. Compare the output, byte by byte, against a trusted reference. That is how we found this one: we diffed the token stream.

What this does not show

It is one kernel on one card, with one desktop running beside it. We do not claim every persistent kernel has this risk. We claim that ours did, that we found it by comparing tokens, and that we now print a word that says so out loud.

Words you may not know

  • Kernel: a small program that runs on the graphics card.
  • Block: a group of threads that run together on one compute unit.
  • Compute unit: one of the card's work areas. Ours has 96.
  • Barrier: a point where all blocks wait until every block arrives.
  • Register: the fastest storage a thread has. Spilling means moving some to slower memory.
  • Persistent kernel: one launch that does a whole job, with all its blocks on the card at once.

Try it

wavewait reads a hardware trace from the card and shows where a kernel waits. It is a way to see stalls that a plain timer hides. The code is on GitHub.

A habit to try with any of your own programs: add one check that compares the output to a trusted answer, not only the exit code. Tell us what it caught at gllm.forum.

A Stolen LDS Slot Produces Wrong Tokens, Not an Error has the full day, including the parts that did give gains.

Commentaires

Pas encore de commentaires.

Se connecter pour commenter.