外链论坛

 找回密码
 立即注册
搜索
查看: 47|回复: 0

告别 OpenAI,一个命令行跨平台运行开源百川大模型 Baichuan2-13B-Chat

[复制链接]

2642

主题

210

回帖

9778万

积分

论坛元老

Rank: 8Rank: 8

积分
97780482
发表于 2024-8-22 13:57:45 | 显示全部楼层 |阅读模式

想要快速起始,只需在自己的设备上运行下面的命令行就可与 Baichuan2-13B-Chat 交互。这个命令行工具会自动下载并安装 WasmEdge 运行时、模型文件和用于推理的完全可移植 Wasm 应用。

bash <(curl -sSfL https://code.flows.network/webhook/iwYN1SdN3AmPgR5ao5Gt/run-llm.sh)

Baichuan2-13B-Chat 大模型[1]是由于百川智能研发的 13B 大语言模型(LLM),其灵感来自于离线强化学习。据百川团队叫作,这种办法准许模型在偏好标签的状况下从混合质量的数据中学习,使其能够供给乃至能够繁杂的 ChatGPT 模型相媲美的卓越性能。

本文中,咱们将介绍:

怎样在自己的设备上运行  Baichuan2-13B-Chat 大模型怎样为 Baichuan2-13B-Chat 大模型创建一个与 OpenAI 兼容的 API 服务

咱们运用 Rust + Wasm 技术栈研发安排此模型的应用程序。不需要安装繁杂的 Python 包或 C++ 工具链!认识咱们选取这个技术栈的原由[2]。

在自己的设备上运行 Baichuan2-13B-Chat 大模型

过程1:经过以下命令行安装 WasmEdge[3]。

curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --plugin wasi_nn-ggml

过程2:下载该模型的GGUF 文件[4]。因为模型的体积为几个 GB,下载可能需要一按时间。

curl -LO https://huggingface.co/second-state/Baichuan2-13B-Chat-GGUF/resolve/main/Baichuan2-13B-Chat-ggml-model-q4_0.gguf

过程 3:下载聊天应用程序的跨平台可移植 Wasm 文件。该应用程序让你能用命令行与模型聊天。该应用程序的Rust 源代码在这儿[5]。

curl -LO https://github.com/second-state/LlamaEdge/releases/latest/download/llama-chat.wasm

完成啦!能够经过输入以下命令在终端与模型进行聊天。

wasmedge --dir .:. --nn-preload default:GGML:AUTO:Baichuan2-13B-Chat-ggml-model-q4_0.gguf llama-chat.wasm -p baichuan-2 -r用户:

可移植 Wasm 应用程序会自动利用我设备上的硬件加速器(如 GPU)。

在我 M1 32G 内存的 Mac 上,速度约为每秒 7.85 个 token。

[USER]:一个苹果5元钱,2个苹果多少钱?

[ASSITANT]:两个苹果需要支付10元钱。

[USER]:

为百川大模型创建与 OpenAI 兼容的 API 服务

与 OpenAI 兼容的 Web API 让该模型可与区别的 LLM 工具和代理框架(如 flows.network、LangChain 、LlamaIndex 等)一块工作。

下载一个 API 服务器应用程序。它是一个跨平台可移植的 Wasm 应用程序,能够各样区别 CPU 和 GPU 设备上运行。

curl -LO https://github.com/second-state/LlamaEdge/releases/latest/download/llama-api-server.wasm

而后,下载聊天设备人 Web UI,以经过聊天设备人 UI 与模型进行交互。

curl -LO https://github.com/second-state/chatbot-ui/releases/download/v0.1.0/chatbot-ui.tar.gz

tar xzf chatbot-ui.tar.gz

rm chatbot-ui.tar.gz

接下来,运用以下命令行起步模型的 API 服务器。而后,打开浏览器拜访 [http://localhost:8080] 起始聊天!

wasmedge --dir .:. --nn-preload default:GGML:AUTO:Baichuan2-13B-Chat-ggml-model-q4_0.gguf llama-api-server.wasm -p baichuan-2 -r用户:

能够从另一个终端运用 curl 与 API 服务器交互。

curl -X OST http://localhost:8080/v1/chat/completions \

  -H accept:application/json

 \

  -H Content-Type: application/json

 \

  -d {"messages":[{"role":"system", "content": "You are a helpful assistant."}, {"role":"user", "content": "李白是谁"}], "model":"Baichuan2-13B-Chat"}

这般。WasmEdge 是运行 LLM 应用程序最简单、最快速、最安全的方式[6]。尝试一下吧!

加入 WasmEdge Discord[7] 提问和分享见解。倘若在运行这个模型时有任何问题,请拜访 second-state/LlamaEdge[8] 提 issue,或预约 demo[9]。

参考资料

[1]

Baichuan2-13B-Chat 大模型: https://huggingface.co/baichuan-inc/Baichuan2-13B-Chat

[2]

认识咱们选取这个技术栈的原由: https://www.secondstate.io/articles/fast-llm-inference/

[3]

WasmEdge: https://github.com/WasmEdge/WasmEdge

[4]

GGUF 文件: https://huggingface.co/second-state/Baichuan2-13B-Chat-GGUF/tree/main

[5]

Rust 源代码在这儿: https://github.com/second-state/llama-utils/tree/main/chat

[6]

运行 LLM 应用程序最简单、最快速、最安全的方式: https://www.secondstate.io/articles/fast-llm-inference/

[7]

WasmEdge Discord: https://discord.com/invite/U4B5sFTkFc

[8]

second-state/LlamaEdge: https://github.com/second-state/LlamaEdge/

[9]

demo: https://code.flows.network/webhook/vvAtEBUk6QMhVVLuw7IU

关于 WasmEdge

WasmEdge 是轻量级、安全、高性能、可扩展、兼容OCI的软件容器与运行环境。日前是 CNCF 沙箱项目。WasmEdge 被应用在 SaaS、云原生,service mesh、边缘计算、边缘云、微服务、流数据处理、LLM 推理等行业

GitHub:https://github.com/WasmEdge/WasmEdge

官网:https://wasmedge.org/

‍‍Discord 群:https://discord.gg/U4B5sFTkFc

文档:https://wasmedge.org/docs

文案转载自Second State点击这儿阅读原文认识更加多

CNCF概况(幻灯片)

扫描二维码联系咱们

CNCF (Cloud Native Computing Foundation)成立于2015年12月,隶属于Linux  Foundation,是非营利性组织。 

CNCF云原生计算基金会)致力于培育和守护一个厂商中立的开源生态系统,来推广云原生技术。咱们经过将最前沿的模式民主化,让这些创新为公众所用。请关注CNCF微X公众号。

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

站点统计|Archiver|手机版|小黑屋|外链论坛 ( 非经营性网站 )|网站地图

GMT+8, 2024-10-4 02:33 , Processed in 1.271960 second(s), 37 queries .

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.