网易首页 > 网易号 > 正文 申请入驻

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

0
分享至

机器之心报道

编辑:小舟

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 repo

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

make

# obtain the original LLaMA model weights and place them in ./models

ls ./models

65B 30B 13B 7B tokenizer_checklist.chk tokenizer.model

# install Python dependencies

python3 -m pip install torch numpy sentencepiece

# convert the 7B model to ggml FP16 format

python3 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 512

I llama.cpp build info:I UNAME_S: Darwin

I UNAME_P: arm

I UNAME_M: arm64

I CFLAGS: -I. -O3 -DNDEBUG -std=c11 -fPIC -pthread -DGGML_USE_ACCELERATE

I CXXFLAGS: -I. -I./examples -O3 -DNDEBUG -std=c++11 -fPIC -pthread

I LDFLAGS: -framework Accelerate

I 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 = 1678486056

llama_model_load: loading model from './models/7B/ggml-model-q4_0.bin' - please wait ...llama_model_load: n_vocab = 32000

llama_model_load: n_ctx = 512

llama_model_load: n_embd = 4096

llama_model_load: n_mult = 256

llama_model_load: n_head = 32

llama_model_load: n_layer = 32

llama_model_load: n_rot = 128

llama_model_load: f16 = 2

llama_model_load: n_ff = 11008

llama_model_load: ggml ctx size = 4529.34 MB

llama_model_load: memory_size = 512.00 MB, n_mem = 16384

llama_model_load: .................................... done

llama_model_load: model size = 4017.27 MB / num tensors = 291

main: prompt: 'Building a website can be done in 10 simple steps:'

main: number of tokens in prompt = 15

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.950000

Building a website can be done in 10 simple steps:1) Select a domain name and web hosting plan

2) Complete a sitemap

3) List your products

4) Write product descriptions

5) Create a user account

6) Build the template

7) Start building the website

8) Advertise the website

9) Provide email support

10) Submit the website to search engines

A 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 hosted

main: mem per token = 14434244 bytes

main: load time = 1332.48 ms

main: sample time = 1081.40 ms

main: predict time = 31378.77 ms / 61.41 ms per token

main: total time = 34036.74 ms

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

特别声明:以上内容(如有图片或视频亦包括在内)为自媒体平台“网易号”用户上传并发布,本平台仅提供信息存储服务。

Notice: The content above (including the pictures and videos if any) is uploaded and posted by a user of NetEase Hao, which is a social media platform and only provides information storage services.

相关推荐
热点推荐
多库连场世界波,曼城争冠悬念续命

多库连场世界波,曼城争冠悬念续命

绿茵狂热者
2026-05-12 07:17:34
主角:四个女人四种结局,李青娥惨死,米兰嫁富商,花彩香最可惜

主角:四个女人四种结局,李青娥惨死,米兰嫁富商,花彩香最可惜

阿废冷眼观察所
2026-05-13 01:40:05
伊朗:已将高浓缩铀送往第三国!若谈判失败,伊朗会将其取回

伊朗:已将高浓缩铀送往第三国!若谈判失败,伊朗会将其取回

AI商业论
2026-05-11 08:36:11
突发!走了,才29岁!李凯尔悲痛万分…

突发!走了,才29岁!李凯尔悲痛万分…

左右为篮
2026-05-13 06:45:51
果然降温了!今晚,又出利空了!

果然降温了!今晚,又出利空了!

老A情报圈
2026-05-13 00:29:21
绝了!伊朗又想出了一个招,把全世界都看傻了

绝了!伊朗又想出了一个招,把全世界都看傻了

扬子的故事屋
2026-05-11 10:09:53
A股:刚刚,两个大消息传来,释放一信号,明日将迎来更大的变盘

A股:刚刚,两个大消息传来,释放一信号,明日将迎来更大的变盘

云鹏叙事
2026-05-13 00:00:12
茶叶是血糖的“加速器”?医生忠告:不想血糖升高,少喝4种茶

茶叶是血糖的“加速器”?医生忠告:不想血糖升高,少喝4种茶

橘子约定
2026-05-12 20:44:04
中国男乒四大“贵公子”:家境优渥不缺钱,仍为梦想拼尽全力

