lllyasviel commited on
Commit
27db148
1 Parent(s): ef3acbf
Files changed (3) hide show
  1. launch.py +23 -1
  2. modules/launch_util.py +81 -1
  3. requirements_versions.txt +12 -0
launch.py CHANGED
@@ -1,7 +1,11 @@
1
  import os
2
  import sys
 
3
 
4
- from modules.launch_util import commit_hash, fooocus_tag
 
 
 
5
 
6
 
7
  def prepare_environment():
@@ -21,6 +25,24 @@ def prepare_environment():
21
  print(f"Version: {tag}")
22
  print(f"Commit hash: {commit}")
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  prepare_environment()
26
 
 
1
  import os
2
  import sys
3
+ import platform
4
 
5
+ from modules.launch_util import commit_hash, fooocus_tag, is_installed, run, python, run_pip, repo_dir, git_clone
6
+
7
+
8
+ REINSTALL_ALL = True
9
 
10
 
11
  def prepare_environment():
 
25
  print(f"Version: {tag}")
26
  print(f"Commit hash: {commit}")
27
 
28
+ git_clone(comfy_repo, repo_dir('StabilityAI-official-comfyui'), "Inference Engine", comfy_commit_hash)
29
+
30
+ if REINSTALL_ALL or not is_installed("torch") or not is_installed("torchvision"):
31
+ run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
32
+
33
+ if REINSTALL_ALL or not is_installed("xformers"):
34
+ if platform.system() == "Windows":
35
+ if platform.python_version().startswith("3.10"):
36
+ run_pip(f"install -U -I --no-deps {xformers_package}", "xformers", live=True)
37
+ else:
38
+ print("Installation of xformers is not supported in this version of Python.")
39
+ print("You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness")
40
+ if not is_installed("xformers"):
41
+ exit(0)
42
+ elif platform.system() == "Linux":
43
+ run_pip(f"install -U -I --no-deps {xformers_package}", "xformers")
44
+
45
+
46
 
47
  prepare_environment()
48
 
modules/launch_util.py CHANGED
@@ -1,10 +1,20 @@
1
  import os
2
-
3
  import subprocess
 
 
4
  from functools import lru_cache
5
 
6
 
 
7
  git = os.environ.get('GIT', "git")
 
 
 
 
 
 
 
8
  fooocus_tag = '1.0.0'
9
 
10
 
@@ -15,3 +25,73 @@ def commit_hash():
15
  except Exception:
16
  return "<none>"
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+ import importlib
3
  import subprocess
4
+ import sys
5
+
6
  from functools import lru_cache
7
 
8
 
9
+ python = sys.executable
10
  git = os.environ.get('GIT', "git")
11
+ default_command_live = (os.environ.get('LAUNCH_LIVE_OUTPUT') == "1")
12
+ index_url = os.environ.get('INDEX_URL', "")
13
+
14
+ modules_path = os.path.dirname(os.path.realpath(__file__))
15
+ script_path = os.path.dirname(modules_path)
16
+ dir_repos = "repositories"
17
+
18
  fooocus_tag = '1.0.0'
19
 
20
 
 
25
  except Exception:
26
  return "<none>"
27
 
28
+
29
+ def git_clone(url, dir, name, commithash=None):
30
+ # TODO clone into temporary dir and move if successful
31
+
32
+ if os.path.exists(dir):
33
+ if commithash is None:
34
+ return
35
+
36
+ current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}", live=False).strip()
37
+ if current_hash == commithash:
38
+ return
39
+
40
+ run(f'"{git}" -C "{dir}" fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}")
41
+ run(f'"{git}" -C "{dir}" checkout {commithash}', f"Checking out commit for {name} with hash: {commithash}...", f"Couldn't checkout commit {commithash} for {name}", live=True)
42
+ return
43
+
44
+ run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}", live=True)
45
+
46
+ if commithash is not None:
47
+ run(f'"{git}" -C "{dir}" checkout {commithash}', None, "Couldn't checkout {name}'s hash: {commithash}")
48
+
49
+
50
+ def repo_dir(name):
51
+ return os.path.join(script_path, dir_repos, name)
52
+
53
+
54
+ def is_installed(package):
55
+ try:
56
+ spec = importlib.util.find_spec(package)
57
+ except ModuleNotFoundError:
58
+ return False
59
+
60
+ return spec is not None
61
+
62
+
63
+ def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_command_live) -> str:
64
+ if desc is not None:
65
+ print(desc)
66
+
67
+ run_kwargs = {
68
+ "args": command,
69
+ "shell": True,
70
+ "env": os.environ if custom_env is None else custom_env,
71
+ "encoding": 'utf8',
72
+ "errors": 'ignore',
73
+ }
74
+
75
+ if not live:
76
+ run_kwargs["stdout"] = run_kwargs["stderr"] = subprocess.PIPE
77
+
78
+ result = subprocess.run(**run_kwargs)
79
+
80
+ if result.returncode != 0:
81
+ error_bits = [
82
+ f"{errdesc or 'Error running command'}.",
83
+ f"Command: {command}",
84
+ f"Error code: {result.returncode}",
85
+ ]
86
+ if result.stdout:
87
+ error_bits.append(f"stdout: {result.stdout}")
88
+ if result.stderr:
89
+ error_bits.append(f"stderr: {result.stderr}")
90
+ raise RuntimeError("\n".join(error_bits))
91
+
92
+ return (result.stdout or "")
93
+
94
+
95
+ def run_pip(command, desc=None, live=default_command_live):
96
+ index_url_line = f' --index-url {index_url}' if index_url != '' else ''
97
+ return run(f'"{python}" -m pip {command} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", live=live)
requirements_versions.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ torchsde
3
+ einops
4
+ transformers>=4.25.1
5
+ safetensors>=0.3.0
6
+ aiohttp
7
+ accelerate
8
+ pyyaml
9
+ Pillow
10
+ scipy
11
+ tqdm
12
+ psutil