Skip to content

Commit

Permalink
Fix the .exe (#2101)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetters-amd authored Mar 22, 2024
1 parent ca69fd5 commit 44ef35f
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 215 deletions.
4 changes: 2 additions & 2 deletions apps/shark_studio/api/sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def __init__(
# "num_loras": num_loras,
"height": height,
"width": width,
# "precision": precision,
# "max_length": self.model_max_length,
"precision": precision,
"max_length": self.model_max_length,
},
"vae_encode": {
"hf_model_name": base_model_id,
Expand Down
14 changes: 5 additions & 9 deletions apps/shark_studio/studio_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,23 @@
datas += copy_metadata("pyyaml")
datas += copy_metadata("huggingface-hub")
datas += copy_metadata("gradio")
datas += copy_metadata("scipy")
datas += collect_data_files("torch")
datas += collect_data_files("tokenizers")
datas += collect_data_files("tiktoken")
datas += collect_data_files("accelerate")
datas += collect_data_files("diffusers")
datas += collect_data_files("transformers")
datas += collect_data_files("pytorch_lightning")
datas += collect_data_files("skimage")
datas += collect_data_files("gradio")
datas += collect_data_files("gradio_client")
datas += collect_data_files("iree")
datas += collect_data_files("iree", include_py_files=True)
datas += collect_data_files("shark", include_py_files=True)
datas += collect_data_files("timm", include_py_files=True)
datas += collect_data_files("tqdm")
datas += collect_data_files("tkinter")
datas += collect_data_files("webview")
datas += collect_data_files("sentencepiece")
datas += collect_data_files("jsonschema")
datas += collect_data_files("jsonschema_specifications")
datas += collect_data_files("cpuinfo")
datas += collect_data_files("cv2")
datas += collect_data_files("scipy", include_py_files=True)
datas += [
("web/ui/css/*", "ui/css"),
("web/ui/js/*", "ui/js"),
Expand All @@ -59,7 +55,6 @@

# hidden imports for pyinstaller
hiddenimports = ["shark", "apps"]
#hiddenimports += [x for x in collect_submodules("skimage") if "tests" not in x]
hiddenimports += [x for x in collect_submodules("gradio") if "tests" not in x]
hiddenimports += [
x for x in collect_submodules("diffusers") if "tests" not in x
Expand All @@ -71,4 +66,5 @@
if not any(kw in x for kw in blacklist)
]
hiddenimports += [x for x in collect_submodules("iree") if "tests" not in x]
hiddenimports += ["iree._runtime"]
hiddenimports += ["iree._runtime"]
hiddenimports += collect_submodules('scipy')
2 changes: 1 addition & 1 deletion apps/shark_studio/web/configs/default_sd_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"resample_type": "Nearest Neighbor",
"controlnets": {},
"embeddings": {}
}
}
1 change: 1 addition & 0 deletions apps/shark_studio/web/index.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from multiprocessing import Process, freeze_support
freeze_support()
from PIL import Image

import os
Expand Down
14 changes: 8 additions & 6 deletions apps/shark_studio/web/ui/sd.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
get_checkpoints_path,
get_checkpoints,
get_configs_path,
write_default_sd_config,
)
from apps.shark_studio.api.sd import (
sd_model_map,
Expand Down Expand Up @@ -631,14 +632,15 @@ def base_model_changed(base_model_id):
with gr.Tab(label="Config", id=102) as sd_tab_config:
with gr.Column(elem_classes=["sd-right-panel"]):
with gr.Row(elem_classes=["fill"]):
Path(get_configs_path()).mkdir(parents=True, exist_ok=True)
default_config_file = os.path.join(
get_configs_path(),
"default_sd_config.json",
)
write_default_sd_config(default_config_file)
sd_json = gr.JSON(
elem_classes=["fill"],
value=view_json_file(
os.path.join(
get_configs_path(),
"default_sd_config.json",
)
),
value=view_json_file(default_config_file),
)
with gr.Row():
with gr.Column(scale=3):
Expand Down
32 changes: 32 additions & 0 deletions apps/shark_studio/web/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,38 @@
"*.safetensors",
)

default_sd_config = r"""{
"prompt": [
"a photo taken of the front of a super-car drifting on a road near mountains at high speeds with smoke coming off the tires, front angle, front point of view, trees in the mountains of the background, ((sharp focus))"
],
"negative_prompt": [
"watermark, signature, logo, text, lowres, ((monochrome, grayscale)), blurry, ugly, blur, oversaturated, cropped"
],
"sd_init_image": [null],
"height": 512,
"width": 512,
"steps": 50,
"strength": 0.8,
"guidance_scale": 7.5,
"seed": "-1",
"batch_count": 1,
"batch_size": 1,
"scheduler": "EulerDiscrete",
"base_model_id": "stabilityai/stable-diffusion-2-1-base",
"custom_weights": null,
"custom_vae": null,
"precision": "fp16",
"device": "AMD Radeon RX 7900 XTX => vulkan://0",
"ondemand": false,
"repeatable_seeds": false,
"resample_type": "Nearest Neighbor",
"controlnets": {},
"embeddings": {}
}"""

