lllyasviel commited on
Commit
712c171
·
1 Parent(s): c779f27
Files changed (4) hide show
  1. launch.py +8 -6
  2. modules/launch_util.py +6 -5
  3. modules/model_loader.py +5 -5
  4. webui.py +22 -6
launch.py CHANGED
@@ -7,13 +7,13 @@ from modules.launch_util import commit_hash, fooocus_tag, is_installed, run, pyt
7
  from modules.model_loader import load_file_from_url
8
  from modules.path import modelfile_path
9
 
10
-
11
  REINSTALL_ALL = False
12
 
13
 
14
  def prepare_environment():
15
  torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu118")
16
- torch_command = os.environ.get('TORCH_COMMAND', f"pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url {torch_index_url}")
 
17
  requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
18
 
19
  xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.20')
@@ -41,7 +41,8 @@ def prepare_environment():
41
  run_pip(f"install -U -I --no-deps {xformers_package}", "xformers", live=True)
42
  else:
43
  print("Installation of xformers is not supported in this version of Python.")
44
- print("You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness")
 
45
  if not is_installed("xformers"):
46
  exit(0)
47
  elif platform.system() == "Linux":
@@ -54,8 +55,10 @@ def prepare_environment():
54
 
55
 
56
  model_filenames = [
57
- ('sd_xl_base_1.0.safetensors', 'https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'),
58
- ('sd_xl_refiner_1.0.safetensors', 'https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors')
 
 
59
  ]
60
 
61
 
@@ -69,4 +72,3 @@ prepare_environment()
69
  download_models()
70
 
71
  from webui import *
72
-
 
7
  from modules.model_loader import load_file_from_url
8
  from modules.path import modelfile_path
9
 
 
10
  REINSTALL_ALL = False
11
 
12
 
13
  def prepare_environment():
14
  torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu118")
15
+ torch_command = os.environ.get('TORCH_COMMAND',
16
+ f"pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url {torch_index_url}")
17
  requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
18
 
19
  xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.20')
 
41
  run_pip(f"install -U -I --no-deps {xformers_package}", "xformers", live=True)
42
  else:
43
  print("Installation of xformers is not supported in this version of Python.")
44
+ print(
45
+ "You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness")
46
  if not is_installed("xformers"):
47
  exit(0)
48
  elif platform.system() == "Linux":
 
55
 
56
 
57
  model_filenames = [
58
+ ('sd_xl_base_1.0.safetensors',
59
+ 'https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'),
60
+ ('sd_xl_refiner_1.0.safetensors',
61
+ 'https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors')
62
  ]
63
 
64
 
 
72
  download_models()
73
 
74
  from webui import *
 
modules/launch_util.py CHANGED
@@ -8,11 +8,9 @@ import logging
8
 
9
  from functools import lru_cache
10
 
11
-
12
  logging.getLogger("torch.distributed.nn").setLevel(logging.ERROR) # sshh...
13
  logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage())
14
 
15
-
16
  python = sys.executable
17
  git = os.environ.get('GIT', "git")
18
  default_command_live = (os.environ.get('LAUNCH_LIVE_OUTPUT') == "1")
@@ -40,12 +38,14 @@ def git_clone(url, dir, name, commithash=None):
40
  if commithash is None:
41
  return
42
 
43
- current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}", live=False).strip()
 
44
  if current_hash == commithash:
45
  return
46
 
47
  run(f'"{git}" -C "{dir}" fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}")
48
- 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)
 
49
  return
50
 
51
  run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}", live=True)
@@ -101,7 +101,8 @@ def run(command, desc=None, errdesc=None, custom_env=None, live: bool = default_
101
 
102
  def run_pip(command, desc=None, live=default_command_live):
103
  index_url_line = f' --index-url {index_url}' if index_url != '' else ''
104
- return run(f'"{python}" -m pip {command} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", live=live)
 
105
 
106
 
107
  re_requirement = re.compile(r"\s*([-_a-zA-Z0-9]+)\s*(?:==\s*([-+_.a-zA-Z0-9]+))?\s*")
 
8
 
9
  from functools import lru_cache
10
 
 
11
  logging.getLogger("torch.distributed.nn").setLevel(logging.ERROR) # sshh...
12
  logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage())
13
 
 
14
  python = sys.executable
15
  git = os.environ.get('GIT', "git")
16
  default_command_live = (os.environ.get('LAUNCH_LIVE_OUTPUT') == "1")
 
38
  if commithash is None:
39
  return
40
 
41
+ current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None,
42
+ f"Couldn't determine {name}'s hash: {commithash}", live=False).strip()
43
  if current_hash == commithash:
