Understanding Go AI Inference: What Is Inference?

valyala1 pts0 comments

What is Inference? | Internals for Interns<br>Welcome to a new series! For most developers today, using a large language model means one thing: an HTTP call to somebody else&rsquo;s computer. You send a prompt to an API, tokens come back, and everything in between is somebody else&rsquo;s magic.<br>But here&rsquo;s what I find much more interesting: you can run these models locally, inside your own process, on your own hardware โ€” and if you&rsquo;re a Go developer, you can do it directly from Go. Two projects make this genuinely pleasant today: Yzma , which lets Go call the llama.cpp libraries directly (without cgo โ€” that gets its own article later in the series), and Kronk , which builds a high-level, OpenAI-API-feeling SDK and model server on top of Yzma. And underneath both of them sits llama.cpp , the C/C++ inference engine that made running LLMs on ordinary hardware practical.<br>In this series we&rsquo;re going to understand that whole stack from the inside: what llama.cpp actually does when it &ldquo;runs a model,&rdquo; how Yzma manages to call it from Go, and how Kronk turns all of that into an engine you&rsquo;d actually want in production.<br>๐Ÿ“Œ A note on scope<br>The goal of this article is to understand the mechanics around the model โ€” how a model file is stored, loaded, and run โ€” not what happens inside the neural network itself. The math inside those layers is a whole topic of its own, and it&rsquo;s out of scope here.<br>The llama.cpp details are against master as of July 2026 (commit ad8d8219) โ€” llama.cpp moves fast and doesn&rsquo;t do stable releases, so I&rsquo;m pinning a commit instead of a version. And this is deliberately a conceptual tour: we&rsquo;re not going to get into the C++ code details. We&rsquo;ll also stay out of the Go layers entirely โ€” Yzma and Kronk get their own articles.

With the scope set, let&rsquo;s dive in.<br>What Inference Actually Is<br>Let&rsquo;s start by demystifying the word. A language model has two very different lives.<br>The first life is training : you show the model terabytes of text, and an optimization process gradually adjusts billions of numbers โ€” the weights (also called parameters ) โ€” until the model gets good at one narrow task: given a sequence of text, predict what comes next. Training takes months and data centers. We&rsquo;re not talking about training in this series, at all.<br>The second life is inference : training is over, the weights are frozen, and now you just&mldr; use them. The best mental model is a plain, pure function: it takes two inputs โ€” your sequence of text and those billions of frozen weights โ€” and returns one output, a prediction for the next token. Something like nextToken(input, weights). That&rsquo;s it. That&rsquo;s the whole secret. No learning happens, nothing is updated โ€” the weights are read-only arguments, so a model file is exactly as smart the millionth time you call it as the first.<br>๐Ÿ“Œ A note on weights<br>If you&rsquo;re curious about how much memory those weights actually take up โ€” how quantization shrinks them, and why they usually dominate the VRAM you need to run a model locally โ€” Kronk&rsquo;s VRAM calculator write-up is a nice read.

So when you download a &ldquo;model,&rdquo; what you&rsquo;re downloading is essentially a giant pile of frozen numbers โ€” those weights โ€” plus a description of how to use them. And &ldquo;running&rdquo; the model means doing a very large amount of arithmetic between your input and those numbers. If that sounds suspiciously hand-wavy, don&rsquo;t worry: we&rsquo;ll demystify the weights later in the article, when we crack open an actual model file. For now, all you need to hold on to is that a model is a huge pile of numbers that somebody else already calculated for you.<br>We&rsquo;ve already mentioned tokens a couple of times now โ€” but what exactly is a token? Let&rsquo;s see.<br>Tokens: the model&rsquo;s alphabet<br>There&rsquo;s one catch before any arithmetic can happen: models don&rsquo;t read text. They work with tokens โ€” integer IDs from a fixed vocabulary, where each ID corresponds to a chunk of text (a word, a piece of a word, a punctuation mark).<br>Our prompt &ldquo;The capital of France is " might become something like five or six token IDs โ€” say [791, 6864, 315, 9822, 374] (the exact IDs depend entirely on the model&rsquo;s vocabulary). From this point on, the model never sees letters again; everything downstream is done in terms of these integers.<br>So the model receives a list of integers. What does it actually do with them?<br>One pass, one prediction<br>Here&rsquo;s the shape of the computation, stripped to its essence. One important thing up front: the model doesn&rsquo;t process the input word by word in separate rounds โ€” the whole sequence of tokens goes through the network together, in a single pass, and out comes a single prediction. Let&rsquo;s walk through it with this diagram:

Reading it left to right, we start by converting each token ID into an embedding โ€” a vector of numbers that represents the...

rsquo model weights inference tokens from

Related Articles