﻿# 使用 Ollama 執行 TAIDE 的 TAIDE-LX-7B-Chat-4bit 大語言模型

我自從寫了 [介紹好用工具：Ollama 快速在本地啟動並執行大型語言模型](/post/2024/03/04/Useful-tool-Ollama) 文章後，就幾乎都在本機用 [Ollama](https://ollama.com/) 執行各種大語言模型的推論。由於幾天前 [TAIDE](https://taide.tw/index) 團隊發表了一套符合台灣語言和文化特性的大語言模型(`TAIDE-LX-7B`)，我當下就立刻用 [Ollama](https://ollama.com/) 跑起來了。這篇文章我將分享幾個簡單的小步驟，幫助大家也可以很順利的在本機將 `TAIDE-LX-7B-Chat-4bit` 模型跑起來。

![image](https://stwillblogassets.blob.core.windows.net/files/images/external/stwillblogassets.blob.core.windows.net/12575d8dba7fa91281ab-89a1e8c1-5407-4e65-80df-d10fa63e4f53.webp)

理論上，任何一套 [GGUF](https://www.datalearner.com/blog/1051705718835586) 格式的大語言模型檔案，都可以透過 [Ollama](https://ollama.com/) 來執行。而 TAIDE 團隊提供的 `TAIDE-LX-7B-Chat-4bit` 模型以 `LaMA2-7b` 為基礎，這個版本是 4bit 的量化版本，因此要建立成 Ollama 可以使用的模型就相當簡單，以下是操作步驟：

1.  下載 `taide-7b-a.2-q4_k_m.gguf` 檔案
    
    你要先進入 Hugging Face 的 [taide/TAIDE-LX-7B-Chat-4bit](https://huggingface.co/taide/TAIDE-LX-7B-Chat-4bit) 頁面，然後必須先同意授權條款才能下載與使用此模型。
    
    ![同意授權條款](https://stwillblogassets.blob.core.windows.net/files/images/external/github.com/42675b36e46bb3779fee-d914a669-853f-46ef-9765-79e89fd2c8a4.jpg)
    
    切換到 `Files and versions` 頁籤，下載 `taide-7b-a.2-q4_k_m.gguf` 檔案 (4.22 GB)
    
    ![Files and versions: taide-7b-a.2-q4\_k\_m.gguf](https://stwillblogassets.blob.core.windows.net/files/images/external/github.com/be296451b572040d28f5-8b7d9ba2-0c17-4662-ab63-2ddd5ade302f.jpg)
    
2.  在本機建立一個 `Modelfile` 模型定義檔
    
    這是一個文字檔，檔案內容如下：
    
    ```
    FROM ./taide-7b-a.2-q4_k_m.gguf
    ```
    
3.  建立 Ollama 模型
    
    ```bash
    ollama create taide-lx-7b-chat-4bit:latest -f Modelfile
    ```
    
4.  執行 Ollama 模型
    
    ```bash
    ollama run taide-lx-7b-chat-4bit:latest
    ```
    

> 更完整的 Ollama 用法，建議參考我的[介紹好用工具：Ollama 快速在本地啟動並執行大型語言模型](/post/2024/03/04/Useful-tool-Ollama)文章。

### 相關連結

-   [TAIDE - 推動臺灣可信任生成式AI發展計畫](https://taide.tw/)
-   [taide (TAIDE)](https://huggingface.co/taide) (Hugging Face)
    -   [taide/TAIDE-LX-7B-Chat-4bit · Hugging Face](https://huggingface.co/taide/TAIDE-LX-7B-Chat-4bit)
-   [ollama/ollama](https://github.com/ollama/ollama): Get up and running with Llama 2, Mistral, Gemma, and other large language models.
-   [OllamaSharp](https://github.com/awaescher/OllamaSharp)
