Google开源轻量 开源模型

Gemma 2 2

Gemma系列 · Google · 2024-06发布

开源支持本地部署国内可直连有免费额度

模型介绍

Google 开源轻量模型系列,基于 Gemini 同源技术,27B 在同等规模中性能领先,适合在自有硬件上运行。

模型基础信息

模型系列Gemma系列
开发机构Google
发布时间2024-06
参数规模2B / 9B / 27B
上下文窗口8K
模型类型文本
中文能力良好
使用方式网页体验 / API调用 / 本地部署

免费额度与收费政策

开源免费

免费规则详情

权重免费下载,遵守 Gemma 使用条款即可商用(禁止滥用用途)。

收费标准简介

本地运行零成本;Google Cloud Vertex AI 托管按 token 计费。

模型能力介绍

✅ 核心优势

  • 与 Gemini 同源技术,同尺寸性能领先
  • 2B / 9B / 27B 覆盖轻量到中端
  • 在自有硬件上运行成本极低
  • 指令跟随与多语言较稳健

⚠️ 短板与局限

  • 默认上下文仅 8K,长文本受限
  • 中文能力弱于国内同尺寸模型
  • 许可为自定义协议,需阅读条款

🎯 适用场景

  • 端侧与边缘设备推理
  • 低成本对话与内容生成
  • 教育与研究实验
  • 数据敏感场景的本地部署

模型使用教程

本章节整理 Gemma 2 的在线体验、API调用、本地部署全套入门教程,快速上手使用该模型。

  • 27B:性能最强,需 24GB+ 显存(量化)。
  • 9B:均衡,单卡 16GB 可运行。
  • 2B:轻量,适合端侧与快速实验。
  • 注意 Gemma 采用自定义许可,商用需遵守其使用条款(无限制商用但禁止特定用途)。

体验地址:https://aistudio.google.com/prompts/new_chat

在 Hugging Face 的 google/gemma-2-9b-it 页面同意协议后下载:

HF_ENDPOINT=https://hf-mirror.com huggingface-cli download google/gemma-2-9b-it --local-dir ./gemma-2-9b
from transformers import AutoTokenizer, AutoModelForCausalLM
tok = AutoTokenizer.from_pretrained("./gemma-2-9b")
model = AutoModelForCausalLM.from_pretrained("./gemma-2-9b", device_map="auto")
ids = tok("请介绍量子计算", return_tensors="pt").input_ids
print(tok.decode(model.generate(ids, max_new_tokens=128)[0], skip_special_tokens=True))
# Ollama 一键运行
ollama pull gemma2:9b
ollama run gemma2:9b

Transformers

from transformers import AutoTokenizer, AutoModelForCausalLM
tok = AutoTokenizer.from_pretrained("google/gemma-2-9b-it")
model = AutoModelForCausalLM.from_pretrained("google/gemma-2-9b-it", device_map="auto")
ids = tok("请介绍量子计算", return_tensors="pt").input_ids
print(tok.decode(model.generate(ids, max_new_tokens=128)[0], skip_special_tokens=True))

💡 使用小技巧

用 Ollama 一键运行:ollama pull gemma2

9B 只需 16GB 显存(Q4 量化 6GB 即可),是单卡首选。

❓ 常见问题 FAQ

Q1:Gemma 和 Gemini 什么关系?

A1:Gemma 是 Google 从 Gemini 技术蒸馏的开源轻量模型。

Q2:可以商用吗?

A2:可以,但需遵守 Gemma 使用条款。

访问备注与注意事项