-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
255 lines (236 loc) · 10.9 KB
/
Copy pathDockerfile
File metadata and controls
255 lines (236 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
FROM ubuntu:24.04 as rocm-base
USER root
WORKDIR /root
ARG ROCM_VERSION=7.2.4
# Install "minimum" dependencies (4GB?), register ROCm 7.2.3 repository, and install runtime + tools
RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends \
curl \
gnupg2 \
ca-certificates \
&& mkdir -p /etc/apt/keyrings \
\
# 1. Download and install the official AMD GPG key
&& curl -fsSL https://repo.radeon.com/rocm/rocm.gpg.key | gpg --dearmor | tee /etc/apt/keyrings/rocm.gpg > /dev/null \
\
# 2. Register the ROCm repository for Ubuntu 24.04
&& echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/rocm.gpg] https://repo.radeon.com/rocm/apt/$ROCM_VERSION noble main" \
| tee /etc/apt/sources.list.d/rocm.list \
\
# 3. Pin the repository to prioritize official AMD packages
&& echo 'Package: *\nPin: release o=repo.radeon.com\nPin-Priority: 600' \
| tee /etc/apt/preferences.d/rocm-pin-600 \
\
# 4. Install only what's needed for llama-server and monitoring
&& apt-get update && apt-get install -y --no-install-recommends \
rocm-hip-runtime \
amd-smi-lib \
rocminfo \
hipblas \
rocblas \
\
# 5. Cleanup to keep image slim
&& apt-get purge -y gnupg2 \
&& apt-get autoremove -y \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
FROM rocm-base as rocm-dev
RUN apt update && apt install -y \
# Vulkan related dev packages
libssl-dev curl libxcb-xinput0 libxcb-xinerama0 libxcb-cursor-dev libvulkan-dev glslc spirv-headers \
# ROCm packages
hip-dev \
hipblas-dev \
rocblas-dev \
rocm-dev \
rocwmma-dev \
# build essentials
build-essential \
cmake \
git \
libssl-dev \
curl \
libgomp1 \
ninja-build \
&& apt-get autoremove -y \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
FROM rocm-dev as stable-diffusion
ARG stable_diffusion_tag
# Build stable-diffusion.cpp (sd-server and sd-cli)
ARG GPU_TARGETS="gfx1151;gfx1200;gfx1201;gfx1100;gfx1101;gfx1102;gfx1030;gfx1031;gfx1032"
RUN apt update && apt install -y \
zip \
nodejs npm && \
curl -fsSL https://get.pnpm.io/install.sh | PNPM_VERSION=10.15.1 ENV="$HOME/.bashrc" SHELL="$(which bash)" bash - && \
. /root/.bashrc && \
echo $SD_GPU_TARGETS && \
echo stable_diffusion_tag=${stable_diffusion_tag} && \
git clone --branch ${stable_diffusion_tag} --depth 1 https://github.com/leejet/stable-diffusion.cpp && \
cd stable-diffusion.cpp && \
# Use the supported stable-ui variant of stable-diffusion front-end
git clone --depth 1 https://github.com/leejet/stable-ui.git examples/server/frontend && \
git submodule init && \
git submodule sync && \
git submodule update --recursive --depth 1 -- ./ ':!examples/server/frontend' && \
cd .. && \
mkdir stable-diffusion.cpp/build && \
cd stable-diffusion.cpp/build && \
cmake .. -G "Ninja" -DCMAKE_C_COMPILER=amdclang -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CXX_COMPILER=amdclang++ -DSD_HIPBLAS=ON -DCMAKE_BUILD_TYPE=Release -DGPU_TARGETS=$GPU_TARGETS -DAMDGPU_TARGETS=$GPU_TARGETS -DCMAKE_INSTALL_RPATH='$ORIGIN;$ORIGIN/../lib' -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON && \
cmake --build . --config Release && \
mkdir -p /opt/stable-diffusion/bin && \
mkdir -p /opt/stable-diffusion/lib && \
cp ./bin/sd-server /opt/stable-diffusion/bin/ && \
cp ./bin/sd-cli /opt/stable-diffusion/bin/ && \
cp ./bin/libstable-diffusion.so /opt/stable-diffusion/lib/ && \
cd .. && rm build -R && \
mkdir build && cd build && \
cmake .. -G "Ninja" -DSD_BUILD_SHARED_LIBS=ON -DSD_VULKAN=ON -DCMAKE_INSTALL_RPATH='$ORIGIN;$ORIGIN/../lib' -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON && \
cmake --build . --config Release && \
mkdir -p /opt/stable-diffusion/vulkan/bin && \
mkdir -p /opt/stable-diffusion/vulkan/lib && \
cp ./bin/sd-server /opt/stable-diffusion/vulkan/bin/ && \
cp ./bin/sd-cli /opt/stable-diffusion/vulkan/bin/ && \
cp ./bin/libstable-diffusion.so /opt/stable-diffusion/vulkan/lib/ && \
cd .. && \
apt remove -y git zip nodejs npm \
&& \
apt autoremove -y && \
apt clean && \
mkdir -p /opt/stable-diffusion && \
mv ./LICENSE /opt/stable-diffusion/LICENSE && \
chmod 444 /opt/stable-diffusion/LICENSE && \
rm -rf \
/root/stable-diffusion.cpp \
/var/lib/apt/lists/* \
/var/tmp/* \
/tmp/* \
/root/.local/share/pnpm
FROM rocm-dev as llama-cpp
WORKDIR /app
ARG GPU_TARGETS="gfx1151;gfx1200;gfx1201;gfx1100;gfx1101;gfx1102;gfx1030;gfx1031;gfx1032"
ARG llama_build
RUN echo llama_build=$llama_build && \
# git clone --branch ${llama_build} --depth 1 https://github.com/domvox/llama.cpp-turboquant-hip.git llama.cpp && \
git clone --branch ${llama_build} --depth 1 https://github.com/ggml-org/llama.cpp.git && \
cd llama.cpp && \
# export build_int="1" && \
export build_int=$(echo "$llama_build" | sed 's/[[:alpha:]]//g') && \
HIPCXX="$(hipconfig -l)/clang" HIP_PATH="$(hipconfig -R)" \
cmake -S . -B build \
-DLLAMA_BUILD_NUMBER="$build_int" \
-DGGML_HIP=ON \
-DCMAKE_INSTALL_RPATH='$ORIGIN;$ORIGIN/../lib' \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DGGML_HIP_ROCWMMA_FATTN=ON \
-DAMDGPU_TARGETS="$GPU_TARGETS" \
-DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON \
-DCMAKE_BUILD_TYPE=Release -DLLAMA_BUILD_TESTS=OFF \
&& cmake --build build --config Release -j$(nproc) && \
mkdir -p /opt/llama/bin && \
mv /app/llama.cpp/LICENSE /opt/llama && \
mv /app/llama.cpp/build/bin/* /opt/llama/bin/ && \
rm /app/llama.cpp/build -R && \
cmake -B build -DGGML_NATIVE=OFF \
-DLLAMA_BUILD_NUMBER="$build_int" \
-DGGML_VULKAN=ON \
-DCMAKE_INSTALL_RPATH='$ORIGIN;$ORIGIN/../lib' \
-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
-DLLAMA_BUILD_TESTS=OFF \
-DGGML_BACKEND_DL=ON \
-DGGML_CPU_ALL_VARIANTS=ON && \
cmake --build build --config Release -j$(nproc) && \
mkdir -p /opt/llama/vulkan/bin && \
mv /app/llama.cpp/build/bin/* /opt/llama/vulkan/bin/ && \
rm /app -rf
# Use our own rocm base and install our lxc base system and service
FROM rocm-base as llama-lxc
RUN apt-get update && \
apt-get remove -y unminimize && \
apt-get install -y --no-install-recommends \
ca-certificates \
software-properties-common && \
apt-get install -y --no-install-recommends \
libvulkan1 vulkan-tools mesa-vulkan-drivers \
curl \
openssh-server \
sudo \
# For convenience, instal nano
nano \
jq yq \
# Network tools such as ping and host command
iputils-ping \
bind9-host \
# Full systemd init entrypoint
init \
# Networkd based stack (better ipv6 and dhcp support than network interfaces when running on proxmox/lxc)
#networkd-dispatcher \
iproute2 \
# Python... (mostly for huggingface cli, to manage and cleanup model cache)
python3 python3-pip && \
pip3 install -U "huggingface_hub" --break-system-packages && \
apt-get -y remove dbus && \
apt-get -y autoremove && \
apt-get -y clean && \
rm -rf \
/var/lib/apt/lists/* \
/var/tmp/* \
/tmp/* && \
# Remove clutter messages on login
rm /etc/update-motd.d/10* && rm /etc/update-motd.d/50* && rm /etc/update-motd.d/60* && \
# Enable some service and remove a bunch of unwanted automatic timers
# Updates will have to be run manually or with new containers builds
systemctl enable systemd-networkd.service && \
rm /etc/systemd/system/timers.target.wants/apt* && \
rm /etc/systemd/system/timers.target.wants/dpkg* && \
rm /etc/systemd/system/timers.target.wants/e2scrub* && \
rm /etc/systemd/system/timers.target.wants/fstrim* && \
rm /etc/systemd/system/timers.target.wants/motd* && \
rm /usr/lib/systemd/system/apt-daily-upgrade.timer && \
rm /usr/lib/systemd/system/apt-daily.timer && \
rm /usr/lib/systemd/system/dpkg-db-backup.timer && \
rm /usr/lib/systemd/system/e2scrub_all.timer && \
rm /usr/lib/systemd/system/fstrim.timer && \
rm /lib/systemd/system/motd-news.timer && \
mkdir -p /home/ubuntu/.ssh && chown ubuntu:ubuntu /home/ubuntu/.ssh && \
sed -i -e '2iTERM=xterm-color\\' /root/.profile && \
cp /root/.profile /home/ubuntu/.profile && \
cp /root/.bashrc /home/ubuntu/.bashrc
# Get llama-swap binary directly from their github release download
# It seems simpler that way, and no extra delay for getting the latest llama-cpp, which is the most important
ARG llama_swap_build
RUN mkdir -p /opt/llama/llama-swap && \
curl -sL https://github.com/mostlygeek/llama-swap/releases/download/v${llama_swap_build}/llama-swap_${llama_swap_build}_linux_amd64.tar.gz > llama-swap.tar.gz && \
mkdir llama-swap && tar -xzvf llama-swap.tar.gz -C ./llama-swap && \
mv ./llama-swap/llama-swap /usr/local/bin/ && mv ./llama-swap/LICENSE.md /opt/llama/llama-swap/ && rm -rf llama-swap.tar.gz llama-swap
# Copy llama.cpp binaries that we just build in a previous stage
COPY --from=llama-cpp /opt/llama /opt/llama
# Copy the stable-diffusion binaries that we compiled in a previous stage
COPY --from=stable-diffusion /opt/stable-diffusion /opt/stable-diffusion
RUN \
# Create our own expected gid for video and render
# so that our host script can expect pre defined numbers
# that won't change
groupadd -g 444 render && \
groupadd -g 555 video_host && \
groupadd -g 777 render_host && \
# but also add the root user to every possible group (probably needed for podman local run)
usermod -aG video_host,render_host,video,render root && \
echo "PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/rocm/bin:/opt/llama/bin:/opt/stable-diffusion/bin\"" > /etc/environment && \
echo "LLAMA_CACHE=/root/data/models" >> /etc/environment && \
echo "ROCR_VISIBLE_DEVICES=0" >> /etc/environment && \
echo "HF_HUB_CACHE=/root/data/models/" >> /etc/environment && \
echo "/opt/rocm/lib" > /etc/ld.so.conf.d/10-rocm.conf && \
echo "/opt/rocm/lib/llvm//lib" >> /etc/ld.so.conf.d/10-rocm.conf
RUN ln -s /opt/llama/vulkan/bin/llama-server /usr/local/bin/llama-server-vulkan && \
ln -s /opt/stable-diffusion/vulkan/bin/sd-server /usr/local/bin/sd-server-vulkan
ADD container-files/llama-swap-launcher.sh /opt/llama/llama-swap/default-llama-swap-launcher
ADD container-files/prepare-llama.service /etc/systemd/system/
ADD --chmod=755 container-files/prepare.sh /usr/local/bin
ADD --chmod=755 container-files/llama-lxc-motd /etc/
ADD --chmod=755 container-files/cleanup-hf-cache.sh /usr/local/bin/
ADD container-files/llama-swap.service /etc/systemd/system/
ADD container-files/config.default.yaml /opt/llama/llama-swap
RUN mkdir -p /root/.cache && touch /root/.cache/motd.legal-displayed && \
systemctl enable llama-swap.service && \
systemctl enable prepare-llama.service && \
ln -s /etc/llama-lxc-motd /etc/update-motd.d/10-llama-lxc-motd
STOPSIGNAL SIGRTMIN+3
ENTRYPOINT ["/sbin/init"]