各种办法尝试个遍,这样弄保证你能开始玩儿。
准备
PC一台,有无GPU随意。硬盘几十G。
Python3.11以上。
根据是否由GPU、GPU型号不同,安装不同的PyTorch(PyTorch安装指令)
下载Gemma
- 安装HuggingFace CLI
- 下载:
huggingface-cli download --local-dir . google/gemma-2b-it
Clone
git clone https://github.com/aiXpertLab/Run-Google-Gemma-Locally-on-Desktop-Laptop.git
源码
# from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "google/gemma-2b-it"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model=AutoModelForCausalLM.from_pretrained("google/gemma-2b-it", device_map="auto")
input_text = "write me a poem about beautifuly woman."
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")
outputs = model.generate(**input_ids)
print(tokenizer.decode(outputs[0]))
更多更详细的内容,在github✨⭐✨:
点个⭐,码更行!
https://github.com/aiXpertLab/Run-Google-Gemma-Locally-on-Desktop-Laptop
点个赞,开源❤️!