在发布Gemma 2一个月后,Google 扩展了其 Gemma 模型系列,新增了以下几款:
Gemma 2 2B- 这是 Gemma 2 的 2.6B 参数版本,是设备端使用的理想选择。https://hf.co/collections/google/gemma-2-2b-release-66a20f3796a2ff2a7c76f98f
ShieldGemma- 一系列安全分类器,基于 Gemma 2 训练,用于开发者过滤其应用程序的输入和输出。https://hf.co/collections/google/shieldgemma-release-66a20efe3c10ef2bd5808c79
Gemma Scope- 一个全面的、开放的稀疏自动编码器套件,适用于 Gemma 2 2B 和 9B。https://hf.co/collections/google/gemma-scope-release-66a4271f6f0b4d4a9d5e04e2
Gemma 2https://hf.co/blog/gemma2
让我们逐一看看这些新产品!
Gemma 2 2B
对于错过之前发布的用户,Gemma 是 Google 推出的一系列轻量级、先进的开源模型,使用创建 Gemini 模型的同样研究和技术构建。它们是支持英文的文本到文本,仅解码的大语言模型,开放预训练和指令调优版本的权重。这次发布的是 Gemma 2 的 2.6B 参数版本 (基础版和指令调优版) ,补充了现有的 9B 和 27B 版本。
基础版https://hf.co/google/gemma-2-2b
指令调优版https://hf.co/google/gemma-2-2b-it
Gemma 2 2B 与其他 Gemma 2 系列模型具有相同的架构,因此利用了滑动注意力和 Logit 软封顶技术等特性。你可以在我们之前的博客文章中查看更多详细信息。与其他 Gemma 2 模型一样,我们建议在推理中使用bfloat16
。
欢迎使用 Gemma 2 - Google 最新的开放大语言模型https://hf.co/blog/gemma2
使用 Transformers
借助 Transformers,你可以使用 Gemma 并利用 Hugging Face 生态系统中的所有工具。要使用 Transformers 与 Gemma 模型,请确保使用主版本中的 Transformers,以获取最新的修复和优化:
pip install git+https://github.com/huggingface/transformers.git --upgrade
然后,你可以使用如下代码与 Transformers 配合使用gemma-2-2b-it
:
from transformers import pipeline
import torch
pipe = pipeline(
"text-generation",
model="google/gemma-2-2b-it",
model_kwargs={"torch_dtype": torch.bfloat16},
device="cuda", # 在Mac上使用“mps”
)
messages = [
{"role": "user", "content": "你是谁?请用海盗的语言回答。"},
]
outputs = pipe(messages, max_new_tokens=256)
assistant_response = outputs[0]["generated_text"][-1]["content"].strip()
print(assistant_response)
啊哈,船员!我是 Gemma,一个数字恶棍,一个数字海洋中的语言鹦鹉。我在这里帮助你解决文字问题,回答你的问题,讲述数字世界的故事。那么,你有什么要求吗?🦜
关于如何使用 Transformers 与这些模型,请查看模型卡。
模型卡https://hf.co/google/gemma-2-2b-it
使用 llama.cpp
你可以在设备上运行 Gemma 2 (在 Mac、Windows、Linux 等设备上) ,只需几分钟即可使用 llama.cpp。
步骤 1:安装 llama.cpp
在 Mac 上你可以直接通过 brew 安装 llama.cpp。要在其他设备上设置 llama.cpp,请查看这里:https://github.com/ggerganov/llama.cpp?tab=readme-ov-file#usage
brew install llama.cpp
```注意:如果你从头开始构建 llama.cpp,请记住添加`LLAMA_CURL=1`标志。
步骤 2:运行推理
```bash
./llama-cli
-