-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathauto_prepare_sd_models.sh
130 lines (111 loc) · 3.52 KB
/
auto_prepare_sd_models.sh
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
#!/usr/bin/bash
# for Mac temp files cleaning
find . -name "._*" -type f -print
find . -name "._*" -type f -delete
# Default values for command line options
auto_confirm=""
# Parse command line options
while getopts ":nyc" opt; do
case $opt in
n)
auto_confirm="no"
;;
y)
auto_confirm="yes"
;;
c)
auto_confirm="cancel"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
# Function to display the confirmation prompt
confirm() {
echo "Parsing input params..."
if [ "$auto_confirm" == "yes" ]; then
return 0
elif [ "$auto_confirm" == "no" ]; then
return 1
elif [ "$auto_confirm" == "cancel" ]; then
echo "CANCELED..."
exit
fi
echo "WARNING: to prepare safetensors_2_onnx converter env,
this cli-tool needs to force reinstalling all necessary pack,
from conda to current-conda-env's pip state."
echo "IT'S A High-Risk Operation! be careful you choose."
while true; do
read -r -p "Ops: yes no [y/n] or cancel [c] ?" yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
[Cc]*)
echo "CANCELED..."
exit
;;
*) echo "Please answer YES, NO, or CANCEL." ;;
esac
done
}
env_skipped() {
echo "Skip converter environment security..."
echo "Try to convert without env_check..."
}
env_prepare() {
echo "Installing converter environment..."
conda uninstall safetensors transformers diffusers
conda uninstall torch torchaudio torchvision
conda uninstall llvm-openmp intel-openmp
conda uninstall pyarrow pillow image
pip install pip_search
conda install nomkl
conda install numpy scipy pandas tensorflow
pip install regex protobuf
pip install pyarrow pillow image
pip install numpy scipy pandas tensorflow
pip install torch==2.2.0 torchaudio==2.2.0 torchvision==0.17.0
pip install safetensors transformers==4.40.0 diffusers
pip install optimum
echo "Installed..."
}
# Function: Auto convert Stable Diffusion models
auto_convert_sd() {
echo "===========================Auto converting start==========================="
optimum-cli export onnx --model runwayml/stable-diffusion-v1-5 sd-base-model/onnx-sd-v15/
optimum-cli export onnx --model stabilityai/sd-turbo sd-base-model/onnx-sd-turbo/
echo "===========================Auto converting done.==========================="
}
# Function: Auto download Stable Diffusion models
auto_download_sd() {
echo "========================Auto cloning official start========================"
# Check if the onnx-official-sd-v15 directory exists
if [ -d "sd-base-model/onnx-official-sd-v15" ]; then
echo "Directory onnx-official-sd-v15 already exists. Skipping clone."
else
git clone https://huggingface.co/runwayml/stable-diffusion-v1-5 -b onnx sd-base-model/onnx-official-sd-v15/
fi
# Check if the onnx-sd-turbo directory exists
if [ -d "sd-base-model/onnx-sd-v15" ]; then
echo "Directory onnx-sd-v15 already exists. Skipping clone."
else
git clone https://huggingface.co/Windsander/onnx-sd-v15 sd-base-model/onnx-sd-v15/
fi
# Check if the onnx-sd-turbo directory exists
if [ -d "sd-base-model/onnx-sd-turbo" ]; then
echo "Directory onnx-sd-turbo already exists. Skipping clone."
else
git clone https://huggingface.co/Windsander/onnx-sd-turbo sd-base-model/onnx-sd-turbo/
fi
echo "========================Auto cloning official done.========================"
}
# do script
if confirm; then
env_prepare
auto_convert_sd
else
env_skipped
auto_download_sd
fi