中国男乒四大“贵公子”:家境优渥不缺钱,仍为梦想拼尽全力

郭揦包工头
2026-04-29 16:09:40
俄乌战场“最破防”的,从来不是士兵,而是中国炮兵专家?

俄乌战场“最破防”的,从来不是士兵,而是中国炮兵专家?

阿器谈史
2026-05-10 04:07:48
以总理称伊朗导弹有中国的零部件?外交部:反对没有事实依据的无端指责

以总理称伊朗导弹有中国的零部件?外交部:反对没有事实依据的无端指责

澎湃新闻
2026-05-12 15:48:26
谁,在为俞浩的“表演”埋单?

谁,在为俞浩的“表演”埋单?

小蜜情感说
2026-05-12 16:06:53
好牛逼的状元!29岁带队进西决,30岁带队进东决,31岁带队进东决

好牛逼的状元!29岁带队进西决,30岁带队进东决,31岁带队进东决

球毛鬼胎
2026-05-12 11:24:51
颠覆认知!鱼油 Omega-3 或加速脑功能衰退,降低脑细胞运行效率

颠覆认知!鱼油 Omega-3 或加速脑功能衰退,降低脑细胞运行效率

思思夜话
2026-05-12 13:01:13
大伯出狱全家没人接,我开车去接他,他偷偷塞我一张卡说有1200万

大伯出狱全家没人接,我开车去接他,他偷偷塞我一张卡说有1200万

千秋文化
2026-05-09 20:08:48
消费者称厕所漏水在啄木鸟平台上申请维修,因不同意维修方案,拒修后被收500元检测费

消费者称厕所漏水在啄木鸟平台上申请维修,因不同意维修方案,拒修后被收500元检测费

山西经济日报
2026-05-12 15:19:36
心理学研究40年发现:被人算计后,拼命反击是在喂养对方恶意,选择示弱只会越陷越深,真正看透“投射反噬”的人没人敢惹

心理学研究40年发现:被人算计后,拼命反击是在喂养对方恶意,选择示弱只会越陷越深,真正看透“投射反噬”的人没人敢惹

心理观察局
2026-05-12 09:06:31
马光远:AI泡沫一定会破灭,而且一定会以非常惨烈的方式破灭!

马光远:AI泡沫一定会破灭,而且一定会以非常惨烈的方式破灭!

混沌录
2026-05-10 19:32:20
开车四小时为送一顿饭!张凌赫爸妈横店探班,这才是顶级“投喂”

开车四小时为送一顿饭!张凌赫爸妈横店探班,这才是顶级“投喂”

小丸子Showw
2026-05-11 20:19:26
无缘提前夺冠 41岁C罗遭绝平后无奈瘫坐替补席 失望摊手+径直离场

无缘提前夺冠 41岁C罗遭绝平后无奈瘫坐替补席 失望摊手+径直离场

我爱英超
2026-05-13 05:00:12
2026-05-13 07:28:49
机器之心Pro incentive-icons
机器之心Pro
专业的人工智能媒体
12979文章数 142648关注度
往期回顾 全部

科技要闻

宇树发布载人变形机甲,定价390万元起

头条要闻

特朗普称将同中方讨论对台军售和黎智英案 外交部回应

头条要闻

特朗普称将同中方讨论对台军售和黎智英案 外交部回应

体育要闻

骑士终于玩明白了?

娱乐要闻

白鹿风波升级!掉粉20万评论区沦陷

财经要闻

利润再腰斩 京东干外卖后就没过过好日子

汽车要闻

吉利银河“TT”申报图曝光 电动尾翼+激光雷达

态度原创

房产
游戏
健康
手机
公开课

房产要闻

穗八条引爆楼市!万博宝藏红盘,五一劲销出圈

《GTA6》期望太大口碑可能翻车?T2 CEO都怕了

干细胞能让人“返老还童”吗

手机要闻

谷歌携手苹果升级换机体验:iPhone转安卓可迁移密码、主屏布局

公开课

李玫瑾:为什么性格比能力更重要?

无障碍浏览 进入关怀版