goccy/go-llama
Running large language models with nothing but pure Go code
go-llama takes llama.cpp, the widely used engine for running AI models, compiles it to WebAssembly, and then translates that into plain Go source. The result runs GGUF model files without cgo or any shared library, as a single static binary. No wasm runtime is needed at execution time since everything has already become native Go.
What it does
- llama.cpp is compiled to WebAssembly via the llama-wasm project, then translated into Go source code by wasm2go, so no wasm runtime runs at execution time.
- A single Llama instance can load multiple models, and each model can spawn multiple contexts (each keeping its own KV cache) so one model can serve several independent conversations, or multiple models can be loaded together for speculative decoding, where a small draft model speeds up a larger target model.
- It supports streaming, where generated text is delivered piece by piece as it decodes, and interruption, which lets another goroutine (Go's lightweight thread) stop a running generation immediately.
- Sandbox options let you restrict which directory the engine can see and cap its memory growth, so an oversized model fails safely inside the guest rather than crashing the host process.
- Because wasm32 caps linear memory at 4 GiB, and model weights plus every context's KV cache must fit inside that space, the practical target is roughly a 3B-parameter model quantized to Q4.
Why it matters
Because it needs no cgo and no separate shared library, a single Go build produces a portable binary that can be cross-compiled and deployed anywhere Go runs, from servers to CLI tools to embedded systems. This removes the usual friction of installing native inference libraries when adding LLM features to a Go project.
Terms in this repo
- cgo · a Go feature that lets Go code call C libraries
- GGUF · a compact file format used to store AI model weights, common in the llama.cpp ecosystem
- WebAssembly (wasm) · a low-level bytecode format designed to run portably across environments
- KV cache · per-conversation memory that stores previous computation results to speed up generating the next word
- speculative decoding · a technique where a small model predicts ahead and a larger model verifies the predictions in one pass, speeding up generation
Repository description (English)
llama.cpp in pure Go
Open on GitHubTrending repos
- liustack/modlensA plugin that lets text-only AI models like DeepSeek 'see' pasted images by turning them into structured text data
- vorssaint/vorssaint-utilsOne free menu bar app replaces a dozen paid Mac utilities
- MadsLorentzen/ai-job-searchAn open-source framework that runs your entire job search through Claude Code, built by someone who actually got hired using it
- rohitg00/ai-engineering-from-scratchA free hands-on curriculum that teaches AI by having you build every piece from scratch, from math to shippable agents
- AgriciDaniel/claude-obsidianAn open-source second brain that lets Claude Code file your notes into Obsidian while you keep full ownership of the files
- openclaw/openclawA personal AI assistant that lives on your own devices and talks to you through the messaging apps you already use
- tashfeenahmed/freellmapiAn open-source router that stitches 34 free LLM tiers into one API key so your app never hits a rate limit
- Alishahryar1/free-claude-codeA local proxy that lets coding AI agents run on 49 free or cheap model providers instead of one paid service
Latest from METAL LAB
- 우크라이나 전장 AI 데이터셋, 영국에 처음 열렸다
- Chinese State-Backed Hackers Double Attack Volume Using AI
- As Fable Gets Pricier, Developers Split Coding Work Across Models Like GLM 5.2
- General Intuition's Valuation Triples to $6 Billion in Weeks
- Google Workspace signup blocks legitimate domains, mistaking them for email providers