-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
99 lines (81 loc) · 3.51 KB
/
Makefile
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
PROJECT:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
GIT_CLONE_SPARSE=GIT_LFS_SKIP_SMUDGE=1 git clone --depth 1
# can be original or split_einsum
ATTENTION_TYPE=split_einsum
ORIGINAL_MODEL_FILES=Unet.mlmodelc
SPLIT_EINSUM_MODEL_FILES=UnetChunk1.mlmodelc UnetChunk2.mlmodelc
MODEL_REPO_PATH=$(ATTENTION_TYPE)/compiled
REMOVE_MODEL_FILES=
MODEL_FILES=
MODEL_FILES+=SafetyChecker.mlmodelc
MODEL_FILES+=TextEncoder.mlmodelc
MODEL_FILES+=VAEDecoder.mlmodelc
MODEL_FILES+=merges.txt
MODEL_FILES+=vocab.json
ifeq ($(ATTENTION_TYPE),split_einsum)
# If we target iOS, we need to use chunked Unet, which is only available
# with MODEL_REPO_PATH `split_einsum/compiled`.
MODEL_FILES+=$(SPLIT_EINSUM_MODEL_FILES)
REMOVE_MODEL_FILES+=$(ORIGINAL_MODEL_FILES)
else
# We need to remove the split_einsum chunk files because the
# StableDiffusionPipeline will try to load them if they exist on disk
# at all - and then fail, because they're only stubs.
MODEL_FILES+=$(ORIGINAL_MODEL_FILES)
REMOVE_MODEL_FILES+=$(SPLIT_EINSUM_MODEL_FILES)
endif
MODEL_SPARSE_CHECKOUT_FILES=$(addprefix $(MODEL_REPO_PATH)/,$(MODEL_FILES))
MODEL_SPARSE_CHECKOUT_REMOVE_FILES=$(addprefix $(MODEL_REPO_PATH)/,$(REMOVE_MODEL_FILES))
MODEL_SPARSE_CHECKOUT_PATTERNS=$(MODEL_SPARSE_CHECKOUT_FILES)
SPACE:=$(subst ,, )
COMMA:=,
MODEL_SPARSE_CHECKOUT_PATTERN=$(subst $(SPACE),$(COMMA),$(MODEL_SPARSE_CHECKOUT_PATTERNS))
.PHONY: dev download zips aars clean clean-all serve uninstall-models
dev: download ApplicationSupport
download: compiled-models/sd1.4 compiled-models/sd1.5 compiled-models/sd2
zips: compiled-models/sd1.4.zip.00 compiled-models/sd1.5.zip.00 compiled-models/sd2.zip.00
aars: compiled-models/sd1.4.aar.00 compiled-models/sd1.5.aar.00 compiled-models/sd2.aar.00
clean:
@echo "Note: run 'make clean-all' to remove downloaded repos, which are large"
rm -rf compiled-models/*.zip*
rm -rf compiled-models/*.aar*
find compiled-models -maxdepth 1 -type l -delete
clean-all:
rm -rf compiled-models
# Targets to clone each model's repo from HuggingFace,
# then hydrate the large files we care about using `git lfs`
compiled-models/sd1.4.repo:
$(GIT_CLONE_SPARSE) https://huggingface.co/apple/coreml-stable-diffusion-v1-4 $@
@make [email protected]
compiled-models/sd1.5.repo:
$(GIT_CLONE_SPARSE) https://huggingface.co/apple/coreml-stable-diffusion-v1-5 $@
@make [email protected]
compiled-models/sd2.repo:
$(GIT_CLONE_SPARSE) https://huggingface.co/apple/coreml-stable-diffusion-2-base $@
@make [email protected]
compiled-models/%.repo.checkout: compiled-models/%.repo
cd $^ && git lfs fetch --include $(MODEL_SPARSE_CHECKOUT_PATTERN)
cd $^ && git lfs checkout $(MODEL_SPARSE_CHECKOUT_FILES)
cd $^ && rm -rf $(MODEL_SPARSE_CHECKOUT_REMOVE_FILES)
# Make a symlink directly to the subdirectory of the repo that contains the
# models we want to use.
#
# This makes it easier to build a zip with the paths we want.
compiled-models/%: compiled-models/%.repo
ln -sf $(PROJECT)/$^/$(MODEL_REPO_PATH) $@
# Zip directories
compiled-models/%.zip: compiled-models/%
cd compiled-models && zip -r $(notdir $@) $(notdir $^)/
# Archive directories with Apple Archive, which can be decompressed
# using the standard library.
compiled-models/%.aar: compiled-models/%
aa archive -d $^ -o $@
# Split files into 1900 MB chunks
compiled-models/%.00: compiled-models/%
split -b 1900m -d $^ $^.
ApplicationSupport:
ln -s $(HOME)/Library/Application\ Support/tl.jake.Gauss/ $@
serve: aars
cd compiled-models && python3 -m http.server 8080
uninstall-models: ApplicationSupport
rm -rf ./ApplicationSupport/models