From 55929473624971fe868b091ac8c5a9814c75bd43 Mon Sep 17 00:00:00 2001 From: Komninos Date: Thu, 18 Apr 2024 17:16:12 +0300 Subject: [PATCH 1/3] Create Dockerfile --- Dockerfile | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e537fc16 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,82 @@ +# SimpleTuner needs CU118 +FROM nvidia/cuda:11.8.0-runtime-ubuntu22.04 + +# /workspace is the default volume for Runpod & other hosts +WORKDIR /workspace + +# Update apt-get +RUN apt-get update -y + +# Prevents different commands from being stuck by waiting +# on user input during build +ENV DEBIAN_FRONTEND noninteractive + +# Install openssh & git +RUN apt-get install -y --no-install-recommends openssh-server \ + openssh-client \ + git \ + git-lfs + +# Installl misc unix libraries +RUN apt-get install -y wget \ + curl \ + tmux \ + tldr \ + nvtop \ + vim \ + rsync \ + net-tools \ + less \ + iputils-ping \ + 7zip \ + zip \ + unzip \ + htop \ + inotify-tools + +# Set up git to support LFS, and to store credentials; useful for Huggingface Hub +RUN git config --global credential.helper store && \ + git lfs install + +# Install Python VENV +RUN apt-get install -y python3.10-venv + +# Ensure SSH access. Not needed for Runpod but is required on Vast and other Docker hosts +EXPOSE 22/tcp + +# Install misc Python & CUDA Libraries +RUN apt-get update -y && apt-get install -y python3 python3-pip libcudnn8 libcudnn8-dev +RUN python3 -m pip install pip --upgrade + +# HF +ARG HUGGING_FACE_HUB_TOKEN +ENV HUGGING_FACE_HUB_TOKEN=$HUGGING_FACE_HUB_TOKEN +ENV HF_HOME=/workspace/huggingface + +RUN pip3 install "huggingface_hub[cli]" + +RUN huggingface-cli login --token "$HUGGING_FACE_HUB_TOKEN" --add-to-git-credential + +# WanDB +ARG WANDB_TOKEN +ENV WANDB_TOKEN=$WANDB_TOKEN + +RUN pip3 install wandb + +RUN wandb login "$WANDB_TOKEN" + +# Clone SimpleTuner +RUN git clone https://github.com/bghira/SimpleTuner --branch release +# RUN git clone https://github.com/bghira/SimpleTuner --branch main # Uncomment to use latest (possibly unstable) version + +# Install SimpleTuner +RUN pip3 install poetry +RUN cd SimpleTuner && python3 -m venv .venv && poetry install --no-root +RUN chmod +x SimpleTuner/train_sdxl.sh +RUN chmod +x SimpleTuner/train_sd2x.sh + +# Copy start script with exec permissions +COPY --chmod=755 docker-start.sh /start.sh + +# Dummy entrypoint +ENTRYPOINT [ "/start.sh" ] From 60b251e59b70448215e0bf7c0b082616d3ac133a Mon Sep 17 00:00:00 2001 From: Komninos Date: Thu, 18 Apr 2024 17:17:00 +0300 Subject: [PATCH 2/3] Create docker-start.sh --- docker-start.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 docker-start.sh diff --git a/docker-start.sh b/docker-start.sh new file mode 100644 index 00000000..748376f3 --- /dev/null +++ b/docker-start.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Export useful ENV variables, including all Runpod specific vars, to /etc/rp_environment +# This file can then later be sourced in a login shell +echo "Exporting environment variables..." +printenv | + grep -E '^RUNPOD_|^PATH=|^HF_HOME=|^HUGGING_FACE_HUB_TOKEN=|^_=' | + sed 's/^\(.*\)=\(.*\)$/export \1="\2"/' >>/etc/rp_environment + +# Add it to Bash login script +echo 'source /etc/rp_environment' >>~/.bashrc + +# Vast.ai uses $SSH_PUBLIC_KEY +if [[ $SSH_PUBLIC_KEY ]]; then + PUBLIC_KEY="${SSH_PUBLIC_KEY}" +fi + +# Runpod uses $PUBLIC_KEY +if [[ $PUBLIC_KEY ]]; then + mkdir -p ~/.ssh + chmod 700 ~/.ssh + echo "${PUBLIC_KEY}" >>~/.ssh/authorized_keys + chmod 700 -R ~/.ssh +fi + +service ssh start + +sleep infinity From c4b188d3ec0dac5279afb3540908519fe3f03000 Mon Sep 17 00:00:00 2001 From: Komninos Date: Thu, 18 Apr 2024 17:34:29 +0300 Subject: [PATCH 3/3] Update docker-start.sh --- docker-start.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-start.sh b/docker-start.sh index 748376f3..328dae53 100644 --- a/docker-start.sh +++ b/docker-start.sh @@ -23,6 +23,8 @@ if [[ $PUBLIC_KEY ]]; then chmod 700 -R ~/.ssh fi +# Start SSH server service ssh start +# 🫡 sleep infinity