# Meta CodeLlama 7B 架設 ( Apple Silicon ) >最後編輯日:2024.03.24 >硬體: Macbook Pro (13-inch, M1, 8GB, 2020) >韌體: MacOS 14.4 ## 第一步 下載 llama.cpp 1. 打開新的終端機 2. 切換至桌面 ``` = cd desktop ``` 3. 下載 llama.cpp ```= git clone https://github.com/ggerganov/llama.cpp ``` 4. 切換到```llama.cpp``` ```= cd llama.cpp ``` 5. 建立環境 ```= LLAMA_METAL=1 make ``` 6. 安裝附加套件 ``` = python3 -m pip install -r requirements.txt python3 -m pip install torch numpy sentencepiece ``` ## 第二步 下載 CodeLlama 本體 1. 打開新的終端機 2. 去 [Meta官網](https://llama.meta.com/llama-downloads) 填寫個人資料 3. 從 Meta 寄送的郵件獲取 URL 4. 切換至桌面 ```= cd desktop ``` 5. 下載`CodeLlama` ``` = git clone https://github.com/meta-llama/llama.git ``` 6. 切換至`CodeLlama` ```= cd CodeLlama ``` 7. 運行`download.sh` ```= ./download.sh ``` >依次輸入 URL(一段網址)與 欲下載的版本![截圖 2024-04-01 上午9.27.35](https://hackmd.io/_uploads/r1QqpKPJ0.png) ![截圖 2024-04-01 上午9.28.37](https://hackmd.io/_uploads/SkQRaKwy0.png) 備註:推薦 7b-Instruct 7. 關閉終端機 8. 將`CodeLlama`新出現的檔案/資料夾移入`desktop/llama.cpp/models` >通常包含`tokenizer_checklist.chk` `tokenizer.model` `CodeLlama-2-7b` ## 第三步 量化模型 1. 切到第一步開啟的終端機 2. 運行`convert.py`把模型轉換為 `f16.gguf`,以減少記憶體使用和算力需求 ```= python3 convert.py models/CodeLlama-7b-Instruct ``` >原貌:`python3 convert.py folder_path_to_model` 3. 量化成 q4_0 or q8_0 > 差別在 q4_0 速度較快,但損耗較多; q8_0 速度較慢,但損耗較少,也較吃記憶體( M1 8G 會顯示 ```status 5 ```記憶體不足 ) ```= ./quantize ./models/CodeLlama-7b-Instruct/ggml-model-f16.gguf ./models/CodeLlama-7b-Instruct/ggml-model-q4_0.gguf q4_0 ``` > 原貌:`./quantize model_path new_model_path q4_0` 4. 運行模型 ```= ./main -m models/CodeLlama-7b-Instruct/ggml-model-q4_0.gguf -n 256 --repeat_penalty 1.0 --color -i -r "User:" -f prompts/chat-with-bob.txt ``` >原貌:`./main -m path_to_model -n 256 --repeat_penalty 1.0 --color -i -r "User:" -f prompts/chat-with-bob.txt` 5. 大功告成 ![截圖 2024-02-04 凌晨1.33.18](https://hackmd.io/_uploads/rkcktlhcp.png) ## 備註 1. 再次開啟步驟: ```= cd desktop cd llama.cpp ./main -m models/CodeLlama-7b-Instruct/ggml-model-q4_0.gguf -n 256 --repeat_penalty 1.0 --color -i -r "User:" -f prompts/chat-with-bob.txt ``` 2. 其他模組安裝(例如:`CodeLlama-7b`or`CodeLlama-7b-Python` )僅需將`CodeLlama-7b-Instruct`全替換成`CodeLlama-7b`or`CodeLlama-7b-Python`