当前位置: 首页 > news >正文

在Windows或Mac上安装并运行LLAMA2

LLAMA2在不同系统上运行的结果

LLAMA2 在windows 上运行的结果

LLAMA2 在Mac上运行的结果

安装Llama2的不同方法

方法一:

 编译 llama.cpp

克隆 llama.cpp

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

通过conda 创建或者venv. 下面是通过conda 创建的。

conda create --name llama_test python=3.9
conda activate llama_test

安装python依赖的包

pip3 install -r requirements.txt

编译llama.cpp

mac

LLAMA_METAL=1 make

windows , 用powershell 运行 make

下载llama2模型

直接在huggingface里下载量化了的 gguf格式的llama2模型。

https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGUF/tree/main

我下载的是llama-2-7b-chat.Q4_0.gguf

拷贝llama-2-7b-chat.Q4_0.gguf 到llama.cpp目录里的models目录里

运行模型

如果是windows,要用powershell

./main -m ./models/llama-2-7b-chat.Q4_0.gguf --color --ctx_size 2048 -n -1 -ins -b 256 --top_k 10000 --temp 0.2 --repeat_penalty 1.1 -t 8

方法二:

Meta已将llama2开源,任何人都可以通过在meta ai上申请并接受许可证、提供电子邮件地址来获取模型。 Meta 将在电子邮件中发送下载链接。

下载llama2 

  • 获取download.sh文件,将其存储在mac上
  • 打开mac终端,执行 chmod +x ./download.sh 赋予权限。
  • 运行 ./download.sh 开始下载过程
  • 复制电子邮件中的下载链接,粘贴到终端
  • 仅下载13B-chat

安装系统依赖的东西


必须安装 Xcode 才能编译 C++ 项目。 如果您没有,请执行以下操作:

xcode-select --install

接下来,安装用于构建 C++ 项目的依赖项。

brew install pkgconfig cmake

最后,我们安装 Torch。

如果您没有安装python3,请通过以下方式安装

brew install python@3.11

像这样创建一个虚拟环境:

/opt/homebrew/bin/python3.11 -m venv venv

激活 venv。

source venv/bin/activate

安装 PyTorch:

pip install --pre torch torchvision --extra-index-url https://download.pytorch.org/whl/nightly/cpu

编译 llama.cpp

克隆 llama.cpp

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

安装python依赖包

pip3 install -r requirements.txt

编译

LLAMA_METAL=1 make

如果你有两个arch (x86_64, arm64), 可以用下面指定arm64

arch -arm64 make

将下载的 13B 移至 models 文件夹下的 llama.cpp 项目。

将模型转换为ggml格式
13B和70B是不一样的。 Convert-pth-to-ggml.py 已弃用,请使用 Convert.py 代替

13B-chat

 python3 convert.py --outfile ./models/llama-2-13b-chat/ggml-model-f16.bin --outtype f16 ./models/llama-2-13b-chat

Quantize 模型:

In order to run these huge LLMs in our small laptops we will need to reconstruct and quantize the model with the following commands, here we will convert the model’s weights from float16 to int4 requiring less memory to be executed and only losing a little bit of quality in the process.

13B-chat:

./quantize ./models/llama-2-13b-chat/ggml-model-f16.bin ./models/llama-2-13b-chat/ggml-model-q4_0.bin q4_0

运行模型

./main -m ./models/llama-2-13b-chat/ggml-model-q4_0.bin -t 4 -c 2048 -n 2048 --color -i -r '### Question:' -p '### Question:'

您可以使用 -ngl 1 命令行参数启用 GPU 推理。 任何大于 0 的值都会将计算负载转移到 GPU。 例如:

./main -m ./models/llama-2-13b-chat/ggml-model-q4_0.bin -t 4 -c 2048 -n 2048 --color -i -ngl 1 -r '### Question:' -p '### Question:'

在我的 Mac 上测试时,它比纯 cpu 快大约 25%。

其它

ggml格式的llama2

如果你下载的是ggml格式的, 要运行下面命令转换格式