44
  return
45
 
46
  run(f'"{git}" -C "{dir}" fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}")
47
+ run(f'"{git}" -C "{dir}" checkout {commithash}', f"Checking out commit for {name} with hash: {commithash}...",
48
+ f"Couldn't checkout commit {commithash} for {name}", live=True)
49
  return
50
 
51
  run(f'"{git}" clone "{url}" "{dir}"', f"Cloning {name} into {dir}...", f"Couldn't clone {name}", live=True)
 
101
 
102
  def run_pip(command, desc=None, live=default_command_live):
103
  index_url_line = f' --index-url {index_url}' if index_url != '' else ''
104
+ return run(f'"{python}" -m pip {command} --prefer-binary{index_url_line}', desc=f"Installing {desc}",
105
+ errdesc=f"Couldn't install {desc}", live=live)
106
 
107
 
108
  re_requirement = re.compile(r"\s*([-_a-zA-Z0-9]+)\s*(?:==\s*([-+_.a-zA-Z0-9]+))?\s*")
modules/model_loader.py CHANGED
@@ -3,11 +3,11 @@ from urllib.parse import urlparse
3
 
4
 
5
  def load_file_from_url(
6
- url: str,
7
- *,
8
- model_dir: str,
9
- progress: bool = True,
10
- file_name: str | None = None,
11
  ) -> str:
12
  """Download a file from `url` into `model_dir`, using the file present if possible.
13
 
 
3
 
4
 
5
  def load_file_from_url(
6
+ url: str,
7
+ *,
8
+ model_dir: str,
9
+ progress: bool = True,
10
+ file_name: str | None = None,
11
  ) -> str:
12
  """Download a file from `url` into `model_dir`, using the file present if possible.
13
 
webui.py CHANGED
@@ -1,4 +1,6 @@
1
  import os
 
 
2
  from comfy.sd import load_checkpoint_guess_config
3
 
4
  from nodes import (
@@ -11,7 +13,6 @@ from nodes import (
11
 
12
  from modules.path import modelfile_path
13
 
14
-
15
  xl_base_filename = os.path.join(modelfile_path, 'sd_xl_base_1.0.safetensors')
16
  xl_refiner_filename = os.path.join(modelfile_path, 'sd_xl_refiner_1.0.safetensors')
17
 
@@ -22,10 +23,25 @@ opCLIPTextEncode = CLIPTextEncode()
22
  opEmptyLatentImage = EmptyLatentImage()
23
  opKSamplerAdvanced = KSamplerAdvanced()
24
 
25
-
26
- positive_embedding = opCLIPTextEncode.encode(clip=xl_base_clip, text='a handsome man in forest')
27
- negative_embedding = opCLIPTextEncode.encode(clip=xl_base_clip, text='bad, ugly')
28
-
29
- initial_latent_image = opEmptyLatentImage.generate(width=1024, height=1536, batch_size=1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  a = 0
 
1
  import os
2
+ import random
3
+
4
  from comfy.sd import load_checkpoint_guess_config
5
 
6
  from nodes import (
 
13
 
14
  from modules.path import modelfile_path
15
 
 
16
  xl_base_filename = os.path.join(modelfile_path, 'sd_xl_base_1.0.safetensors')
17
  xl_refiner_filename = os.path.join(modelfile_path, 'sd_xl_refiner_1.0.safetensors')
18
 
 
23
  opEmptyLatentImage = EmptyLatentImage()
24
  opKSamplerAdvanced = KSamplerAdvanced()
25
 
26
+ positive_conditions = opCLIPTextEncode.encode(clip=xl_base_clip, text='a handsome man in forest')[0]
27
+ negative_conditions = opCLIPTextEncode.encode(clip=xl_base_clip, text='bad, ugly')[0]
28
+
29
+ initial_latent_image = opEmptyLatentImage.generate(width=1024, height=1536, batch_size=1)[0]
30
+
31
+ samples = opKSamplerAdvanced.sample(
32
+ add_noise="enable",
33
+ noise_seed=random.randint(1, 2 ** 64),
34
+ steps=25,
35
+ cfg=9,
36
+ sampler_name="euler",
37
+ scheduler="normal",
38
+ start_at_step=0,
39
+ end_at_step=25,
40
+ return_with_leftover_noise="enable",
41
+ model=xl_base,
42
+ positive=positive_conditions,
43
+ negative=negative_conditions,
44
+ latent_image=initial_latent_image,
45
+ )
46
 
47
  a = 0