在Windows或Mac上安装并运行LLAMA2

这篇具有很好参考价值的文章主要介绍了在Windows或Mac上安装并运行LLAMA2。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

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

LLAMA2 在windows 上运行的结果

在Windows或Mac上安装并运行LLAMA2,llama

LLAMA2 在Mac上运行的结果

在Windows或Mac上安装并运行LLAMA2,llama

安装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

在Windows或Mac上安装并运行LLAMA2,llama

拷贝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

在Windows或Mac上安装并运行LLAMA2,llama

方法二:

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

在Windows或Mac上安装并运行LLAMA2,llama

下载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

在Windows或Mac上安装并运行LLAMA2,llama

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

arch -arm64 make

在Windows或Mac上安装并运行LLAMA2,llama

在Windows或Mac上安装并运行LLAMA2,llama

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

在Windows或Mac上安装并运行LLAMA2,llama

将模型转换为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.

在Windows或Mac上安装并运行LLAMA2,llama

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 header
    gguf: write metadata
    gguf: 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文章来源地址https://www.toymoban.com/news/detail-744705.html

到了这里,关于在Windows或Mac上安装并运行LLAMA2的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 大模型部署手记(8)LLaMa2+Windows+llama.cpp+英文文本补齐

    组织机构:Meta(Facebook) 代码仓:https://github.com/facebookresearch/llama 模型:llama-2-7b 下载:使用download.sh下载 硬件环境:暗影精灵7Plus Windows版本:Windows 11家庭中文版 Insider Preview 22H2 内存 32G GPU显卡:Nvidia GTX 3080 Laptop (16G) 下载llama.cpp的代码仓: git clone https://github.com/ggergan

    2024年02月03日
    浏览(41)
  • 大模型部署手记(11)LLaMa2+Chinese-LLaMA-Plus-2-7B+Windows+llama.cpp+中文对话

    组织机构:Meta(Facebook) 代码仓:GitHub - facebookresearch/llama: Inference code for LLaMA models 模型:LIama-2-7b-hf、Chinese-LLaMA-Plus-2-7B   下载:使用huggingface.co和百度网盘下载 硬件环境:暗影精灵7Plus Windows版本:Windows 11家庭中文版 Insider Preview 22H2 内存 32G GPU显卡:Nvidia GTX 3080 Laptop (1

    2024年02月03日
    浏览(41)
  • 大模型部署手记(9)LLaMa2+Chinese-LLaMA-Plus-7B+Windows+llama.cpp+中文文本补齐

    组织机构:Meta(Facebook) 代码仓:GitHub - facebookresearch/llama: Inference code for LLaMA models 模型:llama-2-7b、Chinese-LLaMA-Plus-7B(chinese_llama_plus_lora_7b)   下载:使用download.sh下载 硬件环境:暗影精灵7Plus Windows版本:Windows 11家庭中文版 Insider Preview 22H2 内存 32G GPU显卡:Nvidia GTX 3080 La

    2024年02月03日
    浏览(40)
  • 大模型部署手记(10)LLaMa2+Chinese-LLaMA-Plus-7B+Windows+llama.cpp+中英文对话

    组织机构:Meta(Facebook) 代码仓:GitHub - facebookresearch/llama: Inference code for LLaMA models 模型:llama-2-7b、llama-2-7b-chat( 后来证明无法实现中文转换 )、Chinese-LLaMA-Plus-7B(chinese_llama_plus_lora_7b)   下载:使用download.sh下载 硬件环境:暗影精灵7Plus Windows版本:Windows 11家庭中文版

    2024年02月04日
    浏览(41)
  • 使用GGML和LangChain在CPU上运行量化的llama2

    Meta AI 在本周二发布了最新一代开源大模型 Llama 2。对比于今年 2 月发布的 Llama 1,训练所用的 token 翻了一倍,已经达到了 2 万亿,对于使用大模型最重要的上下文长度限制,Llama 2 也翻了一倍。 在本文,我们将紧跟趋势介绍如何在本地CPU推理上运行量化版本的开源Llama 2。 我

    2024年02月16日
    浏览(38)
  • 大模型部署手记(13)LLaMa2+Chinese-LLaMA-Plus-2-7B+Windows+LangChain+摘要问答

    组织机构:Meta(Facebook) 代码仓:GitHub - facebookresearch/llama: Inference code for LLaMA models 模型:chinese-alpaca-2-7b-hf、text2vec-large-chinese 下载:使用百度网盘和huggingface.co下载 硬件环境:暗影精灵7Plus Windows版本:Windows 11家庭中文版 Insider Preview 22H2 内存 32G GPU显卡:Nvidia GTX 3080 Laptop

    2024年02月04日
    浏览(33)
  • Sealos 国内集群正式上线,可一键运行 LLama2 中文版大模型!

    2023 年 7 月 19 日,MetaAI 宣布开源旗下的 LLama2 大模型,Meta 首席科学家、图灵奖得主 Yann LeCun 在推特上表示 Meta 此举可能将改变大模型行业的竞争格局。一夜之间,大模型格局再次发生巨变。 不同于 LLama,LLama2 免费可商用 ! LLama2 的能力在 GPT-3 ~ GPT-3.5 之间,对于关注数据隐

    2024年02月12日
    浏览(41)
  • llama.cpp LLM模型 windows cpu安装部署;运行LLaMA-7B模型测试

    参考: https://www.listera.top/ji-xu-zhe-teng-xia-chinese-llama-alpaca/ https://blog.csdn.net/qq_38238956/article/details/130113599 cmake windows安装参考:https://blog.csdn.net/weixin_42357472/article/details/131314105 1、下载: 2、编译 3、测试运行 参考: https://zhuanlan.zhihu.com/p/638427280 模型下载: https://huggingface.co/nya

    2024年02月15日
    浏览(42)
  • LLMs之LLaMA2:LLaMA2的简介(技术细节)、安装、使用方法(开源-免费用于研究和商业用途)之详细攻略

    LLMs之LLaMA-2:LLaMA-2的简介(技术细节)、安装、使用方法(开源-免费用于研究和商业用途)之详细攻略 导读 :2023年7月18日,Meta重磅发布Llama 2!这是一组预训练和微调的大型语言模型(LLM),规模从70亿到700亿个参数不等。Meta微调的LLM称为Llama 2-Chat,专为对话使用场景进行了优化

    2024年02月16日
    浏览(41)
  • Windows11下私有化部署大语言模型实战 langchain+llama2

    CPU:锐龙5600X 显卡:GTX3070 内存:32G 注:硬件配置仅为博主的配置,不是最低要求配置,也不是推荐配置。该配置下计算速度约为40tokens/s。实测核显笔记本(i7-1165g7)也能跑,速度3tokens/s。 Windows系统版本:Win11专业版23H2 Python版本:3.11 Cuda版本:12.3.2 VS版本:VS2022 17.8.3 lan

    2024年02月03日
    浏览(65)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包