def write_default_sd_config(path):
with open(path, "w") as f:
f.write(default_sd_config)

def safe_name(name):
return name.replace("/", "_").replace("-", "_")
Expand Down
56 changes: 11 additions & 45 deletions process_skipfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from distutils.sysconfig import get_python_lib
import fileinput
from pathlib import Path
import os

# Temporary workaround for transformers/__init__.py.
path_to_transformers_hook = Path(
Expand All @@ -16,51 +17,16 @@
with open(path_to_transformers_hook, "w") as f:
f.write("module_collection_mode = 'pyz+py'")

path_to_skipfiles = Path(get_python_lib() + "/torch/_dynamo/skipfiles.py")
paths_to_skipfiles = [Path(get_python_lib() + "/torch/_dynamo/skipfiles.py"), Path(get_python_lib() + "/torch/_dynamo/trace_rules.py")]

modules_to_comment = ["abc,", "os,", "posixpath,", "_collections_abc,"]
startMonitoring = 0
for line in fileinput.input(path_to_skipfiles, inplace=True):
if "SKIP_DIRS = " in line:
startMonitoring = 1
print(line, end="")
elif startMonitoring in [1, 2]:
if "]" in line:
startMonitoring += 1
for path in paths_to_skipfiles:
if not os.path.isfile(path):
continue
for line in fileinput.input(path, inplace=True):
if "[_module_dir(m) for m in BUILTIN_SKIPLIST]" in line and "x.__name__ for x in BUILTIN_SKIPLIST" not in line:
print(f"{line.rstrip()} + [x.__name__ for x in BUILTIN_SKIPLIST]")
elif "(_module_dir(m) for m in BUILTIN_SKIPLIST)" in line and "x.__name__ for x in BUILTIN_SKIPLIST" not in line:
print(line, end="")
print(f"SKIP_DIRS.extend(filter(None, (x.__name__ for x in BUILTIN_SKIPLIST)))")
else:
flag = True
for module in modules_to_comment:
if module in line:
if not line.startswith("#"):
print(f"#{line}", end="")
else:
print(f"{line[1:]}", end="")
flag = False
break
if flag:
print(line, end="")
else:
print(line, end="")

# For getting around scikit-image's packaging, laze_loader has had a patch merged but yet to be released.
# Refer: https://github.com/scientific-python/lazy_loader
path_to_lazy_loader = Path(get_python_lib() + "/lazy_loader/__init__.py")

for line in fileinput.input(path_to_lazy_loader, inplace=True):
if 'stubfile = filename if filename.endswith("i")' in line:
print(
' stubfile = (filename if filename.endswith("i") else f"{os.path.splitext(filename)[0]}.pyi")',
end="",
)
else:
print(line, end="")

# For getting around timm's packaging.
# Refer: https://github.com/pyinstaller/pyinstaller/issues/5673#issuecomment-808731505
path_to_timm_activations = Path(get_python_lib() + "/timm/layers/activations_jit.py")
for line in fileinput.input(path_to_timm_activations, inplace=True):
if "@torch.jit.script" in line:
print("@torch.jit._script_if_tracing", end="\n")
else:
print(line, end="")
print(line, end="")
34 changes: 0 additions & 34 deletions requirements-importer-macos.txt

This file was deleted.

41 changes: 0 additions & 41 deletions requirements-importer.txt

This file was deleted.

20 changes: 3 additions & 17 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
setuptools
wheel

shark-turbine @ git+https://github.com/nod-ai/SHARK-Turbine#egg=shark-turbine&subdirectory=core
turbine-models @ git+https://github.com/nod-ai/SHARK-Turbine#egg=turbine-models&subdirectory=models
torch==2.3.0.dev20240305
shark-turbine @ git+https://github.com/nod-ai/SHARK-Turbine.git@ean-sd-fp16#subdirectory=core
turbine-models @ git+https://github.com/nod-ai/SHARK-Turbine.git@ean-sd-fp16#subdirectory=models

# SHARK Runner
tqdm
Expand All @@ -31,25 +32,10 @@ altair
omegaconf
# 0.3.2 doesn't have binaries for arm64
safetensors==0.3.1
opencv-python
scikit-image
pytorch_lightning # for runwayml models
tk
pywebview
sentencepiece
py-cpuinfo
tiktoken # for codegen
joblib # for langchain
timm # for MiniGPT4
langchain
einops # for zoedepth
pydantic==2.4.1 # pin until pyinstaller-hooks-contrib works with beta versions
mpmath==1.3.0

# Keep PyInstaller at the end. Sometimes Windows Defender flags it but most folks can continue even if it errors
pefile
pyinstaller

# For quantized GPTQ models
optimum
auto_gptq
Loading

0 comments on commit 44ef35f

Please sign in to comment.