|
| 1 | +## Building llama-server |
| 2 | + |
| 3 | +Brad Hutchings<br/> |
| 4 | + |
| 5 | + |
| 6 | +This file contains instructions for building `llama.cpp` with `cosmocc` to yield a `llama-server` executable that will run on multiple platforms. |
| 7 | + |
| 8 | +### Environment Variables |
| 9 | + |
| 10 | +Let's define some environment variables: |
| 11 | +``` |
| 12 | +BUILDING_DIR="1-BUILDING-llama.cpp" |
| 13 | +printf "\n**********\n*\n* FINISHED: Environment Variables.\n*\n**********\n\n" |
| 14 | +``` |
| 15 | + |
| 16 | +_Note that if you copy each code block from the guide and paste it into your terminal, each block ends with a message so you won't lose your place in this guide._ |
| 17 | + |
| 18 | +--- |
| 19 | +### Build Dependencies |
| 20 | +I build with a freshly installed Ubuntu 24.04 VM. Here are some packages that are helpful in creating a working build system. You may need to install more. |
| 21 | +``` |
| 22 | +sudo apt install -y git python3-pip build-essential zlib1g-dev \ |
| 23 | + libffi-dev libssl-dev libbz2-dev libreadline-dev libsqlite3-dev \ |
| 24 | + liblzma-dev tk-dev python3-tk cmake zip npm |
| 25 | +printf "\n**********\n*\n* FINISHED: Build Dependencies.\n*\n**********\n\n" |
| 26 | +``` |
| 27 | + |
| 28 | +--- |
| 29 | +### Clone this Repo Locally |
| 30 | +Clone this repo into a `~\llama.cpp` directory. |
| 31 | +``` |
| 32 | +cd ~ |
| 33 | +git clone https://github.com/BradHutchings/llama-server-one.git $BUILDING_DIR |
| 34 | +printf "\n**********\n*\n* FINISHED: Clone this Repo Locally.\n*\n**********\n\n" |
| 35 | +``` |
| 36 | + |
| 37 | +**Optional:** Use the `work-in-progress` branch where I implement and test my own changes and where I test upstream changes from `llama.cpp`. |
| 38 | +``` |
| 39 | +cd ~/$BUILDING_DIR |
| 40 | +git checkout work-in-progress |
| 41 | +printf "\n**********\n*\n* FINISHED: Checkout work-in-progress.\n*\n**********\n\n" |
| 42 | +``` |
| 43 | + |
| 44 | +--- |
| 45 | +### Customize WebUI |
| 46 | +``` |
| 47 | +APP_NAME='Mmojo Chat' |
| 48 | +sed -i -e "s/<title>.*<\/title>/<title>$APP_NAME<\/title>/g" examples/server/webui/index.html |
| 49 | +sed -i -e "s/>llama.cpp<\/div>/>$APP_NAME<\/div>/g" examples/server/webui/src/components/Header.tsx |
| 50 | +cd examples/server/webui |
| 51 | +npm i |
| 52 | +npm run build |
| 53 | +cd ~/$BUILDING_DIR |
| 54 | +printf "\n**********\n*\n* FINISHED: Customize WebUI.\n*\n**********\n\n" |
| 55 | +``` |
| 56 | + |
| 57 | +--- |
| 58 | +### Make llama.cpp |
| 59 | +We use the old `Makefile` rather than CMake. We've updated the `Makefile` in this repo to build llama.cpp correctly. |
| 60 | +``` |
| 61 | +cd ~/$BUILDING_DIR |
| 62 | +export LLAMA_MAKEFILE=1 |
| 63 | +make clean |
| 64 | +make |
| 65 | +printf "\n**********\n*\n* FINISHED: Make llama.cpp.\n*\n**********\n\n" |
| 66 | +``` |
| 67 | + |
| 68 | +If the build is successful, it will end with this message: |
| 69 | + |
| 70 | + **NOTICE: The 'server' binary is deprecated. Please use 'llama-server' instead.** |
| 71 | + |
| 72 | +If the build fails and you've checked out the `work-in-progress` branch, well, it's in progess, so switch back to the `master` branch and build that. |
| 73 | + |
| 74 | +If the build fails on the `master` branch, please post a note in the [Discussions](https://github.com/BradHutchings/llama-server-one/discussions) area. |
| 75 | + |
| 76 | +#### List Directory |
| 77 | + |
| 78 | +At this point, you should see `llama-server` and other built binaries in the directory listing. |
| 79 | +``` |
| 80 | +ls -al |
| 81 | +printf "\n**********\n*\n* FINISHED: List Directory.\n*\n**********\n\n" |
| 82 | +``` |
| 83 | + |
| 84 | +--- |
| 85 | +### Install Cosmo |
| 86 | +``` |
| 87 | +mkdir -p cosmocc |
| 88 | +cd cosmocc |
| 89 | +wget https://cosmo.zip/pub/cosmocc/cosmocc.zip |
| 90 | +unzip cosmocc.zip |
| 91 | +rm cosmocc.zip |
| 92 | +cd .. |
| 93 | +printf "\n**********\n*\n* FINISHED: Install Cosmo.\n*\n**********\n\n" |
| 94 | +``` |
| 95 | + |
| 96 | +--- |
| 97 | +### Prepare to make llama.cpp with Cosmo |
| 98 | +``` |
| 99 | +export PATH="$(pwd)/cosmocc/bin:$PATH" |
| 100 | +export CC="cosmocc -I$(pwd)/cosmocc/include -L$(pwd)/cosmocc/lib" |
| 101 | +export CXX="cosmocc -I$(pwd)/cosmocc/include \ |
| 102 | + -I$(pwd)/cosmocc/include/third_party/libcxx \ |
| 103 | + -L$(pwd)/cosmocc/lib" |
| 104 | +export UNAME_S="cosmocc" |
| 105 | +export UNAME_P="cosmocc" |
| 106 | +export UNAME_M="cosmocc" |
| 107 | +printf "\n**********\n*\n* FINISHED: Prepare to make llama.cpp with Cosmo.\n*\n**********\n\n" |
| 108 | +``` |
| 109 | + |
| 110 | +--- |
| 111 | +### Make llama.cpp with Cosmo |
| 112 | +``` |
| 113 | +make clean |
| 114 | +make |
| 115 | +printf "\n**********\n*\n* FINISHED: Make llama.cpp with Cosmo\n*\n**********\n\n" |
| 116 | +``` |
| 117 | + |
| 118 | +If the build is successful, it will end with this message: |
| 119 | + |
| 120 | + **NOTICE: The 'server' binary is deprecated. Please use 'llama-server' instead.** |
| 121 | + |
| 122 | +If the build fails and you've checked out the `work-in-progress` branch, well, it's in progess, so switch back to the `master` branch and build that. |
| 123 | + |
| 124 | +If the build fails on the `master` branch, please post a note in the [Discussions](https://github.com/BradHutchings/llama-server-one/discussions) area. |
| 125 | + |
| 126 | +#### List Directory |
| 127 | + |
| 128 | +At this point, you should see `llama-server` and other built binaries in the directory listing. |
| 129 | +``` |
| 130 | +ls -al |
| 131 | +printf "\n**********\n*\n* FINISHED: List Directory.\n*\n**********\n\n" |
| 132 | +``` |
| 133 | + |
| 134 | +#### Verify Zip Archive |
| 135 | + |
| 136 | +`llama-server` is actually a zip acrhive with an "Actually Portable Executable" (APE) loader prefix. Let's verify the zip archive part: |
| 137 | +``` |
| 138 | +unzip -l llama-server |
| 139 | +printf "\n**********\n*\n* FINISHED: Verify Zip Archive.\n*\n**********\n\n" |
| 140 | +``` |
| 141 | + |
| 142 | +--- |
| 143 | +### Configuring llama-server-one |
| 144 | + |
| 145 | +Now that you've built `llama-server`, you're ready to configure it as `llama-server-one`. Follow instructions in [Configuring-ls1-Brads-Env.md](Configuring-ls1-Brads-Env.md). |
0 commit comments