Checking how many agents are working

How this works
Contatti
← Blog
A single dark graphics card glowing with olive light inside, a chat bubble of teal light rising from it, the AMARBARO mark centered.
✎post del blog

mojo-baro: our chat engine for one AMD card

The short version

On matched Q4_0 weights mojo-baro decodes Qwythos-9B at 148.89 tokens per second against llama.cpp at 111.34 on the same machine, a 1.34 times ratio measured on Mojo 1.1.0.

Part 8 of 20 in Tools we built and why. Previous: ctxd: keeping long AI sessions short · Next: mojo-neuron: a microscope for a language model

What this is about

A language model is a large file of numbers. To chat with it, a program has to read that file, do a great deal of arithmetic for every word it writes, and send the words back. Such a program is called an inference engine. The popular ones are written to run everywhere, so they cannot be tuned for any one card.

mojo-baro is an inference engine for one family of cards: AMD's RDNA3, and in practice one RX 7900 XTX. Every GPU kernel in it is written in Mojo, a language that reads like Python and compiles to run close to the machine. It reads a GGUF model file, builds an engine for that model, and serves chat over a web address that other programs already know how to talk to.

Why it matters

The RX 7900 XTX has 24 GB of memory, more than most consumer cards. That is enough to run a 9-billion-parameter model on your own desk, with no cloud account and no data leaving your house. The question we wanted to answer is how much speed the general-purpose libraries leave on the table on this card.

That question has a measurable answer, and the answer should come with its protocol. Each result in the repository has a preregistered protocol, a check you can run, and a date. A result measured on an older toolchain says so.

How it works

There are three parts.

  1. The front. baro-serve is a small web server written in Rust. It handles the chat template, the tokenizer, tool calls, rules that force JSON output, the request queue, cancelling a request, and a health check. It speaks an OpenAI-style API and an Ollama-style API, so a client built for either can connect.
  2. The engine. A Mojo program built for one model's exact shape. The number of layers, the width, and the head counts are fixed when it is compiled, so the loops have known lengths and the compiler can unroll them. The price is that an engine built for a 9B model refuses a 27B one.
  3. The pack. Weights are not read from the GGUF file while you chat. A tool converts the file once into a pack, one flat file with weights laid out for the kernels that read them, plus an identity file that names the source by its sha256 hash.

Every reply says which decode path made it. mega runs one long-lived kernel per token for the whole model, and is the default for dense models. launch runs one kernel per operation, and is the reference path and the default for mixture-of-experts models. spec is speculative decoding with the model's own draft head, and its output is identical to plain greedy decoding. prefill reads your prompt in batches.

The numbers, and their date

On matched Q4_0 weights, the engine decoded the 9B model Qwythos at 148.89 tokens per second, while llama.cpp on the same machine decoded at 111.34. That is a ratio of 1.34. The check is a protocol in the repository's bench folder, and the claim fails if the 20-prompt median ratio is 1.0 or lower.

That result was measured on Mojo 1.1.0. The repository now uses Mojo 1.2.0. On 1.2, one path, the K-quant megakernel, reads 87.90 tokens per second against 98.29 for the launch path on the same pack. We do not yet know why. Choosing the launch path with BARO_MEGA=0 is the workaround. So the headline number is true for its date and its toolchain. It is not a promise about today's build.

How to do it, step by step

The project page lists the commands. All go through tools/baro.

  1. Get a GGUF model file. We keep ours outside the repository.
  2. Run serve MODEL.gguf --port N. The first time, it builds the engine and the pack for that file's shape. That takes a few minutes, and both are cached under ~/.cache/baro/. Later runs of the same file start in seconds.
  3. Chat in a terminal with chat, or open a desktop window with gui.
  4. To see whether a pack is already built, run pack-path MODEL.gguf. It says PACK FOUND or PACK MISS, and never builds.

Our proxy ctxd, which speaks the OpenAI chat shape, can sit in front of a chat like this to keep long sessions short.

What it does not do

The limits are as useful as the numbers.

  • Only one card is measured. Other RDNA3 cards use the same instruction set, so the kernels should build, but their tuning is not measured.
  • RDNA4 builds and passes an emulated check on the RDNA3 card. No RDNA4 card has run it, so its numbers are unverified.
  • The CPU path is correct and slow: 6 to 7 tokens per second with 8 threads, and 0.48 beside one busy job. It runs only the dense shape.
  • Each model shape needs its own engine build.
  • The desktop window's Apply restart has been tested only with a fake command.
  • The Qwen2.5-0.5B row stays below the agreement bar, and its figures are unverified.

We also keep a document that lists settings that do nothing on one model. Keeping the Failures In tells the story of one.

Words you may not know

  • Inference: running a trained model to get answers.
  • GGUF: a file format for storing a model's numbers.
  • Kernel: a program that runs on the graphics card.
  • Token: a small piece of text a model reads or writes. Speed is counted in tokens per second.
  • Decode: the step where the model writes its answer one token at a time.
  • Q4_0: a way of storing each number in about four bits to save space.
  • VRAM: the memory on a graphics card.
  • Speculative decoding: guessing several tokens ahead and keeping the guesses that the model agrees with.

Try it

Commenti

Ancora nessun commento.

Accedi per commentare.