告别OpenAI 一个命令行跨设备运行 Dolphin-2.6-Phi-2
Second_State
2024年01月18日 17:17
当你让GPT

轻量 2MB AI 推理APP 可完全跨平台运行,在自己的 Mac 试试吧!

想要快速开始,只需在自己的设备上运行一个命令[1]即可与 Dolphin-2.6-Phi-2 交互。 这个命令行工具会自动下载并安装 WasmEdge 运行时、模型文件和用于推理的完全可移植 Wasm 应用。

Dolphin 2.6 Phi-2[2] 由 Eric Hartford 和 Fernando Fernandes 开发,是基于 Phi-2 架构的高级大语言模型。 该模型由 Convai 赞助,在最新的 2.6 版本中进行了重大改进,包括修复训练配置问题以及重新引入基于 samantha 的同理心数据。 它用 Capybara 取代了以前的 Synthia 和 pure-dove 模型。 值得注意的是,Dolphin 2.6 Phi-2 未经审查,消除了对齐和偏差以提高合规性。 但是,建议用户进行自己的对齐层以符合道德使用。 [Image: Easily Implement dolphin-2.2-yi-34b on Your Device with Rust + Wasm (12).png]本文中,我们将介绍:

  • 在自己的设备上运行 Dolphin-2.6-Phi-2

  • 为 Dolphin-2.6-Phi-2 大模型创建一个与 OpenAI 兼容的 API 服务

我们将使用 LlamaEdge[3](Rust + Wasm 技术栈)开发和部署此模型的应用程序。不需要安装复杂的 Python 包或 C++ 工具链!了解我们选择这个技术栈的原因。[4]

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

步骤1:通过以下命令行安装 WasmEdge[5]

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

步骤2:下载 Dolphin-2.6-Phi-2-Instrcut-v0.1 GGUF 文件。[6]由于模型的大小为几个 GB,下载可能需要一定时间。

curl -LO https://huggingface.co/second-state/Dolphin-2.6-Phi-2-GGUF/resolve/main/dolphin-2_6-phi-2.Q5_K_M.gguf

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

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

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

wasmedge --dir .:. --nn-preload default:GGML:AUTO:dolphin-2_6-phi-2.Q5_K_M.gguf llama-chat.wasm -p chatml

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

[You]:

What is CES?

[Bot]

CES, or Consumer Electronics Show, is an annual event held in the United States by the Consumer Technology Association (CTA). It features a showcase of new consumer electronic products, innovations, and trends in technology. The event typically takes place in Las Vegas during January. CES serves as an exhibition venue where companies can reveal cutting-edge devices, services, and technologies to consumers, industry professionals, investors, and media personnel. It has grown into one of the world's largest technology conferences and events, attracting over 200,000 attendees each year. The event often influences the direction of technological advancements in various industries, such as telecommunications, consumer electronics, computing, home entertainment, and automotive

为 Dolphin-2.6-Phi-2 大模型创建与 OpenAI 兼容的 API 服务

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

下载一个 API 服务器应用程序。它也是一个跨平台可移植的 Wasm 应用程序,可以在各种不同 CPU 和 GPU 设备上运行。戳此查看该 app 的 Rust 源代码。[8]

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/latest/download/chatbot-ui.tar.gz

tar xzf chatbot-ui.tar.gz

rm chatbot-ui.tar.gz

接下来,使用以下命令行启动模型的 API 服务器。 然后,打开浏览器访问 http://localhost:8080[9] 开始聊天!

wasmedge --dir .:. --nn-preload default:GGML:AUTO:dolphin-2_6-phi-2.Q5_K_M.gguf llama-api-server.wasm -p chatml

还可以从另一个终端使用 curl 与 API 服务器交互。

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

  -H 'accept:application/json' \

  -H 'Content-Type: application/json' \

  -d '{"messages":[{"role":"system", "content": "You are an AI assistant."}, {"role":"user", "content": "What is the capital of France?"}], "model":"dolphin-2.6-phi-2"}'

就这样。WasmEdge 是运行 LLM 应用程序最简单、最快速、最安全的方式[10]。尝试一下吧! 加入 WasmEdge Discord[11]提问和分享见解。如果在运行这个模型时有任何问题,请访问 second-state/llamaedge[12] 提 issue,或预约demo[13]

参考资料

[1]

一个命令: https://www.secondstate.io/run-llm/

[2]

Dolphin 2.6 Phi-2: https://huggingface.co/cognitivecomputations/dolphin-2_6-phi-2

[3]

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

[4]

了解我们选择这个技术栈的原因。: https://www.secondstate.io/articles/fast-llm-inference/

[5]

WasmEdge: https://link.zhihu.com/?target=https%3A//github.com/WasmEdge/WasmEdge

[6]

Dolphin-2.6-Phi-2-Instrcut-v0.1 GGUF 文件。: https://huggingface.co/second-state/Dolphin-2.6-Phi-2-GGUF

[7]

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

[8]

戳此查看该 app 的 Rust 源代码。: https://github.com/second-state/llama-utils/tree/main/api-server

[9]

http://localhost:8080: http://localhost:8080/

[10]

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

[11]

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

[12]

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

[13]

demo: https://link.zhihu.com/?target=https%3A//code.flows.network/webhook/vvAtEBUk6QMhVVLuw7IU