如何借助Cortex運(yùn)行本地LLM 原創(chuàng)
?AI行業(yè)正在經(jīng)歷一場(chǎng)轉(zhuǎn)變,轉(zhuǎn)向更小巧更高效的大語言模型(LLM),從而使用戶能夠在本地機(jī)器上運(yùn)行模型,無需功能強(qiáng)大的服務(wù)器。本教程將指導(dǎo)你借助Cortex運(yùn)行本地LLM,著重介紹其獨(dú)特的功能和易用性,使任何擁有標(biāo)準(zhǔn)硬件的人都可以享用AI。
注意:Cortex目前正在積極開發(fā)中,這可能會(huì)導(dǎo)致bug或某些功能無法正常運(yùn)行。你可以通過???GitHub??或??Discord??報(bào)告任何問題。
Cortex簡(jiǎn)介
?Cortex是一個(gè)動(dòng)態(tài)的本地AI API平臺(tái),旨在輕松高效地運(yùn)行和定制大語言模型(LLM)。它擁有一個(gè)簡(jiǎn)單直觀的靈感來自O(shè)llama的命令行界面(CLI),完全用C++構(gòu)建而成。你可以下載適用于Windows、macOS和Linux的安裝軟件包。
用戶可以從Hugging Face中選擇模型,也可以使用Cortex的內(nèi)置模型,這些模型以通用文件格式存儲(chǔ),以增強(qiáng)兼容性。使用Cortex最棒的地方在于,它支持可切換的引擎,從llama.cpp開始,可計(jì)劃在將來添加ONNX Runtime和TensorRT-LLM。此外,你還可以獲得帶有儀表板的實(shí)用服務(wù)器,用于查看API命令并對(duì)其進(jìn)行測(cè)試。?
開始上手Cortex
?之后,打開終端或PowerShell,輸入如下命令以下載Llama 3.2 3B指令模型。
$ cortex pull llama3.2
它將提示你選擇模型的各種量化版本;只需選擇默認(rèn)選項(xiàng)llama3.2:3b-ggulf-q4-km。模型將被下載,下載時(shí)間取決于你的網(wǎng)速。?
Available to download:
1. llama3.2:3b-gguf-q2-k
2. llama3.2:3b-gguf-q3-kl
3. llama3.2:3b-gguf-q3-km
4. llama3.2:3b-gguf-q3-ks
5. llama3.2:3b-gguf-q4-km (default)
6. llama3.2:3b-gguf-q4-ks
7. llama3.2:3b-gguf-q5-km
8. llama3.2:3b-gguf-q5-ks
9. llama3.2:3b-gguf-q6-k
10. llama3.2:3b-gguf-q8-0
Select a model (1-10): 5
Selected: llama3.2:3b-gguf-q4-km
Validating download items, please wait..
Start downloading: model.gguf
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1104 100 1104 0 0 3255 0 --:--:-- --:--:-- --:--:-- 3266
100 1925M 100 1925M 0 0 2397k 0 0:13:42 0:13:42 --:--:-- 2430k
Start downloading: model.yml
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1522 100 1522 0 0 4042 0 --:--:-- --:--:-- --:--:-- 4058
Model llama3.2:3b-gguf-q4-km downloaded successfully!
你還可以從Hugging Face Hub中提取模型,只要在‘pull’命令后輸入模型的存儲(chǔ)庫ID,它就會(huì)自動(dòng)下載。
$ cortex pull kingabzpro/Gemma-2-9b-it-chat-doctor
下載完成后,輸入帶有模型名稱的‘run’命令來啟動(dòng)服務(wù)器。
$ cortex run llama3.2
?一旦一切設(shè)置完畢,你就可以開始從Llama 3.2提問了。
正如我們所見,模型準(zhǔn)確地回答了關(guān)于世界上最高建筑的問題。?
Starting server ...
Host: 127.0.0.1 Port: 39281
Server started
API Documentation available at: http://127.0.0.1:39281
Inorder to exit, type `exit()`
> What is the tallest building in the world?
The Burj Khalifa, located in Dubai, United Arab Emirates, is currently the tallest building in the world, standing at a height of 828 meters (2,722 feet) with 163 floors.
我們甚至問了一些后續(xù)問題,它也能理解上下文。簡(jiǎn)單又快速。
> tell me more about it.
The Burj Khalifa!
Here are some fascinating facts about the Burj Khalifa:
1. **Design and Construction**: The Burj Khalifa was designed by the American architectural firm Skidmore, Owings & Merrill, with Adrian Smith and John G. Buffman as the lead architects.
2. **Height and Floors**: The Burj Khalifa stands at a height of 828 meters (2,722 feet) with 163 ..........
?當(dāng)你運(yùn)行服務(wù)器時(shí),還可以選擇通過Python API、CURL命令以及其他語言的API訪問模型。
在瀏覽器中輸入U(xiǎn)RL http://127.0.0.1:39281,開始探究你可以用服務(wù)器做些什么。?
如果你想查看有多少模型在后臺(tái)運(yùn)行以及它們消耗了多少內(nèi)存,可以輸入‘ps’命令來查看。
$ cortex ps
+------------------------+-----------+-----------+---------+------------------------+
| Model | Engine | RAM | VRAM | Up time |
+------------------------+-----------+-----------+---------+------------------------+
| llama3.2:3b-gguf-q4-km | llama-cpp | 308.23 MB | 1.87 GB | 22 minutes, 31 seconds |
+------------------------+-----------+-----------+---------+--------------------
結(jié)論
我們?cè)诒窘坛讨辛私饬薈ortex、如何安裝以及如何下載并在終端本地使用Llama 3.2,強(qiáng)烈建議你在本地嘗試一下。
原文標(biāo)題:??Run Local LLMs with Cortex??,作者:Abid Ali Awan
