A llama.cpp fork focused on CPU inference speed, with extra quantization types and features for running GGUF LLMs locally.
google/gemma.cpp
A lightweight, standalone C++ inference engine for running Google's Gemma models on CPU.
- Stars
- 7,079
- Forks
- 673
- Open issues
- 52
- Last commit
- 22 hours ago
What is it?
gemma.cpp is a minimalist C++ inference engine for Gemma-2, Gemma-3 and PaliGemma-2 models. It is built for experimentation and research, aiming to sit between deployment-oriented C++ runtimes and Python-based ML frameworks, with a small core implementation that is easy to read, modify and embed in other projects.
The engine runs CPU-only inference using Google Highway for portable SIMD, and integrates weight compression directly into its matrix multiplication, including a custom fp8 format, bf16, f32 and non-uniform 4-bit quantization. It also includes a backward pass and Adam optimizer for Gemma research.
The project provides C++ APIs with streaming for single and batched queries, a basic interactive command-line app, and Python bindings via pybind11. Weights are downloaded from Kaggle, and builds use CMake or Bazel on Linux, Windows and macOS.
Key features
- 01Runs Gemma-2, Gemma-3 and PaliGemma-2 inference on CPU.
- 02Integrates weight compression such as fp8, bf16 and 4-bit NUQ into GEMM.
- 03Uses Google Highway for portable SIMD and runtime ISA selection.
- 04Offers C++ streaming APIs for single and batched inference.
- 05Includes a basic interactive CLI and pybind11 Python bindings.
- 06Supports a backward pass and Adam optimizer for research.
Use cases
- Experimenting with low-level inference optimizations for Gemma models.
- Embedding a small local LLM runtime into a C++ application.
- Running Gemma or PaliGemma models on CPU-only machines for research.
- Studying a compact, readable LLM implementation.
Quick start
- 1
Install CMake and a Clang C++ compiler (C++17 or newer)
- 2
Download model weights and tokenizer from Kaggle (gemma2-2b-it-sfp recommended) and extract the archive
tar -xf archive.tar.gz - 3
Configure and build the gemma executable with CMake
cmake --preset make - 4
Run gemma with the tokenizer and weights files
./gemma --tokenizer tokenizer.spm --weights gemma2-2b-it-sfp.sbs
Things to know
- CPU-only inference; no GPU support.
- Requires downloading model weights from Kaggle after accepting a consent form.
- Building natively on Windows requires Visual Studio Build Tools with clang-cl; WSL is recommended instead.
- Designed for experimentation and research rather than production deployment.
Topics
FAQ
- What is gemma.cpp?
- A lightweight, standalone C++ inference engine for running Google's Gemma models on CPU. gemma.cpp is a minimalist C++ inference engine for Gemma-2, Gemma-3 and PaliGemma-2 models. It is built for experimentation and research, aiming to sit between deployment-oriented C++ runtimes and Python-based ML frameworks, with a small core implementation that is easy to read, modify and embed in other projects.
- Is gemma.cpp free to use? What license does it have?
- gemma.cpp is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is gemma.cpp still maintained?
- Actively maintained. The last commit to gemma.cpp was on Nov 6, 2026.
- What can I use gemma.cpp for?
- Experimenting with low-level inference optimizations for Gemma models. Embedding a small local LLM runtime into a C++ application. Running Gemma or PaliGemma models on CPU-only machines for research. Studying a compact, readable LLM implementation.
- How do I install gemma.cpp?
- Install CMake and a Clang C++ compiler (C++17 or newer) Download model weights and tokenizer from Kaggle (gemma2-2b-it-sfp recommended) and extract the archive: tar -xf archive.tar.gz Configure and build the gemma executable with CMake: cmake --preset make Run gemma with the tokenizer and weights files: ./gemma --tokenizer tokenizer.spm --weights gemma2-2b-it-sfp.sbs
- Where can I get gemma.cpp?
- The source code and installation instructions are on GitHub: https://github.com/google/gemma.cpp
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A C99 inference engine that runs the 2.78-trillion-parameter Kimi K3 model on a single CPU, streaming experts from disk with no GPU or BLAS.
Official CPU/GPU inference framework from Microsoft for 1-bit (ternary, 1.58-bit) large language models, built on llama.cpp.
C++ and Python library that runs Transformer models such as Whisper, Llama and NLLB faster and with less memory via quantization and optimized kernels.
Llama 2 style transformer inference written in pure Mojo, in a single file, using SIMD vectorization and multi-threading.
A plain C/C++ tensor library for machine learning, designed to be simple, portable and efficient with minimal setup.