# Meta Llama 2 7B 架設 ( Apple Silicon ) >最後編輯日:2024.03.30 >硬體: Macbook Pro (13-inch, M1, 8GB, 2020) >韌體: MacOS 14.2.1 ## 第一步 下載 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 ``` ## 第二步 下載 Llama 本體 1. 打開新的終端機 2. 去 [Meta官網](https://llama.meta.com/llama-downloads) 填寫個人資料 3. 從 Meta 寄送的郵件獲取 URL 4. 切換至桌面 ```= cd desktop ``` 5. 下載`llama` ``` = git clone https://github.com/facebookresearch/llama ``` 6. 切換至`llama` ```= cd llama ``` 7. 運行`download.sh` ```= ./download.sh ``` >依次輸入 URL(一段網址)與 欲下載的版本  備註: chat版本的交流能力略優於普通版本,但其知識、邏輯與編程能力較差。 7. 關閉終端機 8. 將`llama`新出現的檔案/資料夾移入```desktop/llama.cpp/models``` >通常包含```tokenizer_checklist.chk``` ```tokenizer.model``` ```llama-2-7b``` ## 第三步 量化模型 1. 切到第一步開啟的終端機 2. 運行`convert.py`把模型轉換為 `f16.gguf`,以減少記憶體使用和算力需求 ```= python3 convert.py models/llama-2-7b ``` >原貌:`python3 convert.py folder_path_to_model` 3. 量化成 q4_0 or q8_0 > 差別在 q4_0 速度較快,但損耗較多; q8_0 速度較慢,但損耗較少,也較吃記憶體( M1 8G 會顯示 ```status 5 ```記憶體不足 ) ```= ./quantize ./models/llama-2-7b/ggml-model-f16.gguf ./models/llama-2-7b/ggml-model-q4_0.gguf q4_0 ``` > 原貌:`./quantize model_path new_model_path q4_0` 4. 運行模型 ```= ./main -m models/llama-2-7b/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. 大功告成  ## 備註 1. 再次開啟步驟: ```= cd desktop cd llama.cpp ./main -m models/llama-2-7b/ggml-model-q4_0.gguf -n 256 --repeat_penalty 1.0 --color -i -r "User:" -f prompts/chat-with-bob.txt ``` 2. 其他模組安裝(例如:`llama-7b-chat` )僅需將`llama-7b`全替換成`llama-7b-chat` ## 延伸 - [加入 Taiwan-LLM](/AIOQT856T_6dz6gShxp-GQ)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up