-
Notifications
You must be signed in to change notification settings - Fork 32
/
build-models.sh
executable file
·60 lines (51 loc) · 1.54 KB
/
build-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
#!/bin/zsh
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/homebrew/Caskroom/miniconda/base/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/opt/homebrew/Caskroom/miniconda/base/etc/profile.d/conda.sh" ]; then
. "/opt/homebrew/Caskroom/miniconda/base/etc/profile.d/conda.sh"
else
export PATH="/opt/homebrew/Caskroom/miniconda/base/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
set -xeo pipefail
conda activate coreml_stable_diffusion
DESTINATION="compiled-models"
build() {
local model_version
model_version="$1"
local dest
dest="$2"
mkdir -p "$DESTINATION"
python -m python_coreml_stable_diffusion.torch2coreml \
--convert-unet --convert-text-encoder --convert-vae-decoder --convert-safety-checker \
--model-version "$model_version" \
--bundle-resources-for-swift-cli \
--chunk-unet \
-o "../$DESTINATION/$dest"
mv "../$DESTINATION/$dest/Resources/Unet.mlmodelc" "../$DESTINATION/$dest"
mv "../$DESTINATION/$dest/{Resources,$dest}"
}
compress() {
local model_version
local dest="$1"
pushd "$DESTINATION/$dest"
if [[ ! -f "$dest.zip" ]] ; then
zip -r $dest.zip $dest/
fi
split -b 1900m -d $dest.zip $dest.zip.
popd
}
# pushd ml-stable-diffusion
# build stabilityai/stable-diffusion-2-base sd2.0
# build CompVis/stable-diffusion-v1-4 sd1.4
# build runwayml/stable-diffusion-v1-5 sd1.5
# popd
compress sd2.0
compress sd1.4
compress sd1.5