您现在的位置是:首页 > 文章详情

不是 GPT4 用不起,而是本地运行 Mixtral-8x7B 更有性价比

日期:2024-01-03点击:79

当 GPT4 刚问世时,社区猜测它用了“多少亿个参数”才实现的如此惊人的性能。 但事实证明,GPT4 的创新不仅仅是“更多参数”。 它本质上是 8 个 GPT 3.5 模型一起工作。 这些模型中的每一个都针对不同的任务(即“专家”)进行了调整。 这称为“专家组合”(Mixture of Experts,缩写为 MoE)。

输入文本根据内容和所需任务会被分派给 8 个专家模型中的一个。 然后,小组中的其他专家模型会评估结果,从而改进未来的问题的分配。

Mistral AI 的 Mixtral 8x7B 是基于 8 个 Mistral-7B 模型的开源 MoE LLM。 借助 WasmEdge,你可以在任意设备上创建并运行该 LLM 的跨平台应用程序,包括自己的笔记本电脑、边缘设备和服务器。

在自己的设备上运行 Mixtral-8x7B

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

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

步骤2: 下载 Mixtral-8x7B-Instrcut-v0.1 GGUF 文件。由于模型的大小为32.2 GB,下载可能需要一定时间。

curl -LO https://huggingface.co/TheBloke/Mixtral-8x7B-Instruct-v0.1-GGUF/resolve/main/mixtral-8x7b-instruct-v0.1.Q5_K_M.gguf 

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

curl -LO https://github.com/second-state/llama-utils/raw/main/chat/llama-chat.wasm 

就是这样。可以通过输入以下命令在终端与模型进行聊天。

wasmedge --dir .:. --nn-preload default:GGML:AUTO:mixtral-8x7b-instruct-v0.1.Q5_0.gguf llama-chat.wasm -p mistral-instruct 

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

以下在 Jetson Orin 64G 上运行的问答。

[You]: What is the best place to watch the new year ball drop in New York City? [Bot] The most famous place to watch the New Year Ball Drop is in Times Square, New York City. However, it's important to note that this area is extremely crowded, so if you prefer a less chaotic environment, there are other options. You can watch the ball drop from nearby hotels like the Marriott Marquis or the Embassy Suites, which have rooms and restaurants with views of Times Square. You can also watch it from surrounding bars and restaurants or from special viewing parties. If you're not in New York City, the event is broadcasted live on television and online platforms. 

为 Mixtral-8x7B 模型创建与 OpenAI 兼容的 API 服务

与 OpenAI 兼容的 Web API 能让该模型与各种不同的 LLM 工具和代理框架(如 flows.network、LangChain 和 LlamaIndex)适配。

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

curl -LO https://github.com/second-state/llama-utils/raw/main/api-server/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:mixtral-8x7b-instruct-v0.1.Q5_0.gguf llama-api-server.wasm -p mistral-instruct 

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

curl -X POST http://localhost:8080/v1/chat/completions \ -H 'accept:application/json' \ -H 'Content-Type: application/json' \ -d '{"messages":[{"role":"user", "content": "What is the capital of France?"}], "model":"Mixtral-8x7B-Instruct-v0.1"}' 

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

什么是“专家组合”(MoE)?

“专家组合”(MoE)是机器学习和人工智能中的一个概念,其中多个专业化的模型或组件(称为“专家”)相结合以提高整体性能。 每个专家都被设计来处理特定的数据子集或特定类型的任务。 会有一个门控网络评估每个输入并确定最适合它的专家。 然后专家的输出被组合起来,通常是相加的。 这种方法允许在单个模型框架专业化地对不同的数据或任务进行处理,从而提高效率和有效性。

原文链接:https://my.oschina.net/u/4532842/blog/10568121
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章