Skip to content

Commit 1c64e40

Browse files
authored
Add PyInstaller for apps/ (huggingface#907)
Build with pyinstaller.exe .\apps\stable_diffusion\web\shark_sd.spec normal flow works. exe is missing a few json files
1 parent 8cafe56 commit 1c64e40

19 files changed

+220
-28
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .txt2img import txt2img_inf
1+
from apps.stable_diffusion.scripts.txt2img import txt2img_inf

apps/stable_diffusion/shark_sd.spec

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
from PyInstaller.utils.hooks import collect_data_files
3+
from PyInstaller.utils.hooks import copy_metadata
4+
5+
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)
6+
7+
datas = []
8+
datas += collect_data_files('torch')
9+
datas += copy_metadata('torch')
10+
datas += copy_metadata('tqdm')
11+
datas += copy_metadata('regex')
12+
datas += copy_metadata('requests')
13+
datas += copy_metadata('packaging')
14+
datas += copy_metadata('filelock')
15+
datas += copy_metadata('numpy')
16+
datas += copy_metadata('tokenizers')
17+
datas += copy_metadata('importlib_metadata')
18+
datas += copy_metadata('torchvision')
19+
datas += copy_metadata('torch-mlir')
20+
datas += copy_metadata('diffusers')
21+
datas += copy_metadata('transformers')
22+
datas += copy_metadata('omegaconf')
23+
datas += copy_metadata('safetensors')
24+
datas += collect_data_files('gradio')
25+
datas += collect_data_files('iree')
26+
datas += collect_data_files('google-cloud-storage')
27+
datas += collect_data_files('shark')
28+
datas += [
29+
( 'resources/prompts.json', 'resources' ),
30+
( 'resources/model_db.json', 'resources' ),
31+
( 'resources/opt_flags.json', 'resources' ),
32+
( 'resources/base_model.json', 'resources' ),
33+
( 'web/logos/*', 'logos' )
34+
]
35+
36+
binaries = []
37+
38+
block_cipher = None
39+
40+
41+
a = Analysis(
42+
['web/index.py'],
43+
pathex=['.'],
44+
binaries=binaries,
45+
datas=datas,
46+
hiddenimports=['shark', 'shark.*', 'shark.shark_inference', 'shark_inference', 'iree.tools.core', 'gradio', 'apps'],
47+
hookspath=[],
48+
hooksconfig={},
49+
runtime_hooks=[],
50+
excludes=[],
51+
win_no_prefer_redirects=False,
52+
win_private_assemblies=False,
53+
cipher=block_cipher,
54+
noarchive=False,
55+
)
56+
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
57+
58+
exe = EXE(
59+
pyz,
60+
a.scripts,
61+
a.binaries,
62+
a.zipfiles,
63+
a.datas,
64+
[],
65+
name='shark_sd',
66+
debug=False,
67+
bootloader_ignore_signals=False,
68+
strip=False,
69+
upx=True,
70+
upx_exclude=[],
71+
runtime_tmpdir=None,
72+
console=True,
73+
disable_windowed_traceback=False,
74+
argv_emulation=False,
75+
target_arch=None,
76+
codesign_identity=None,
77+
entitlements_file=None,
78+
)
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
from PyInstaller.utils.hooks import collect_data_files
3+
from PyInstaller.utils.hooks import copy_metadata
4+
5+
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)
6+
7+
import os
8+
9+
spec_root = os.path.abspath(SPECPATH)
10+
shark_root = os.path.join(spec_root, "../..")
11+
apps_root = os.path.join(spec_root, "../"
12+
print(spec_root)
13+
print(shark_root)
14+
print(apps_root)
15+
16+
datas = []
17+
datas += collect_data_files('torch')
18+
datas += copy_metadata('torch')
19+
datas += copy_metadata('tqdm')
20+
datas += copy_metadata('regex')
21+
datas += copy_metadata('requests')
22+
datas += copy_metadata('packaging')
23+
datas += copy_metadata('filelock')
24+
datas += copy_metadata('numpy')
25+
datas += copy_metadata('tokenizers')
26+
datas += copy_metadata('importlib_metadata')
27+
datas += copy_metadata('torch-mlir')
28+
datas += copy_metadata('diffusers')
29+
datas += copy_metadata('transformers')
30+
datas += copy_metadata('omegaconf')
31+
datas += copy_metadata('safetensors')
32+
datas += collect_data_files('iree')
33+
datas += collect_data_files('google-cloud-storage')
34+
datas += collect_data_files('shark')
35+
datas += collect_data_files('apps')
36+
datas += [
37+
( 'resources/prompts.json', 'resources' ),
38+
( 'resources/model_db.json', 'resources' ),
39+
( 'resources/opt_flags.json', 'resources' ),
40+
( 'resources/base_model.json', 'resources' ),
41+
]
42+
43+
binaries = []
44+
45+
block_cipher = None
46+
47+
a = Analysis(
48+
['scripts/txt2img.py'],
49+
pathex=[spec_root, shark_root, apps_root],
50+
binaries=binaries,
51+
datas=datas,
52+
hiddenimports=['apps', 'shark', 'shark.*', 'shark.shark_inference', 'shark_inference', 'iree.tools.core' ],
53+
hookspath=[],
54+
hooksconfig={},
55+
runtime_hooks=[],
56+
excludes=[],
57+
win_no_prefer_redirects=False,
58+
win_private_assemblies=False,
59+
cipher=block_cipher,
60+
noarchive=False,
61+
)
62+
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
63+
64+
exe = EXE(
65+
pyz,
66+
a.scripts,
67+
a.binaries,
68+
a.zipfiles,
69+
a.datas,
70+
[],
71+
name='shark_sd_cli',
72+
debug=False,
73+
bootloader_ignore_signals=False,
74+
strip=False,
75+
upx=True,
76+
upx_exclude=[],
77+
runtime_tmpdir=None,
78+
console=True,
79+
disable_windowed_traceback=False,
80+
argv_emulation=False,
81+
target_arch=None,
82+
codesign_identity=None,
83+
entitlements_file=None,
84+
)

apps/stable_diffusion/src/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from .utils import (
1+
from apps.stable_diffusion.src.utils import (
22
args,
33
set_init_device_flags,
44
prompt_examples,
55
get_available_devices,
66
)
7-
from .pipelines import Text2ImagePipeline
8-
from .schedulers import get_schedulers
7+
from apps.stable_diffusion.src.pipelines import Text2ImagePipeline
8+
from apps.stable_diffusion.src.schedulers import get_schedulers
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
from .model_wrappers import SharkifyStableDiffusionModel
2-
from .opt_params import get_vae, get_unet, get_clip, get_tokenizer
1+
from apps.stable_diffusion.src.models.model_wrappers import (
2+
SharkifyStableDiffusionModel,
3+
)
4+
from apps.stable_diffusion.src.models.opt_params import (
5+
get_vae,
6+
get_unet,
7+
get_clip,
8+
get_tokenizer,
9+
)

apps/stable_diffusion/src/models/model_wrappers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
import sys
66
import traceback
77
import re
8-
from ..utils import compile_through_fx, get_opt_flags, base_models, args
8+
from apps.stable_diffusion.src.utils import (
9+
compile_through_fx,
10+
get_opt_flags,
11+
base_models,
12+
args,
13+
)
914

1015

1116
# These shapes are parameter dependent.

apps/stable_diffusion/src/models/opt_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from transformers import CLIPTokenizer
3-
from ..utils import models_db, args, get_shark_model
3+
from apps.stable_diffusion.src.utils import models_db, args, get_shark_model
44

55

66
hf_model_variant_map = {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
from .pipeline_shark_stable_diffusion_txt2img import Text2ImagePipeline
1+
from apps.stable_diffusion.src.pipelines.pipeline_shark_stable_diffusion_txt2img import (
2+
Text2ImagePipeline,
3+
)

apps/stable_diffusion/src/pipelines/pipeline_shark_stable_diffusion_txt2img.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
EulerAncestralDiscreteScheduler,
1414
DPMSolverMultistepScheduler,
1515
)
16-
from ..schedulers import SharkEulerDiscreteScheduler
17-
from .pipeline_shark_stable_diffusion_utils import StableDiffusionPipeline
16+
from apps.stable_diffusion.src.schedulers import SharkEulerDiscreteScheduler
17+
from apps.stable_diffusion.src.pipelines.pipeline_shark_stable_diffusion_utils import (
18+
StableDiffusionPipeline,
19+
)
1820

1921

2022
class Text2ImagePipeline(StableDiffusionPipeline):

apps/stable_diffusion/src/pipelines/pipeline_shark_stable_diffusion_utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
DPMSolverMultistepScheduler,
1414
)
1515
from shark.shark_inference import SharkInference
16-
from ..schedulers import SharkEulerDiscreteScheduler
17-
from ..models import (
16+
from apps.stable_diffusion.src.schedulers import SharkEulerDiscreteScheduler
17+
from apps.stable_diffusion.src.models import (
1818
SharkifyStableDiffusionModel,
1919
get_vae,
2020
get_clip,
2121
get_unet,
2222
get_tokenizer,
2323
)
24-
from ..utils import start_profiling, end_profiling, preprocessCKPT
24+
from apps.stable_diffusion.src.utils import (
25+
start_profiling,
26+
end_profiling,
27+
preprocessCKPT,
28+
)
2529

2630

2731
class StableDiffusionPipeline:

0 commit comments

Comments
 (0)