Configs2026年7月19日·1 分钟阅读

gemma.cpp — Lightweight C++ Inference Engine for Google Gemma Models

A standalone, lightweight C++ inference engine from Google for running Gemma language models locally with minimal dependencies, designed for research experimentation and embedded deployment.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
gemma.cpp
直接安装命令
npx -y tokrepo@latest install cf72271b-8349-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

gemma.cpp is Google's official lightweight C++ implementation for running Gemma language models. It prioritizes simplicity and minimal dependencies over maximum throughput, making it a research-friendly alternative to larger inference frameworks. The single-file design and CPU-focused approach enable experimentation on laptops without GPU requirements.

What gemma.cpp Does

  • Runs Gemma 2B and 7B models in pure C++ with no external ML framework dependencies
  • Provides interactive text generation with streaming token output
  • Supports both instruction-tuned (IT) and base pretrained model variants
  • Implements core transformer operations using the Highway library for SIMD vectorization
  • Enables batch processing and embedding extraction for research workflows

Architecture Overview

The engine implements the Gemma transformer architecture (multi-query attention, GeGLU activations, RMSNorm) in C++ using Google's Highway library for portable SIMD operations. It loads model weights from a custom compressed format (.sbs), performs inference on CPU using matrix multiplication kernels optimized for the host architecture (SSE, AVX, NEON), and generates tokens autoregressively with configurable sampling parameters.

Self-Hosting & Configuration

  • Build with CMake on Linux, macOS, or Windows with a C++17 compiler
  • Download model weights from Kaggle in the supported .sbs format
  • Configure generation parameters (temperature, top-k, top-p) via command-line flags
  • Link as a library in custom C++ applications for embedded inference
  • Optionally enable OpenMP for multi-threaded matrix operations

Key Features

  • Minimal dependencies: only requires a C++17 compiler and CMake to build
  • Portable across CPU architectures with SIMD optimization via Highway
  • Small binary footprint suitable for embedded and edge deployment
  • Research-friendly single-codebase design for understanding transformer internals
  • Supports both Gemma 1 and Gemma 2 model architectures

Comparison with Similar Tools

  • llama.cpp — broader model support with GGUF format; gemma.cpp is Gemma-specific and Google-maintained
  • ONNX Runtime — general-purpose with GPU support; gemma.cpp is CPU-only and much lighter
  • Hugging Face Transformers — Python with full ecosystem; gemma.cpp is pure C++ with no Python
  • MediaPipe LLM — Google's mobile inference; gemma.cpp targets desktop and research use
  • MLC-LLM — compiler-based with broad hardware; gemma.cpp is simpler with manual optimization

FAQ

Q: Why use gemma.cpp instead of llama.cpp for Gemma models? A: gemma.cpp is Google's reference implementation with guaranteed correctness for Gemma architectures. llama.cpp offers broader model support and GPU acceleration.

Q: Does it support GPU acceleration? A: Currently it is CPU-only, focusing on portability and simplicity. For GPU inference, use Gemma via Hugging Face or vLLM.

Q: What are the hardware requirements? A: The 2B model runs comfortably on a laptop with 8GB RAM. The 7B model needs approximately 16GB of available memory.

Q: Can I use it for fine-tuned Gemma models? A: It supports loading custom weights in the .sbs format. You would need to convert fine-tuned weights from other formats.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产