最近火熱的 DeepSeek LLM模型, 你玩過了嗎?
其實也可以很容易地在地端執行這個 LLM模型, 當然也可以執行其他廠家的 LLM模型. 使用的工具為這個十分好用的 ollama:
ollama 這個開源工具是用來簡化在地端執行這些 LLM模型的工具, 方便快速地可以在本地部署執行環境, 而且也可以在本地提供 API服務的功能.
先來看看在 Windows/Mac/Linux 下如何運行, 它將執行環境打包可以下載的安裝檔, 安裝完成後是利用 console 來執行互動式指令, 以 Windows 為例, 先下載一個安裝程式, 安裝完成後, 利用 console 來執行, 常用指令如下:
C:\Users\tim>ollama Usage: ollama [flags] ollama [command] Available Commands: serve Start ollama create Create a model from a Modelfile show Show information for a model run Run a model stop Stop a running model pull Pull a model from a registry push Push a model to a registry list List models ps List running models cp Copy a model rm Remove a model help Help about any command Flags: -h, --help help for ollama -v, --version Show version information Use "ollama [command] --help" for more information about a command.
可以看到一連串指令很像 docker 運行的方式, 實際上操作也很像 docker 指令, 例如我們想執行一個 deepseek-r1 的 LLM, 可以直接以 ollama pull deepseek-r1 來下載這個 LLM, 並使用 ollama list 來看看是否下載成功:
C:\Users\tim>ollama pull deepseek-r1 pulling manifest pulling 96c415656d37... 100% ▕████████████████████████████████████████████████████████▏ 4.7 GB pulling 369ca498f347... 100% ▕████████████████████████████████████████████████████████▏ 387 B pulling 6e4c38e1172f... 100% ▕████████████████████████████████████████████████████████▏ 1.1 KB pulling f4d24e9138dd... 100% ▕████████████████████████████████████████████████████████▏ 148 B pulling 40fb844194b2... 100% ▕████████████████████████████████████████████████████████▏ 487 B verifying sha256 digest writing manifest success C:\Users\tim>ollama list NAME ID SIZE MODIFIED deepseek-r1:latest 0a8c26691023 4.7 GB 40 seconds ago
預設的 deepseek-r1 是 7B的版本, 大小為 4.7GB, 可以參考線上還有許多不同大小的版本可供下載:
https://ollama.com/library/deepseek-r1
接來下利用 ollama run deepseek-r1 即可執行互動的介面:
C:\Users\tim>ollama run deepseek-r1 >>> /show info Model architecture qwen2 parameters 7.6B context length 131072 embedding length 3584 quantization Q4_K_M Parameters stop "<|begin▁of▁sentence|>" stop "<|end▁of▁sentence|>" stop "<|User|>" stop "<|Assistant|>" License MIT License Copyright (c) 2023 DeepSeek
這裡在提示介面下使用 /show info 指令, 可以取得對應 LLM的資訊, 接下來我們來試看看能不能判斷 9.9 與 9.11 的大小:
>>> which one is larger 9.9 and 9.11 <think> First, I need to determine which number is larger between 9.9 and 9.11. To compare them effectively, I'll align their decimal places by writing 9.9 as 9.90. Next, I'll compare the numbers digit by digit starting from the leftmost digits. Both numbers have 9 in the units place, so they are equal there. Moving to the tenths place, 9.90 has a 9 while 9.11 has a 1. Since 9 is greater than 1, I can conclude that 9.90 is larger than 9.11. </think> To determine which number is larger between **9.9** and **9.11**, let's compare them step by step. ### Step 1: Align the Decimal Places It's easier to compare numbers when they have the same number of decimal places. - Convert **9.9** to two decimal places: \[ 9.9 = 9.90 \] Now, we have: \[ 9.90 \quad \text{and} \quad 9.11 \] ### Step 2: Compare the Numbers Digit by Digit 1. **Compare the Units Place:** - Both numbers have **9** in the units place. 2. **Compare the Tenths Place:** - **9.90:** The tenths digit is **9**. - **9.11:** The tenths digit is **1**. Since **9 > 1**, we can conclude that **9.90** is larger than **9.11** at this point. ### Conclusion \[ \boxed{9.9} \] >>>
看起來非常順利地判斷出來了, 由於 deepseek-r1 是研究思考型的 LLM, 所以前面會有一段 <think> 的區域, 用來說明他的思路與解決策略, 和最近chatgpt release 的 reasoning 功能十分類似, 不是只有答案的輸出而已, 還包含了解決問題的過程.
利用在提示詞下的 /? 可以看到系統指令:
>>> /? Available Commands: /set Set session variables /show Show model information /load <model> Load a session or model /save <model> Save your current session /clear Clear session context /bye Exit /?, /help Help for a command /? shortcuts Help for keyboard shortcuts Use """ to begin a multi-line message.
離開可以利用 /bye 即可回到系統環境, 再利用 ollama ps 可以看到目前仍在執行的 LLM, 可以利用 ollama stop deepseek-r1 來停止, 並再次使用 ollama ps 來檢查, 如下:
>>> /bye C:\Users\tim>ollama ps NAME ID SIZE PROCESSOR UNTIL deepseek-r1:latest 0a8c26691023 6.0 GB 100% GPU 2 minutes from now C:\Users\tim>ollama stop deepseek-r1 C:\Users\tim>ollama ps NAME ID SIZE PROCESSOR UNTIL C:\Users\tim>
大家可以利用看看這個好用的地端執行環境, 來試試這些開源的LLM吧!
繼續閱讀:
- https://wiki.eryajf.net/pages/97047e/
- https://hk.news.yahoo.com/deepseek-r1-macos-install-tutorial-ai-101603370.html