如何借助Cortex運行本地LLM 原創
?AI行業正在經歷一場轉變,轉向更小巧更高效的大語言模型(LLM),從而使用戶能夠在本地機器上運行模型,無需功能強大的服務器。本教程將指導你借助Cortex運行本地LLM,著重介紹其獨特的功能和易用性,使任何擁有標準硬件的人都可以享用AI。
注意:Cortex目前正在積極開發中,這可能會導致bug或某些功能無法正常運行。你可以通過???GitHub??或??Discord??報告任何問題。
Cortex簡介
?Cortex是一個動態的本地AI API平臺,旨在輕松高效地運行和定制大語言模型(LLM)。它擁有一個簡單直觀的靈感來自Ollama的命令行界面(CLI),完全用C++構建而成。你可以下載適用于Windows、macOS和Linux的安裝軟件包。
用戶可以從Hugging Face中選擇模型,也可以使用Cortex的內置模型,這些模型以通用文件格式存儲,以增強兼容性。使用Cortex最棒的地方在于,它支持可切換的引擎,從llama.cpp開始,可計劃在將來添加ONNX Runtime和TensorRT-LLM。此外,你還可以獲得帶有儀表板的實用服務器,用于查看API命令并對其進行測試。?
開始上手Cortex
?之后,打開終端或PowerShell,輸入如下命令以下載Llama 3.2 3B指令模型。
$ cortex pull llama3.2
它將提示你選擇模型的各種量化版本;只需選擇默認選項llama3.2:3b-ggulf-q4-km。模型將被下載,下載時間取決于你的網速。?
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’命令后輸入模型的存儲庫ID,它就會自動下載。
$ cortex pull kingabzpro/Gemma-2-9b-it-chat-doctor
下載完成后,輸入帶有模型名稱的‘run’命令來啟動服務器。
$ cortex run llama3.2
?一旦一切設置完畢,你就可以開始從Llama 3.2提問了。
正如我們所見,模型準確地回答了關于世界上最高建筑的問題。?
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.
我們甚至問了一些后續問題,它也能理解上下文。簡單又快速。
> 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 ..........
?當你運行服務器時,還可以選擇通過Python API、CURL命令以及其他語言的API訪問模型。
在瀏覽器中輸入URL http://127.0.0.1:39281,開始探究你可以用服務器做些什么。?
如果你想查看有多少模型在后臺運行以及它們消耗了多少內存,可以輸入‘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 |
+------------------------+-----------+-----------+---------+--------------------
結論
我們在本教程中了解了Cortex、如何安裝以及如何下載并在終端本地使用Llama 3.2,強烈建議你在本地嘗試一下。
原文標題:??Run Local LLMs with Cortex??,作者:Abid Ali Awan
