huchukato commited on
Commit
4b2323d
·
verified ·
1 Parent(s): 3681e18

Upload kohyaprov.sh

Browse files
Files changed (1) hide show
  1. kohyaprov.sh +93 -0
kohyaprov.sh ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # This file will be sourced in init.sh
3
+ # Namespace functions with provisioning_
4
+
5
+ # https://raw.githubusercontent.com/ai-dock/kohya_ss/main/config/provisioning/default.sh
6
+
7
+ ### Edit the following arrays to suit your workflow - values must be quoted and separated by newlines or spaces.
8
+
9
+ DISK_GB_REQUIRED=30
10
+
11
+ PIP_PACKAGES=(
12
+ #"package==version"
13
+ )
14
+
15
+ CHECKPOINT_MODELS=(
16
+ "https://huggingface.co/huchukato/favs/resolve/main/ckpt/pimp-my-pony-v1.safetensors"
17
+ #"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors"
18
+ #"https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors"
19
+ )
20
+
21
+
22
+ ### DO NOT EDIT BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING ###
23
+
24
+ function provisioning_start() {
25
+ source /opt/ai-dock/etc/environment.sh
26
+ source /opt/ai-dock/bin/venv-set.sh kohya
27
+
28
+ DISK_GB_AVAILABLE=$(($(df --output=avail -m "${WORKSPACE}" | tail -n1) / 1000))
29
+ DISK_GB_USED=$(($(df --output=used -m "${WORKSPACE}" | tail -n1) / 1000))
30
+ DISK_GB_ALLOCATED=$(($DISK_GB_AVAILABLE + $DISK_GB_USED))
31
+ provisioning_print_header
32
+ provisioning_get_mamba_packages
33
+ provisioning_get_pip_packages
34
+ provisioning_get_models \
35
+ "${WORKSPACE}/storage/stable_diffusion/models/ckpt" \
36
+ "${CHECKPOINT_MODELS[@]}"
37
+
38
+ provisioning_print_end
39
+ }
40
+
41
+ function provisioning_get_pip_packages() {
42
+ if [[ -n $PIP_PACKAGES ]]; then
43
+ "$KOHYA_VENV_PIP" install --no-cache-dir ${PIP_PACKAGES[@]}
44
+ fi
45
+ }
46
+
47
+ function provisioning_get_models() {
48
+ if [[ -z $2 ]]; then return 1; fi
49
+ dir="$1"
50
+ mkdir -p "$dir"
51
+ shift
52
+ if [[ $DISK_GB_ALLOCATED -ge $DISK_GB_REQUIRED ]]; then
53
+ arr=("$@")
54
+ else
55
+ printf "WARNING: Low disk space allocation - Only the first model will be downloaded!\n"
56
+ arr=("$1")
57
+ fi
58
+
59
+ printf "Downloading %s model(s) to %s...\n" "${#arr[@]}" "$dir"
60
+ for url in "${arr[@]}"; do
61
+ printf "Downloading: %s\n" "${url}"
62
+ provisioning_download "${url}" "${dir}"
63
+ printf "\n"
64
+ done
65
+ }
66
+
67
+ function provisioning_print_header() {
68
+ printf "\n##############################################\n# #\n# Provisioning container #\n# #\n# This will take some time #\n# #\n# Your container will be ready on completion #\n# #\n##############################################\n\n"
69
+ if [[ $DISK_GB_ALLOCATED -lt $DISK_GB_REQUIRED ]]; then
70
+ printf "WARNING: Your allocated disk size (%sGB) is below the recommended %sGB - Some models will not be downloaded\n" "$DISK_GB_ALLOCATED" "$DISK_GB_REQUIRED"
71
+ fi
72
+ }
73
+
74
+ function provisioning_print_end() {
75
+ printf "\nProvisioning complete: Web UI will start now\n\n"
76
+ }
77
+
78
+ # Download from $1 URL to $2 file path
79
+ function provisioning_download() {
80
+ if [[ -n $HF_TOKEN && $1 =~ ^https://([a-zA-Z0-9_-]+\.)?huggingface\.co(/|$|\?) ]]; then
81
+ auth_token="$HF_TOKEN"
82
+ elif
83
+ [[ -n $CIVITAI_TOKEN && $1 =~ ^https://([a-zA-Z0-9_-]+\.)?civitai\.com(/|$|\?) ]]; then
84
+ auth_token="$CIVITAI_TOKEN"
85
+ fi
86
+ if [[ -n $auth_token ]];then
87
+ wget --header="Authorization: Bearer $auth_token" -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1"
88
+ else
89
+ wget -qnc --content-disposition --show-progress -e dotbytes="${3:-4M}" -P "$2" "$1"
90
+ fi
91
+ }
92
+
93
+ provisioning_start