python convert-llama-ggml-to-gguf.py --eps 1e-5 -i ./models/llama-2-13b-chat.ggmlv3.q4_0.bin -o ./models/llama-2-13b-chat.ggmlv3.q4_0.gguf.bin
(llama) C:\Users\Harry\PycharmProjects\llama.cpp>python convert-llama-ggml-to-gguf.py --eps 1e-5 -i ./models/llama-2-13b-chat.ggmlv3.q4_0.bin -o ./models/llama-2-13b-chat.ggmlv3.q4_0.gguf.bin
* Using config: Namespace(input=WindowsPath('models/llama-2-13b-chat.ggmlv3.q4_0.bin'), output=WindowsPath('models/llama-2-13b-chat.ggmlv3.q4_0.gguf.bin'), name=None, desc=None, gqa=1, eps='1e-5', context_length=2048, model_metadata_dir=None, vocab_dir=None, vocabtype='spm')=== WARNING === Be aware that this conversion script is best-effort. Use a native GGUF model if possible. === WARNING ===- Note: If converting LLaMA2, specifying "--eps 1e-5" is required. 70B models also need "--gqa 8".
* Scanning GGML input file
* File format: GGJTv3 with ftype MOSTLY_Q4_0
* GGML model hyperparameters: <Hyperparameters: n_vocab=32000, n_embd=5120, n_mult=256, n_head=40, n_layer=40, n_rot=128, n_ff=13824, ftype=MOSTLY_Q4_0>=== WARNING === Special tokens may not be converted correctly. Use --model-metadata-dir if possible === WARNING ===* Preparing to save GGUF file
This gguf file is for Little Endian only
* Adding model parameters and KV items
* Adding 32000 vocab item(s)
* Adding 363 tensor(s)gguf: write headergguf: write metadatagguf: write tensors
* Successful completion. Output saved to: models\llama-2-13b-chat.ggmlv3.q4_0.gguf.bin

参考资料

GitHub - facebookresearch/llama: Inference code for LLaMA models

A comprehensive guide to running Llama 2 locally – Replicate

相关文章:

  • 【六、http】go的http的客户端重定向
  • UE5——源码阅读——4——引擎预初始化
  • 【PWN · heap | unlink】hitcon2014_stkof
  • Box2d 物理画线,Cocos Creator 3.8
  • Ubuntu定时执行日志备份及删除脚本
  • PySpark 优雅的解决依赖包管理
  • 如何在idea中使用maven搭建tomcat环境
  • 【网络协议】聊聊HTTPS协议
  • 一 Java初探
  • NoSQL数据库使用场景以及架构介绍
  • stable diffusion安装踩坑之clip安装、git报错
  • C4D 2024终于发布,速度翻倍!模拟模块大更新!
  • 【数据结构与算法】JavaScript实现哈希表
  • JavaEE-博客系统2(功能设计)
  • CM3D2 汉化杂记
  • create-react-app做的留言板
  • es6
  • Eureka 2.0 开源流产,真的对你影响很大吗?
  • Git 使用集
  • Phpstorm怎样批量删除空行?
  • spring boot 整合mybatis 无法输出sql的问题
  • Vue小说阅读器(仿追书神器)
  • 工程优化暨babel升级小记
  • 关于Java中分层中遇到的一些问题
  • 欢迎参加第二届中国游戏开发者大会
  • 基于HAProxy的高性能缓存服务器nuster
  • 经典排序算法及其 Java 实现
  • 实战|智能家居行业移动应用性能分析
  • 移动端唤起键盘时取消position:fixed定位
  • (52)只出现一次的数字III
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (ZT)薛涌:谈贫说富
  • (二十三)Flask之高频面试点
  • (附源码)ssm基于jsp的在线点餐系统 毕业设计 111016
  • (机器学习-深度学习快速入门)第一章第一节:Python环境和数据分析
  • (力扣题库)跳跃游戏II(c++)
  • (一)80c52学习之旅-起始篇
  • (一)使用Mybatis实现在student数据库中插入一个学生信息
  • (转)Java socket中关闭IO流后,发生什么事?(以关闭输出流为例) .
  • ***php进行支付宝开发中return_url和notify_url的区别分析
  • ./include/caffe/util/cudnn.hpp: In function ‘const char* cudnnGetErrorString(cudnnStatus_t)’: ./incl
  • .net core 客户端缓存、服务器端响应缓存、服务器内存缓存
  • .net core 依赖注入的基本用发
  • .NET(C#、VB)APP开发——Smobiler平台控件介绍:Bluetooth组件
  • .net/c# memcached 获取所有缓存键(keys)
  • .NET/C# 获取一个正在运行的进程的命令行参数
  • .NET框架类在ASP.NET中的使用(2) ——QA
  • .php结尾的域名,【php】php正则截取url中域名后的内容
  • @kafkalistener消费不到消息_消息队列对战之RabbitMq 大战 kafka
  • @Pointcut 使用
  • @RequestMapping-占位符映射
  • @Transaction注解失效的几种场景(附有示例代码)
  • [ web基础篇 ] Burp Suite 爆破 Basic 认证密码
  • [ 手记 ] 关于tomcat开机启动设置问题
  • [AIGC] 如何建立和优化你的工作流?