Llama2模型本地部署(Mac M1 16G)
作者:mmseoamin日期:2024-04-30

环境准备

环境:Mac M1 16G、Conda

Conda创建环境配置

使用Anaconda-Navigator创建python 3.8环境

Llama2模型本地部署(Mac M1 16G),第1张

切换到新建的conda环境:

conda activate llama38

Llama2模型本地部署(Mac M1 16G),第2张

llama.cpp

找一个目录,下载llama.cpp

git clone https://github.com/ggerganov/llama.cpp

进入llama.cpp目录

cd llama.cpp

安装依赖环境

pip install -r requirements.txt

编译代码

LLAMA_METAL=1 make

下载中文模型 chinese-alpaca-2-7b-64k-hf,可以去下面的地址查找GitHub - ymcui/Chinese-LLaMA-Alpaca-2: 中文LLaMA-2 & Alpaca-2大模型二期项目 + 64K超长上下文模型 (Chinese LLaMA-2 & Alpaca-2 LLMs with 64K long context models) 

我这边选用的7b模型,再大就不好运行起来了

Llama2模型本地部署(Mac M1 16G),第3张

下载后放置在llama.cpp/models目录下

Llama2模型本地部署(Mac M1 16G),第4张

模型转换

python convert.py models/chinese-alpaca-2-7b-64k-hf/

量化模型

./quantize ./models/chinese-alpaca-2-7b-64k-hf/ggml-model-f16.gguf ./models/chinese-alpaca-2-7b-64k-hf/ggml-model-q4_0.gguf q4_0

Server方式启动, host和port可选, 不写则启动127.0.0.1 8080

./server --host 0.0.0.0 --port "$port" -m ./models/chinese-alpaca-2-7b-64k-hf/ggml-model-q4_0.gguf -c 4096 -ngl 1

启动成功直接打开页面,我这边没有指定host和port,http://localhost:8080/

Llama2模型本地部署(Mac M1 16G),第5张

开始对话

Llama2模型本地部署(Mac M1 16G),第6张

Llama2模型本地部署(Mac M1 16G),第7张