Last active
May 28, 2024 11:43
-
-
Save theycallmeloki/90acf4dfcdf2ad53a7bb33aafd941479 to your computer and use it in GitHub Desktop.
an ansbile script that quickly bootstraps a Pi 4 cluster with tools required to run a 65B llama model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You will need the following two files, be sure to change the IP address in both sections, the `hostfile_contents` | |
as well as the ansible inventory section to reflect your configuration | |
Rest of the steps should run parallely across the different machines, for any updates to this script, | |
check this thread: https://github.com/ggerganov/llama.cpp/issues/2164#issuecomment-1639640846 | |
If you want an automated way to do this in the future and would like an opionated setup procedure, | |
check this repo: https://github.com/theycallmeloki/edith-cli | |
``` | |
const ansiblePlaybookSetupPi = ` | |
--- | |
- hosts: spartans | |
vars: | |
patch_contents: | | |
diff --git a/llama.cpp b/llama.cpp | |
index 2d09d6c..3ebdca4 100644 | |
--- a/llama.cpp | |
+++ b/llama.cpp | |
@@ -129,11 +129,11 @@ static const std::map<e_model, size_t> & MEM_REQ_SCRATCH1() | |
static const std::map<e_model, size_t> & MEM_REQ_KV_SELF() | |
{ | |
static std::map<e_model, size_t> k_sizes = { | |
- { MODEL_3B, 682ull * MB }, | |
- { MODEL_7B, 1026ull * MB }, | |
- { MODEL_13B, 1608ull * MB }, | |
- { MODEL_30B, 3124ull * MB }, | |
- { MODEL_65B, 5120ull * MB }, | |
+ { MODEL_3B, 682ull * MB / 8 }, | |
+ { MODEL_7B, 1026ull * MB / 8 }, | |
+ { MODEL_13B, 1608ull * MB / 8 }, | |
+ { MODEL_30B, 3124ull * MB / 8 }, | |
+ { MODEL_65B, 5120ull * MB / 8 }, | |
}; | |
return k_sizes; | |
} | |
hostfile_contents: | | |
192.168.0.60 slots=1 | |
192.168.0.61 slots=1 | |
192.168.0.62 slots=1 | |
192.168.0.63 slots=1 | |
192.168.0.64 slots=1 | |
192.168.0.65 slots=1 | |
tasks: | |
- name: Update packages | |
apt: | |
update_cache: yes | |
cache_valid_time: 3600 | |
become: yes | |
- name: Install required packages | |
apt: | |
name: | |
- apt-transport-https | |
- ca-certificates | |
- curl | |
- gnupg | |
- lsb-release | |
- build-essential | |
- jq | |
- htop | |
- nfs-common | |
state: present | |
become: yes | |
- name: Create directory to mount NFS share | |
file: | |
path: /mnt/models | |
state: directory | |
mode: '0777' | |
become: yes | |
- name: Mount NFS share | |
mount: | |
path: /mnt/models | |
src: 192.168.0.10:/mnt/models | |
fstype: nfs | |
state: mounted | |
become: yes | |
- name: Check if /tmp/llama.cpp directory exists | |
stat: | |
path: /tmp/llama.cpp | |
register: repo_folder | |
- name: Remove /tmp/llama.cpp directory if it exists | |
file: | |
path: /tmp/llama.cpp | |
state: absent | |
when: repo_folder.stat.exists | |
- name: Clone the git repository | |
git: | |
repo: 'https://github.com/ggerganov/llama.cpp.git' | |
dest: '/tmp/llama.cpp' | |
clone: yes | |
update: yes | |
- name: Write patch file | |
copy: | |
dest: "/tmp/llama.cpp/llama.patch" | |
content: "{{ patch_contents }}" | |
- name: Apply patch | |
command: | |
cmd: git apply llama.patch | |
chdir: '/tmp/llama.cpp' | |
- name: Compile the project | |
command: | |
cmd: make CC=mpicc CXX=mpicxx LLAMA_MPI=1 -j | |
chdir: '/tmp/llama.cpp' | |
become: yes | |
- name: Run the program | |
command: | |
cmd: mpirun -hostfile /tmp/llama.cpp/hostfile -n 6 /tmp/llama.cpp/main -m /home/laneone/ggml-model-q4_0.bin -p "I believe the meaning of life is" -n 64 | |
become: yes | |
` | |
// change the ip addresses here to match your network | |
const ansiblePiInventory = ` | |
[spartans] | |
spartan1 ansible_host=192.168.0.60 ansible_ssh_pass=<user-password> ansible_become_password=<root-password> ansible_ssh_user=<username> | |
spartan2 ansible_host=192.168.0.61 ansible_ssh_pass=<user-password> ansible_become_password=<root-password> ansible_ssh_user=<username> | |
spartan3 ansible_host=192.168.0.62 ansible_ssh_pass=<user-password> ansible_become_password=<root-password> ansible_ssh_user=<username> | |
spartan4 ansible_host=192.168.0.63 ansible_ssh_pass=<user-password> ansible_become_password=<root-password> ansible_ssh_user=<username> | |
spartan5 ansible_host=192.168.0.64 ansible_ssh_pass=<user-password> ansible_become_password=<root-password> ansible_ssh_user=<username> | |
spartan6 ansible_host=192.168.0.65 ansible_ssh_pass=<user-password> ansible_become_password=<root-password> ansible_ssh_user=<username> | |
` | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment