|
| 1 | +## Configuring llama-server-one |
| 2 | + |
| 3 | +Brad Hutchings<br/> |
| 4 | + |
| 5 | + |
| 6 | +This file contains instructions for configuring the `llama-server-one` executable to make it ready to package for multiple platforms. |
| 7 | + |
| 8 | +--- |
| 9 | +### Environment Variables |
| 10 | + |
| 11 | +Let's define some environment variables: |
| 12 | +``` |
| 13 | +BUILDING_DIR="1-BUILDING-llama.cpp" |
| 14 | +CONFIGURING_DIR="2-CONFIGURING-llama-server-one" |
| 15 | +
|
| 16 | +LLAMA_SERVER="llama-server" |
| 17 | +LLAMA_SERVER_ONE="llama-server-one" |
| 18 | +LLAMA_SERVER_ONE_ZIP="llama-server-one.zip" |
| 19 | +DEFAULT_ARGS="default-args" |
| 20 | +printf "\n**********\n*\n* FINISHED: Environment Variables.\n*\n**********\n\n" |
| 21 | +``` |
| 22 | + |
| 23 | +--- |
| 24 | +### Create Configuration Directory |
| 25 | + |
| 26 | +Next, let's create a directory where we'll configure `llama-server-one`: |
| 27 | +``` |
| 28 | +cd ~ |
| 29 | +rm -r -f ~/$CONFIGURING_DIR |
| 30 | +mkdir -p $CONFIGURING_DIR |
| 31 | +cp ~/$BUILDING_DIR/$LLAMA_SERVER \ |
| 32 | + ~/$CONFIGURING_DIR/$LLAMA_SERVER_ONE_ZIP |
| 33 | +
|
| 34 | +cd ~/$CONFIGURING_DIR |
| 35 | +printf "\n**********\n*\n* FINISHED: Create Configuration Directory.\n*\n**********\n\n" |
| 36 | +``` |
| 37 | + |
| 38 | +--- |
| 39 | +### Examine Contents of Zip Archive |
| 40 | + |
| 41 | +Look at the contents of the `llama-server-one` zip archive: |
| 42 | +``` |
| 43 | +unzip -l $LLAMA_SERVER_ONE_ZIP |
| 44 | +printf "\n**********\n*\n* FINISHED: Examine Contents of Zip Archive.\n*\n**********\n\n" |
| 45 | +``` |
| 46 | + |
| 47 | +--- |
| 48 | +### Delete Extraneous Timezone Files |
| 49 | + |
| 50 | +You should notice a bunch of extraneous timezone related files in `/usr/*`. Let's get rid of those: |
| 51 | +``` |
| 52 | +zip -d $LLAMA_SERVER_ONE_ZIP "/usr/*" |
| 53 | +printf "\n**********\n*\n* FINISHED: Delete Extraneous Timezone Files.\n*\n**********\n\n" |
| 54 | +``` |
| 55 | + |
| 56 | +--- |
| 57 | +### Verify Contents of Zip Archive |
| 58 | + |
| 59 | +Verify that these files are no longer in the archive: |
| 60 | +``` |
| 61 | +unzip -l $LLAMA_SERVER_ONE_ZIP |
| 62 | +printf "\n**********\n*\n* FINISHED: Verify Contents of Zip Archive.\n*\n**********\n\n" |
| 63 | +``` |
| 64 | + |
| 65 | +--- |
| 66 | +### OPTIONAL: Create website Directory in Archive |
| 67 | + |
| 68 | +`llama.cpp` has a built in chat UI. If you'd like to provide a custom UI, you should add a `website` directory to the `llama-server-one` archive. `llama.cpp`'s chat UI is optimized for serving inside the project's source code. But we can copy the unoptimized source: |
| 69 | +``` |
| 70 | +mkdir -p website |
| 71 | +cp -r ~/$BUILDING_DIR/examples/server/public_legacy/* website |
| 72 | +zip -0 -r $LLAMA_SERVER_ONE_ZIP website/* |
| 73 | +printf "\n**********\n*\n* FINISHED: Create website Directory in Archive.\n*\n**********\n\n" |
| 74 | +``` |
| 75 | + |
| 76 | +#### OPTONAL: Verify website Directory in Archive |
| 77 | + |
| 78 | +Verify that the archive has your website: |
| 79 | +``` |
| 80 | +unzip -l $LLAMA_SERVER_ONE_ZIP |
| 81 | +printf "\n**********\n*\n* FINISHED: Verify website Directory in Archive.\n*\n**********\n\n" |
| 82 | +``` |
| 83 | +--- |
| 84 | +### Create default-args File |
| 85 | + |
| 86 | +A `default-args` file in the archive can specify sane default parameters. The format of the file is parameter name on a line, parameter value on a line, rinse, repeat. End the file with a `...` line to include user specified parameters. |
| 87 | + |
| 88 | +We don't yet support including the model inside the zip archive (yet). That has a 4GB size limitation on Windows anyway, as `.exe` files cannot exceed 4GB. So let's use an adjacent file called `model.gguf`. |
| 89 | + |
| 90 | +We will serve on localhost, port 8080 by default for safety. The `--ctx-size` parameter is the size of the context window. This is kinda screwy to have as a set size rather than a maximum because the `.gguf` files now have the training context size in metadata. We set it to 8192 to be sensible. |
| 91 | +``` |
| 92 | +cat << EOF > $DEFAULT_ARGS |
| 93 | +-m |
| 94 | +model.gguf |
| 95 | +--host |
| 96 | +127.0.0.1 |
| 97 | +--port |
| 98 | +8080 |
| 99 | +--ctx-size |
| 100 | +8192 |
| 101 | +... |
| 102 | +EOF |
| 103 | +printf "\n**********\n*\n* FINISHED: Create Default args File.\n*\n**********\n\n" |
| 104 | +``` |
| 105 | + |
| 106 | +#### OPTIONAL: Create default-args File with Website |
| 107 | + |
| 108 | +If you added a website to the archive, use this instead: |
| 109 | +``` |
| 110 | +cat << EOF > $DEFAULT_ARGS |
| 111 | +-m |
| 112 | +model.gguf |
| 113 | +--host |
| 114 | +127.0.0.1 |
| 115 | +--port |
| 116 | +8080 |
| 117 | +--ctx-size |
| 118 | +8192 |
| 119 | +--path |
| 120 | +/zip/website |
| 121 | +... |
| 122 | +EOF |
| 123 | +printf "\n**********\n*\n* FINISHED: Create Default args File with Website.\n*\n**********\n\n" |
| 124 | +``` |
| 125 | + |
| 126 | +--- |
| 127 | +### Add default-args File to Archive |
| 128 | + |
| 129 | +Add the `default-args` file to the archive: |
| 130 | +``` |
| 131 | +zip -0 -r $LLAMA_SERVER_ONE_ZIP $DEFAULT_ARGS |
| 132 | +printf "\n**********\n*\n* FINISHED: Add default-args File to Archive.\n*\n**********\n\n" |
| 133 | +``` |
| 134 | + |
| 135 | +--- |
| 136 | +### Verify default-args File in Archive |
| 137 | + |
| 138 | +Verify that the archive contains the `default-args` file: |
| 139 | +``` |
| 140 | +unzip -l $LLAMA_SERVER_ONE_ZIP |
| 141 | +printf "\n**********\n*\n* FINISHED: Verify default-args File in Archive.\n*\n**********\n\n" |
| 142 | +``` |
| 143 | + |
| 144 | +--- |
| 145 | +### Remove .zip Extension |
| 146 | + |
| 147 | +Remove the `.zip` from our working file: |
| 148 | +``` |
| 149 | +mv $LLAMA_SERVER_ONE_ZIP $LLAMA_SERVER_ONE |
| 150 | +printf "\n**********\n*\n* FINISHED: Remove .zip Extension.\n*\n**********\n\n" |
| 151 | +``` |
| 152 | + |
| 153 | +--- |
| 154 | +### Download Model |
| 155 | + |
| 156 | +Let's download a small model. We'll use Google Gemma 1B Instruct v3, a surprisingly capable tiny model. |
| 157 | +``` |
| 158 | +MODEL_FILE="Google-Gemma-1B-Instruct-v3-q8_0.gguf" |
| 159 | +wget https://huggingface.co/bradhutchings/Brads-LLMs/resolve/main/models/$MODEL_FILE?download=true \ |
| 160 | + --show-progress --quiet -O model.gguf |
| 161 | +printf "\n**********\n*\n* FINISHED: Download Model.\n*\n**********\n\n" |
| 162 | +``` |
| 163 | + |
| 164 | +--- |
| 165 | +### Test Run |
| 166 | + |
| 167 | +Now we can test run `llama-server-one`, listening on localhost:8080. |
| 168 | +``` |
| 169 | +./$LLAMA_SERVER_ONE |
| 170 | +``` |
| 171 | + |
| 172 | +After starting up and loading the model, it should display: |
| 173 | + |
| 174 | +**main: server is listening on http://127.0.0.1:8080 - starting the main loop**<br/> |
| 175 | +**srv update_slots: all slots are idle** |
| 176 | + |
| 177 | +Hit `ctrl-C` on your keyboard to stop it. |
| 178 | + |
| 179 | +--- |
| 180 | +### Test Run on Public Interfaces |
| 181 | + |
| 182 | +If you'd like it to listen on all available interfaces, so you can connect from a browser on another computer: |
| 183 | +``` |
| 184 | +./$LLAMA_SERVER_ONE --host 0.0.0.0 |
| 185 | +``` |
| 186 | + |
| 187 | +After starting up and loading the model, it should display: |
| 188 | + |
| 189 | +**main: server is listening on http://0.0.0.0:8080 - starting the main loop**<br/> |
| 190 | +**srv update_slots: all slots are idle** |
| 191 | + |
| 192 | +Hit `ctrl-C` on your keyboard to stop it. |
| 193 | + |
| 194 | +--- |
| 195 | +Congratulations! You are ready to package your `llams-server-one` executable for deployment. Follow instructions in [Packaging-ls1.md](Packaging-ls1.md). |
0 commit comments