Redian新闻
>
真·ChatGPT平替:无需显卡,MacBook、树莓派就能运行LLaMA

真·ChatGPT平替:无需显卡,MacBook、树莓派就能运行LLaMA

公众号新闻
机器之心报道
编辑:小舟

Meta 发布的开源系列模型 LLaMA,将在开源社区的共同努力下发挥出极大的价值。


Meta 在上个月末发布了一系列开源大模型 ——LLaMA(Large Language Model Meta AI),参数量从 70 亿到 650 亿不等。由于模型参数量较少,只需单张显卡即可运行,LLaMA 因此被称为 ChatGPT 的平替。发布以来,已有多位开发者尝试在自己的设备上运行 LLaMA 模型,并分享经验。

虽然相比于 ChatGPT 等需要大量算力资源的超大规模的语言模型,单张显卡的要求已经很低了,但还能更低!最近有开发者实现了在 MacBook 上运行 LLaMA,还有开发者成功在 4GB RAM 的树莓派上运行了 LLaMA 7B。

这些都得益于一个名为 llama.cpp 的新项目,该项目在 GitHub 上线三天,狂揽 4.6k star。



项目地址:https://github.com/ggerganov/llama.cpp

Georgi Gerganov 是资深的开源社区开发者,曾为 OpenAI 的 Whisper 自动语音识别模型开发 whisper.cpp。

这次,llama.cpp 项目的目标是在 MacBook 上使用 4-bit 量化成功运行 LLaMA 模型,具体包括:

  • 没有依赖项的普通 C/C++ 实现;
  • Apple silicon first-class citizen—— 通过 Arm Neon 和 Accelerate 框架;
  • AVX2 支持 x86 架构;
  • 混合 F16 / F32 精度;
  • 4-bit 量化支持;
  • 在 CPU 上运行。

llama.cpp 让开发者在没有 GPU 的条件下也能运行 LLaMA 模型。项目发布后,很快就有开发者尝试在 MacBook 上运行 LLaMA,并成功在 64GB M2 MacBook Pro 上运行了 LLaMA 7B 和 LLaMA 13B。


在 M2 MacBook 上运行 LLaMA 的方法:https://til.simonwillison.net/llms/llama-7b-m2

如果 M2 芯片 MacBook 这个条件还是有点高,没关系,M1 芯片的 MacBook 也可以。另一位开发者分享了借助 llama.cpp 在 M1 Mac 上运行 LLaMA 模型的方法。


在 M1 Mac 上运行 LLaMA 的方法:https://dev.l1x.be/posts/2023/03/12/using-llama-with-m1-mac/

除了在 MacBook 上运行,还有开发者借助 llama.cpp 在 4GB RAM Raspberry Pi 4 上成功运行了 LLaMA 7B 模型。Meta 首席 AI 科学家、图灵奖得主 Yann LeCun 也点赞转发了。


以上是 3 个在普通硬件设备上成功运行 LLaMA 模型的例子,几位开发者都是借助 llama.cpp 实现的,可见 llama.cpp 项目的实用与强大。我们来具体看一下 llama.cpp 的使用方法。

以 7B 模型为例,运行 LLaMA 的大体步骤如下:

# build this repogit clone https://github.com/ggerganov/llama.cppcd llama.cppmake# obtain the original LLaMA model weights and place them in ./modelsls ./models65B 30B 13B 7B tokenizer_checklist.chk tokenizer.model# install Python dependenciespython3 -m pip install torch numpy sentencepiece# convert the 7B model to ggml FP16 formatpython3 convert-pth-to-ggml.py models/7B/ 1# quantize the model to 4-bits./quantize.sh 7B# run the inference./main -m ./models/7B/ggml-model-q4_0.bin -t 8 -n 128

运行更大的 LLaMA 模型,需要设备有足够的存储空间来储存中间文件。

如果想获得像 ChatGPT 一样的交互体验,开发者只需要以 - i 作为参数来启动交互模式。

./main -m ./models/13B/ggml-model-q4_0.bin -t 8 -n 256 --repeat_penalty 1.0 --color -i -r "User:" \                                           -p \"Transcript of a dialog, where the User interacts with an Assistant named Bob. Bob is helpful, kind, honest, good at writing, and never fails to answer the User's requests immediately and with precision.
User: Hello, Bob.Bob: Hello. How may I help you today?User: Please tell me the largest city in Europe.Bob: Sure. The largest city in Europe is Moscow, the capital of Russia.User:"

使用 --color 区分用户输入和生成文本之后,显示效果如下:


一番操作下来,开发者就能在自己的简单设备上运行 LLaMA 模型,获得类 ChatGPT 的开发体验。以下是项目作者 Georgi Gerganov 给出的 LLaMA 7B 模型详细运行示例:

make -j && ./main -m ./models/7B/ggml-model-q4_0.bin -p "Building a website can be done in 10 simple steps:" -t 8 -n 512I llama.cpp build info:I UNAME_S:  DarwinI UNAME_P:  armI UNAME_M:  arm64I CFLAGS:   -I.              -O3 -DNDEBUG -std=c11   -fPIC -pthread -DGGML_USE_ACCELERATEI CXXFLAGS: -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -pthreadI LDFLAGS:   -framework AccelerateI CC:       Apple clang version 14.0.0 (clang-1400.0.29.202)I CXX:      Apple clang version 14.0.0 (clang-1400.0.29.202)make: Nothing to be done for `default'.main: seed = 1678486056llama_model_load: loading model from './models/7B/ggml-model-q4_0.bin' - please wait ...llama_model_load: n_vocab = 32000llama_model_load: n_ctx   = 512llama_model_load: n_embd  = 4096llama_model_load: n_mult  = 256llama_model_load: n_head  = 32llama_model_load: n_layer = 32llama_model_load: n_rot   = 128llama_model_load: f16     = 2llama_model_load: n_ff    = 11008llama_model_load: ggml ctx size = 4529.34 MBllama_model_load: memory_size =   512.00 MB, n_mem = 16384llama_model_load: .................................... donellama_model_load: model size =  4017.27 MB / num tensors = 291main: prompt: 'Building a website can be done in 10 simple steps:'main: number of tokens in prompt = 151 -> ''  8893 -> 'Build'292 -> 'ing'263 -> ' a'4700 -> ' website'508 -> ' can'367 -> ' be'2309 -> ' done'297 -> ' in'29871 -> ' '29896 -> '1'29900 -> '0'2560 -> ' simple'6576 -> ' steps'29901 -> ':'sampling parameters: temp = 0.800000, top_k = 40, top_p = 0.950000Building a website can be done in 10 simple steps:1) Select a domain name and web hosting plan2) Complete a sitemap3) List your products4) Write product descriptions5) Create a user account6) Build the template7) Start building the website8) Advertise the website9) Provide email support10) Submit the website to search enginesA website is a collection of web pages that are formatted with HTML. HTML is the code that defines what the website looks like and how it behaves.The HTML code is formatted into a template or a format. Once this is done, it is displayed on the user's browser.The web pages are stored in a web server. The web server is also called a host. When the website is accessed, it is retrieved from the server and displayed on the user's computer.A website is known as a website when it is hosted. This means that it is displayed on a host. The host is usually a web server.A website can be displayed on different browsers. The browsers are basically the software that renders the website on the user's screen.A website can also be viewed on different devices such as desktops, tablets and smartphones.Hence, to have a website displayed on a browser, the website must be hosted.A domain name is an address of a website. It is the name of the website.The website is known as a website when it is hosted. This means that it is displayed on a host. The host is usually a web server.A website can be displayed on different browsers. The browsers are basically the software that renders the website on the user’s screen.A website can also be viewed on different devices such as desktops, tablets and smartphones. Hence, to have a website displayed on a browser, the website must be hosted.A domain name is an address of a website. It is the name of the website.A website is an address of a website. It is a collection of web pages that are formatted with HTML. HTML is the code that defines what the website looks like and how it behaves.The HTML code is formatted into a template or a format. Once this is done, it is displayed on the user’s browser.A website is known as a website when it is hostedmain: mem per token = 14434244 bytesmain:     load time =  1332.48 msmain:   sample time =  1081.40 msmain:  predict time = 31378.77 ms / 61.41 ms per tokenmain:    total time = 34036.74 ms

看来,LLaMA 将在 Meta 和开源社区的共同努力下,成为众多开发者钻研大规模语言模型的入口。

探寻隐私计算最新行业技术,「首届隐语开源社区开放日」报名启程


春暖花开之际,诚邀广大技术开发者&产业用户相聚活动现场,体验数智时代的隐私计算生态建设之旅,一站构建隐私计算产业体系知识:

  • 隐私计算领域焦点之性

  • 分布式计算系统的短板与升级策略

  • 隐私计算跨平台互联互通

  • 隐语开源框架金融行业实战经验

3月29日,北京·798机遇空间,隐语开源社区开放日,期待线下面基。

点击阅读原文,立即报名。

© THE END 

转载请联系本公众号获得授权

投稿或寻求报道:[email protected]

微信扫码关注该文公众号作者

戳这里提交新闻线索和高质量文章给我们。
相关阅读
大型语言模型也能跑在浏览器上了!又一ChatGPT平替诞生,训练成本8.5万美元22~23岁末年初出行记 2:圣诞日被泄露的大语言模型LLaMA,引爆ChatGPT平替狂潮笔记本就能运行的ChatGPT平替来了,附完整版技术报告ChatGPT 全球最大开源平替:回复更受欢迎,但中文对话一塌糊涂用树莓派集群进行并行和分布式计算 | Linux 中国斯坦福“草泥马”火了:100美元就能比肩GPT-3.5!手机都能运行的那种孟晚舟将首次出任华为轮值董事长/ 百度All in类ChatGPT项目/ 知乎因ChatGPT大涨50%…今日更多新鲜事在此ChatGPT平替「小羊驼」Mac可跑!2行代码单GPU,UC伯克利再发70亿参数开源模型斯坦福“草泥马”火了:100美元就能比肩GPT-3.5!手机就能运行树莓派基金会推出网页端代码编辑器辞旧迎新之旅: 大自然的颂歌真·从零复刻ChatGPT!斯坦福等开启「红睡衣」计划,先开源1.2万亿token训练集lāo dao?láo dao!特制自己的ChatGPT:多接口统一的轻量级LLM-IFT平台ChatGPT讲座:ChatGPT并不神秘,但ChatGPT很神奇树莓派推出一体式USB调试套件,售价12美元支持麦姐和沈香,也谈同情心和廉耻树莓派推出一体式 USB 调试套件,售价 12 美元无需豪掷数亿购买硬件,用笔记本就能运行650亿参数大模型:这位程序员仅用一晚上就做到了树莓派获得索尼投资,芯片将集成 AI将你的树莓派用作流媒体服务器 | Linux 中国Meta开源的ChatGPT平替到底好不好用?测试结果、加料改装方法已出炉,2天5.2k星开源LLM领域变天!LLaMa惊天泄露引爆ChatGPT平替狂潮ChatGPT 们难以复制的原因,除了耗显卡,还有水电费太贵?ChatGPT全球最大开源平替:回复更受欢迎,但中文对话一塌糊涂你养我小,我养你老使用一块树莓派主板测量圆周率 | Linux 中国反击!Google 版 ChatGPT 首次亮相,有一个功能「碾压」ChatGPT三星 Galaxy Book 3 Ultra 笔记本真机曝光,对标苹果 MacBook Pro集成ChatGPT后必应日活量首破亿!微软推出Azure OpenAI ChatGPT 服务,GPT-4下周发布开发者笑疯了! LLaMa惊天泄露引爆ChatGPT平替狂潮,开源LLM领域变天新 MacBook Pro 首发测评/Open AI推出ChatGPT检测器/DC宇宙公布新计划用树莓派制作的问答售货机 | Linux 中国我的朋友越来越少了!
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。