打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
如何在个人电脑上运行类Chat GPT的Alpaca?

一、什么是Alpaca?

Alpaca是斯坦福大学开发的一个小型人工智能语言模型。与ChatGPT、Google Bard、Bing Chat等人工智能相比,它的独特之处在于体积小,性能强大,据称堪比ChatGPT 3.5。使用者不会遇到向OpenAI申请ChatGPT账户的困难,经过简单的安装和配置,就可以在本地计算机上运行Alpaca,而且无需连接互联网,更加安全且方便。

如果你想体验一下大型语言模型(LLM),又不想大费周章,还冒着泄露信息的风险的话,在本地使用Alpaca无疑是一个绝佳的选择。

图片来源: Stanford.edu

二、安装Alpaca

(一)硬件

Alpaca对硬件的要求很低,无需专用的GPU,在AMD2200G、16G DDR4 这样的老爷机上也可以顺畅运行。还有人将其安装在了树莓派4这种袖珍机上,但响应就非常慢了。

(二)软件

现在很多资料都是关于如何在类Linux的环境下使用Alpaca,而一般人还是更熟悉Windows系统。以下是在Windows环境下安装和使用Alpaca的步骤

首先需要下载和安装所有必要的软件、代码及训练模型。

1. 安装CMake

安装CMake,地址为:

https://cmake.org/download/

记得将CMake加在Windows的PATH路径中。

2. 安装VS

安装Visual Studio 2022,选中“使用C++的桌面开发”,地址为:

https://visualstudio.microsoft.com/downloads/

有介绍MinGW与CMake配合的资料,但没有配置MinGW成功,还是VS更简单,配置完成的截图如下:

3. 安装Git

下载并安装Git,地址为:

https://desktop.github.com/

在Git上,将以下地址的代码克隆到本地:

https://github.com/antimatter15/alpaca.cpp

4. 下载训练模型

接下来需要下载训练模型,目前有7B和13B两个版本,建议选尺寸较小的7B,地址为:

https://gateway.estuary.tech/gw/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC

将下载的文件更名为“ggml-alpaca-7b-q4.bin”,存放在克隆代码目录中。

三、编译及测试

最后是编译源代码,生成可执行文件,再以训练模型为基础进行测试对话。

1. 编译

运行Windows下的命令行终端,进入克隆代码的目录。输入以下指令:

cmake .

cmake --build . --config Release

编译生成chat.exe,进程显示如下 :

  正在生成代码...

chat.vcxproj-> D:\alpaca\alpaca.cpp\Release\chat.exe

Building Custom Rule 

D:/alpaca/alpaca.cpp/CMakeLists.txt

  quantize.cpp

  utils.cpp

  正在生成代码...

  quantize.vcxproj -> 

D:\alpaca\alpaca.cpp\Release\quantize.exe

  Building Custom Rule 

D:/alpaca/alpaca.cpp/CMakeLists.txt

2. 测试 

运行chat.exe,在“>”提示符下即可输入问题,开始与Alpaca对话。下图是它对询问宇宙年龄、写一首关于春天的诗、谁命名了“中国”的回答:

D:\alpaca\alpaca.cpp>.\Release\chat.exe

main: seed = 1680657283

llama_model_load: loading model from 'ggml-alpaca-7b-q4.bin' - please wait ...

llama_model_load: ggml ctx size = 6065.34 MB

llama_model_load: memory_size =  2048.00 MB, n_mem = 65536

llama_model_load: loading model part 1/1 from 'ggml-alpaca-7b-q4.bin'

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

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

system_info: n_threads = 4 / 4 | AVX = 1 | AVX2 = 1 | AVX512 = 0 | FMA = 0 | NEON = 0 | ARM_FMA = 0 | F16C = 0 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 0 | SSE3 = 0 | VSX = 0 |

main: interactive mode on.

sampling parameters: temp = 0.100000, top_k = 40, top_p = 0.950000, repeat_last_n = 64, repeat_penalty = 1.300000

== Running in chat mode. ==

 - Press Ctrl+C to interject at any time.

 - Press Return to return control to LLaMA.

 - If you want to submit another line, end your input in '\'.

> what is the age of the universe?

The current estimate for when our Universe was created (the Big Bang) is 13-14 billion years ago, so it's around this time that we can say the Universe has been in existence.

> can you write a poem of spring?

The sun shines brightly on my face;

A gentle breeze carries away all traces of winter’s chill, and I feel alive again!  The birds are singing their sweet songs in the trees. A warmth fills me as nature awakens once more… Spring has arrived at last!

> Who named China?

The name "China" was given to this country by a Greek historian, Herodotus (485- 425 BC). He used the term as an alternative for the word 'Barbaria' which he had heard from his Persian friends.

3. 简评

Alpaca简单易用,可以给用户较好的体验。缺点是暂时不支持中文,毕竟训练模型就是英文的。貌似已有高手在更改模型,以便让它支持中文。

从使用来看,人工智能非常依赖高质量的训练材料。离开人对它的指导和训练,人工智能还只是人工智障。当然,这并不是在否认人工智能将对人类生活产生巨大的帮助,但绝没有到令人恐慌的程度。现在的媒体和舆论一味贩卖焦虑,没有客观认识这一新事物的新发展是不恰当的,靠炒作来的一阵风来发展人工智能也是不可能持久的。

参考资料:

https://crfm.stanford.edu/2023/03/13/alpaca.html

https://github.com/antimatter15/alpaca.cpp

https://beebom.com/how-run-chatgpt-like-language-model-pc-offline/

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
无需GPU,在 CPU 上使用 llama.cpp高速推理
这个新闻可能比GPT4还要大
LeCun转赞:在苹果M1/M2芯片上跑LLaMA!130亿参数模型仅需4GB内存
中文LLaMA&Alpaca大语言模型词表扩充+预训练+指令精调
惊天秘密,首发3行代码,0资源,就能跑免费LLAMA 30B大模型
5分钟快速运行Llama 2
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服