Llama2模型本地部署(Mac M1 16G)

环境准备

环境:Mac M1 16G、Conda

Conda创建环境配置

使用Anaconda-Navigator创建python 3.8环境

切换到新建的conda环境:

bash 复制代码
conda activate llama38

llama.cpp

找一个目录,下载llama.cpp

bash 复制代码
git clone https://github.com/ggerganov/llama.cpp

进入llama.cpp目录

bash 复制代码
cd llama.cpp

安装依赖环境

bash 复制代码
pip install -r requirements.txt

编译代码

bash 复制代码
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模型,再大就不好运行起来了

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

模型转换

bash 复制代码
python convert.py models/chinese-alpaca-2-7b-64k-hf/

量化模型

bash 复制代码
./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

bash 复制代码
./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/

开始对话

相关推荐
凉年技术1 天前
Claude Code 完整上手指南
ai
vi_h1 天前
在 macOS 上通过 Docker 安装并运行 Ollama(详细可执行教程)
macos·docker·ollama
曲幽2 天前
FastAPI流式输出实战与避坑指南:让AI像人一样“边想边说”
python·ai·fastapi·web·stream·chat·async·generator·ollama
后端AI实验室2 天前
用AI写代码,我差点把漏洞发上线:血泪总结的10个教训
java·ai
程序员鱼皮2 天前
67个AI编程必会知识,1.6w字一次讲透!女友:“你要考研啊?!”
ai·程序员·编程·ai编程·vibe coding
DigitalOcean3 天前
DigitalOcean Gradient AI 推理云平台原生集成 LlamaIndex
llama
后端AI实验室3 天前
我用Cursor开发了3个月,整理出这套提效4倍的工作流
java·ai
牧马人win3 天前
Microsoft Agent Framework 详解与实践
ai