This commit is contained in:
lvmin 2023-08-10 05:29:12 -07:00
parent a6ec0509fd
commit 2d090cf484
4 changed files with 39 additions and 20 deletions

View File

@ -7,13 +7,13 @@ from modules.launch_util import commit_hash, fooocus_tag, is_installed, run, pyt
from modules.model_loader import load_file_from_url
from modules.path import modelfile_path
REINSTALL_ALL = False
def prepare_environment():
torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu118")
torch_command = os.environ.get('TORCH_COMMAND', f"pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url {torch_index_url}")
torch_command = os.environ.get('TORCH_COMMAND',
f"pip install torch==2.0.1 torchvision==0.15.2 --extra-index-url {torch_index_url}")
requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.20')
@ -41,7 +41,8 @@ def prepare_environment():
run_pip(f"install -U -I --no-deps {xformers_package}", "xformers", live=True)
else:
print("Installation of xformers is not supported in this version of Python.")
print("You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness")
print(
"You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness")
if not is_installed("xformers"):
exit(0)
elif platform.system() == "Linux":
@ -54,8 +55,10 @@ def prepare_environment():
model_filenames = [
('sd_xl_base_1.0.safetensors', 'https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'),
('sd_xl_refiner_1.0.safetensors', 'https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors')
('sd_xl_base_1.0.safetensors',
'https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors'),
('sd_xl_refiner_1.0.safetensors',
'https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors')
]
@ -69,4 +72,3 @@ prepare_environment()
download_models()
from webui import *

View File

@ -8,11 +8,9 @@ import logging
from functools import lru_cache
logging.getLogger("torch.distributed.nn").setLevel(logging.ERROR) # sshh...
logging.getLogger("xformers").addFilter(lambda record: 'A matching Triton is not available' not in record.getMessage())
python = sys.executable
git = os.environ.get('GIT', "git")
default_command_live = (os.environ.get('LAUNCH_LIVE_OUTPUT') == "1")
@ -40,12 +38,14 @@ def git_clone(url, dir, name, commithash=None):
if commithash is None:
return
current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None, f"Couldn't determine {name}'s hash: {commithash}", live=False).strip()
current_hash = run(f'"{git}" -C "{dir}" rev-parse HEAD', None,
f"Couldn't determine {name}'s hash: {commithash}", live=False).strip()
if current_hash == commithash:
return
run(f'"{git}" -C "{dir}" fetch', f"Fetching updates for {name}...", f"Couldn't fetch {name}")
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)
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)
return
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_
def run_pip(command, desc=None, live=default_command_live):
index_url_line = f' --index-url {index_url}' if index_url != '' else ''
return run(f'"{python}" -m pip {command} --prefer-binary{index_url_line}', desc=f"Installing {desc}", errdesc=f"Couldn't install {desc}", live=live)
return run(f'"{python}" -m pip {command} --prefer-binary{index_url_line}', desc=f"Installing {desc}",
errdesc=f"Couldn't install {desc}", live=live)
re_requirement = re.compile(r"\s*([-_a-zA-Z0-9]+)\s*(?:==\s*([-+_.a-zA-Z0-9]+))?\s*")

View File

@ -3,11 +3,11 @@ from urllib.parse import urlparse
def load_file_from_url(
url: str,
*,
model_dir: str,
progress: bool = True,
file_name: str | None = None,
url: str,
*,
model_dir: str,
progress: bool = True,
file_name: str | None = None,
) -> str:
"""Download a file from `url` into `model_dir`, using the file present if possible.

View File

@ -1,4 +1,6 @@
import os
import random
from comfy.sd import load_checkpoint_guess_config
from nodes import (
@ -11,7 +13,6 @@ from nodes import (
from modules.path import modelfile_path
xl_base_filename = os.path.join(modelfile_path, 'sd_xl_base_1.0.safetensors')
xl_refiner_filename = os.path.join(modelfile_path, 'sd_xl_refiner_1.0.safetensors')
@ -22,10 +23,25 @@ opCLIPTextEncode = CLIPTextEncode()
opEmptyLatentImage = EmptyLatentImage()
opKSamplerAdvanced = KSamplerAdvanced()
positive_conditions = opCLIPTextEncode.encode(clip=xl_base_clip, text='a handsome man in forest')[0]
negative_conditions = opCLIPTextEncode.encode(clip=xl_base_clip, text='bad, ugly')[0]
positive_embedding = opCLIPTextEncode.encode(clip=xl_base_clip, text='a handsome man in forest')
negative_embedding = opCLIPTextEncode.encode(clip=xl_base_clip, text='bad, ugly')
initial_latent_image = opEmptyLatentImage.generate(width=1024, height=1536, batch_size=1)[0]
initial_latent_image = opEmptyLatentImage.generate(width=1024, height=1536, batch_size=1)
samples = opKSamplerAdvanced.sample(
add_noise="enable",
noise_seed=random.randint(1, 2 ** 64),
steps=25,
cfg=9,
sampler_name="euler",
scheduler="normal",
start_at_step=0,
end_at_step=25,
return_with_leftover_noise="enable",
model=xl_base,
positive=positive_conditions,
negative=negative_conditions,
latent_image=initial_latent_image,
)
a = 0