Skip to content

Commit 7ee25fe

Browse files
authored
chore: convert stable diffusion to submodule (#818)
* feat: integrate whisper.cpp as a submodule with patches * simplify naming * Not final state but wanted to get this up: with these edits now the apply-patches script perfectly lines up with the current whisper.cpp folder in the main branch * apply patches in CI * Update ci.yml * Update ci.yml * fix: register whisper.cpp submodule * pin whisper.cpp to commit * move to patches * patches * Refactor * convert stable diffusion to submodule * allow manual trigger
1 parent 1a5d1c2 commit 7ee25fe

40 files changed

Lines changed: 410 additions & 2962747 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
name: CI
22
on:
3+
workflow_dispatch:
34
push:
45
branches: [ master, main, fix ]
56
pull_request:

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "whisper.cpp"]
22
path = whisper.cpp
33
url = https://github.com/ggerganov/whisper.cpp.git
4+
[submodule "stable-diffusion.cpp"]
5+
path = stable-diffusion.cpp
6+
url = https://github.com/leejet/stable-diffusion.cpp.git

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ setup: # Initialize and configure all dependencies (submodules, patches, etc.)
9898
fi
9999
@echo "Applying whisper.cpp patches..."
100100
@export TMPDIR=$$(pwd)/o/tmp && ./whisper.cpp.patches/apply-patches.sh
101+
@if [ ! -f stable-diffusion.cpp/.git ]; then \
102+
echo "Initializing stable-diffusion.cpp submodule..."; \
103+
git submodule update --init stable-diffusion.cpp; \
104+
fi
105+
@echo "Applying stable-diffusion.cpp patches..."
106+
@export TMPDIR=$$(pwd)/o/tmp && ./stable-diffusion.cpp.patches/apply-patches.sh
101107
@echo "Setup complete!"
102108

103109

stable-diffusion.cpp

Submodule stable-diffusion.cpp added at 697d000
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
SD_DIR="$SCRIPT_DIR/../stable-diffusion.cpp"
7+
PATCHES_DIR="$SCRIPT_DIR/patches"
8+
LLAMAFILE_FILES_DIR="$SCRIPT_DIR/llamafile-files"
9+
10+
cd "$SD_DIR"
11+
12+
if [ -f "BUILD.mk" ]; then
13+
echo "Patches appear to be already applied. Skipping..."
14+
exit 0
15+
fi
16+
17+
echo "Applying patches to stable-diffusion.cpp submodule..."
18+
19+
echo "Applying modifications to upstream files..."
20+
for patch_file in "$PATCHES_DIR"/*.patch; do
21+
if [ -f "$patch_file" ]; then
22+
echo "Applying $(basename "$patch_file")..."
23+
patch -p0 < "$patch_file"
24+
fi
25+
done
26+
27+
echo "Copying llamafile-specific files..."
28+
cp "$LLAMAFILE_FILES_DIR/BUILD.mk" .
29+
cp "$LLAMAFILE_FILES_DIR/README.llamafile" .
30+
cp "$LLAMAFILE_FILES_DIR/main.cpp" .
31+
cp "$LLAMAFILE_FILES_DIR/darts.h" .
32+
cp "$LLAMAFILE_FILES_DIR/miniz.h" .
33+
cp "$LLAMAFILE_FILES_DIR/zip.c" .
34+
cp "$LLAMAFILE_FILES_DIR/zip.h" .
35+
36+
echo "Removing unnecessary files and directories..."
37+
rm -rf .github
38+
rm -rf assets
39+
rm -rf docs
40+
rm -rf examples
41+
rm -rf ggml
42+
rm -rf models
43+
rm -rf thirdparty
44+
rm -f .clang-format
45+
rm -f .dockerignore
46+
rm -f .gitignore
47+
rm -f .gitmodules
48+
rm -f CMakeLists.txt
49+
rm -f Dockerfile
50+
rm -f format-code.sh
51+
rm -f README.md
52+
53+
echo ""
54+
echo "Patches applied successfully!"
55+
echo "Note: These changes are not committed to the submodule."
56+
echo "To reset the submodule to its clean state, run:"
57+
echo " cd stable-diffusion.cpp && git reset --hard && git clean -fd"

stable-diffusion.cpp/BUILD.mk renamed to stable-diffusion.cpp.patches/llamafile-files/BUILD.mk

File renamed without changes.

stable-diffusion.cpp/README.llamafile renamed to stable-diffusion.cpp.patches/llamafile-files/README.llamafile

File renamed without changes.

stable-diffusion.cpp/darts.h renamed to stable-diffusion.cpp.patches/llamafile-files/darts.h

File renamed without changes.

stable-diffusion.cpp/main.cpp renamed to stable-diffusion.cpp.patches/llamafile-files/main.cpp

File renamed without changes.

stable-diffusion.cpp/miniz.h renamed to stable-diffusion.cpp.patches/llamafile-files/miniz.h

File renamed without changes.

0 commit comments

Comments
 (0)