270m,1b)用于设备端和仅 CPU 的工作负载。在本地运行适合您硬件的版本,然后配对 Tokios 连接器,通过 https://api.tokios.com 从任何机器、团队成员或托管代理调用它 — 无需入站端口,无需 VPN。
使用 Ollama 在本地运行
两个版本都在 Ollama 库中。对于 Gemma 4,拉取并运行默认标签(即E4B 边缘模型):
ollama run gemma4:12b、ollama run gemma4:26b(MoE)或 ollama run gemma4:31b。对于上一代,ollama run gemma3 运行 4b 默认版本 — 有关完整的标签列表,请参阅 gemma4 和 gemma3 库页面 — 本文档重点介绍如何连接它,而非每个运行时细节。
Ollama 的默认上下文窗口较小(2048 令牌)— 远低于 Gemma 原生的 128K–256K。在您的 Modelfile 或客户端请求中提高
num_ctx 以使用更多的上下文。变体与标签
以下所有值均来自模型卡片和 Ollama 库。标签和下载大小会随新量化的发布而变化 — 在标准化选择之前,请对照 ollama.com/library/gemma4 和 ollama.com/library/gemma3 进行确认。
来源:ollama.com/library/gemma4, ollama.com/library/gemma3, google/gemma-4-31B-it, google/gemma-4-26B-A4B-it, google/gemma-4-E4B-it, google/gemma-4-12B-it。
量化与格式
Ollama’s default tags areGGUF Q4_K_M. The gemma4 library also publishes -it-qat (quantization-aware-trained int4), -q8_0, -bf16, -mlx (Apple Silicon), -mxfp8, and -nvfp4 (NVIDIA Blackwell) variants for each size. Which format you can run depends on your hardware — see Quantization formats and the hardware they need for the full matrix, and what quantization is for how to read the Q4_K_M-style names.
硬件需求——Gemma 4 是否适合您的 GPU?
在合理的上下文长度下,舒适度约为Q4。请将每项视为估算值——实际情况是实际 GGUF 大小加上您上下文的 KV 缓存。有关 sizing 计算,请参见 多大的模型适合您的 GPU?。
运行它 — 从入门到高级
- Ollama(最简单)
- LM Studio(图形界面)
- vLLM(高级)
- SGLang(高级)
http://127.0.0.1:11434 上监听。提高 num_ctx 以使用更多上下文,并替换为 gemma4:12b、gemma4:26b 或 gemma4:31b 以获得更高档次,或替换为 gemma3 以使用上一代。功能特性
- Reasoning: Gemma 4 supports a configurable thinking mode, off by default. Enable it by including the
<|think|>control token at the start of the system prompt (orenable_thinking=Trueif you’re using the model card’sparse_responsehelper); the model then emits step-by-step reasoning before its final answer. - 原生工具调用: 是,在 Gemma 4 上支持 — 模型卡片记录了用于结构化工具使用和智能体工作流的原生函数调用,使用标准的
system/user/assistant角色。 - 视觉: 多模态 — 整个 Gemma 4 系列均接受文本和图像(支持可变宽高比和分辨率);Gemma 3(
4b及以上版本)也具备视觉能力。 - Audio:
E2BandE4Bonly — native automatic speech recognition (ASR) and speech-to-translated-text, up to 30 seconds of audio per request. - Long context: 131,072 tokens natively on
E2B/E4B, 262,144 tokens on12B,26B-A4B, and31B.
通过 Tokios 进行连接
Gemma 在本地运行后,配对 Tokios 连接器,以便从 Claude Code、Cline 或任何其他兼容客户端以https://api.tokios.com 方式访问它 — 而不仅限于从 localhost:11434 访问。
1
配对 Tokios 连接器
在 tokios.com/console 登录,打开 Setup 选项卡,然后单击 Start pairing 获取一次性领取代码(Then approve the device on the Setup or Connectors tab.
TKS-XXXX-XXXX)。在运行 Ollama 的机器上安装并运行连接器:Windows
macOS
Linux
2
将连接器指向 Ollama 的 /v1 API
Ollama 在
/v1 处提供与 OpenAI 兼容的接口。对于单模型设置,控制台的设置向导会自动将其填写为 http://127.0.0.1:11434/v1。对于多模型,请在 tokios-connector.json 中显式设置 — 参见 连接器配置。3
注册部署
在 Models 选项卡中,注册模型并选择一个公共部署名称,例如
gemma-tunnel。此名称 — 而非 Ollama 的本地模型 ID — 是客户端在 model 字段中发送的内容。4
创建 API 密钥
在 Keys 选项卡中,单击 Create key。立即复制
sk-tok-… 密钥 — 它仅显示一次。从任意位置调用
注意事项
- Gemma 4 的思维模式 默认关闭 — 与某些其他推理家族相反。如果您希望逐步推理,必须通过
<|think|>控制令牌或您客户端的等效项进行选择。 - 音频输入(自动语音识别和语音翻译)仅在
E2B和E4B尺寸上有效 —12B、26B-A4B和31B仅接受文本和图像。 - The
26B-A4BMoE needs all 26B parameters in memory even though only about 4B are active per token — size your hardware off the full download, not the active count. - 许可因版本而异:Gemma 4 采用 Apache 2.0 许可且无需审批,而 Gemma 3 使用 Google 的自定义 Gemma license,其 Hugging Face 检查点为 gated(下载前需接受条款;Ollama 标签在相同许可下重新分发)。Google 的 Gemma 禁止使用政策同时适用于两者 — 在商业或敏感部署前,请查阅 license terms。
- Gemma 3 对于非常小型且对 CPU 友好的部署(
270m、1b)仍然有用,在这些场景中,Gemma 4 的最小版本(E2B)可能仍比您的需求更重。
同级别新替代方案。 Meta 的 Muse Glimmer 30B 与
gemma4:31b 处于同一级别 — 密集、多模态、Apache 2.0 许可,并针对单张消费级 GPU 进行尺寸优化。Meta 直接对它们进行基准测试,其数据偏向 Muse Glimmer,但这些测试由厂商运行,尚无独立复现结果。Gemma 4 仍覆盖更广泛的范围,从边缘硬件上的 E2B 到 31B;而 Muse Glimmer 仅提供单一尺寸。请在您的实际工作负载中测试两者。快速入门
配对连接器并注册您的第一个端到端模型。
哪种尺寸的模型适合您的 GPU?
在拉取模型前,请根据可用显存匹配 Gemma 版本。
量化与硬件
Gemma 的哪些格式 —
GGUF、QAT、MLX、NVFP4 — 能在您的硬件上运行。哪种本地模型适用于哪种任务?
按任务查看 Gemma 与其他本地模型的对比。