support onnx branch and css tweaks

This commit is contained in:
Vladimir Mandic
2023-11-01 11:48:17 -04:00
parent e8d66a7d87
commit eddcc360be
20 changed files with 98 additions and 86 deletions
+15 -12
View File
@@ -245,13 +245,14 @@ def download_diffusers_model(hub_id: str, cache_dir: str = None, download_config
return pipeline_dir
def load_diffusers_models(model_path: str, command_path: str = None):
def load_diffusers_models(model_path: str, command_path: str = None, clear=True):
t0 = time.time()
places = []
places.append(model_path)
if command_path is not None and command_path != model_path:
places.append(command_path)
diffuser_repos.clear()
if clear:
diffuser_repos.clear()
output = []
for place in places:
if not os.path.isdir(place):
@@ -272,20 +273,21 @@ def load_diffusers_models(model_path: str, command_path: str = None):
continue
_, name = folder.split("--", maxsplit=1)
name = name.replace("--", "/")
snapshots = os.listdir(os.path.join(place, folder, "snapshots"))
folder = os.path.join(place, folder)
friendly = os.path.join(place, name)
snapshots = os.listdir(os.path.join(folder, "snapshots"))
if len(snapshots) == 0:
shared.log.warning(f"Diffusers folder has no snapshots: location={place} folder={folder} name={name}")
continue
commit = snapshots[-1]
folder = os.path.join(place, folder, 'snapshots', commit)
mtime = os.path.getmtime(folder)
info = os.path.join(folder, "model_info.json")
diffuser_repos.append({ 'name': name, 'filename': name, 'path': folder, 'hash': commit, 'mtime': mtime, 'model_info': info })
commit = os.path.join(folder, 'snapshots', snapshots[-1])
mtime = os.path.getmtime(commit)
info = os.path.join(commit, "model_info.json")
diffuser_repos.append({ 'name': name, 'filename': name, 'friendly': friendly, 'folder': folder, 'path': commit, 'hash': commit, 'mtime': mtime, 'model_info': info })
if os.path.exists(os.path.join(folder, 'hidden')):
continue
output.append(name)
except Exception as e:
shared.log.error(f"Error analyzing diffusers model: {place}/{folder} {e}")
shared.log.error(f"Error analyzing diffusers model: {folder} {e}")
except Exception as e:
shared.log.error(f"Error listing diffusers: {place} {e}")
shared.log.debug(f'Scanning diffusers cache: {model_path} {command_path} items={len(output)} time={time.time()-t0:.2f}')
@@ -293,11 +295,12 @@ def load_diffusers_models(model_path: str, command_path: str = None):
def find_diffuser(name: str):
import huggingface_hub as hf
if name in diffuser_repos:
return name
repo = [r for r in diffuser_repos if name == r['name'] or name == r['friendly'] or name == r['path']]
if len(repo) > 0:
return repo['name']
if shared.cmd_opts.no_download:
return None
import huggingface_hub as hf
hf_api = hf.HfApi()
hf_filter = hf.ModelFilter(
model_name=name,
+1 -1
View File
@@ -18,7 +18,7 @@ config_path = cli.config if os.path.isabs(cli.config) else os.path.join(cli.data
try:
with open(config_path, 'r', encoding='utf8') as f:
config = json.load(f)
except Exception as err:
except Exception:
config = {}
modules_path = os.path.dirname(os.path.realpath(__file__))
-3
View File
@@ -147,9 +147,6 @@ def process_diffusers(p: StableDiffusionProcessing, seeds, prompts, negative_pro
shared.state.job = prev_job
return imgs
def t(x):
return f"\033[34m{str(tuple(x.shape)).ljust(24)}\033[0m (\033[31mmin {x.amin().item():+.4f}\033[0m / \033[32mmean {x.mean().item():+.4f}\033[0m / \033[33mmax {x.amax().item():+.4f}\033[0m)"
def vae_encode(image, model, full_quality=True): # pylint: disable=unused-variable
if shared.state.interrupted or shared.state.skipped:
return []
+3 -3
View File
@@ -83,7 +83,7 @@ class CheckpointInfo:
self.type = ext
# self.model_name = os.path.splitext(name.replace("/", "_").replace("\\", "_"))[0]
else: # maybe a diffuser
repo = [r for r in modelloader.diffuser_repos if filename == r['filename']]
repo = [r for r in modelloader.diffuser_repos if filename == r['name']]
if len(repo) == 0:
self.name = relname
self.filename = filename
@@ -99,8 +99,8 @@ class CheckpointInfo:
self.title = self.name if self.shorthash is None else f'{self.name} [{self.shorthash}]'
self.path = self.filename
self.model_name = os.path.basename(self.name)
# shared.log.debug(f'Checkpoint: type={self.type} name={self.name} filename={self.filename} hash={self.shorthash} title={self.title}')
self.metadata = read_metadata_from_safetensors(filename)
# shared.log.debug(f'Checkpoint: type={self.type} name={self.name} filename={self.filename} hash={self.shorthash} title={self.title}')
def register(self):
checkpoints_list[self.title] = self
@@ -162,7 +162,7 @@ def list_models():
ext_filter = [".ckpt", ".safetensors"]
model_list = modelloader.load_models(model_path=model_path, model_url=None, command_path=shared.opts.ckpt_dir, ext_filter=ext_filter, download_name=None, ext_blacklist=[".vae.ckpt", ".vae.safetensors"])
if shared.backend == shared.Backend.DIFFUSERS:
model_list += modelloader.load_diffusers_models(model_path=os.path.join(models_path, 'Diffusers'), command_path=shared.opts.diffusers_dir)
model_list += modelloader.load_diffusers_models(model_path=os.path.join(models_path, 'Diffusers'), command_path=shared.opts.diffusers_dir, clear=True)
for filename in sorted(model_list, key=str.lower):
checkpoint_info = CheckpointInfo(filename)
if checkpoint_info.name is not None:
+1 -1
View File
@@ -23,7 +23,7 @@ try:
import importlib
k_diffusion = importlib.import_module('modules.k-diffusion.k_diffusion')
k_sampling = k_diffusion.sampling
except:
except Exception:
pass
if k_sampling is None:
shared.log.info(f'Path search: {sys.path}')
+1 -1
View File
@@ -158,7 +158,7 @@ def create_seed_inputs(tab):
random_seed = ToolButton(symbols.random, elem_id=f"{tab}_random_seed", label='Random seed')
reuse_seed = ToolButton(symbols.reuse, elem_id=f"{tab}_reuse_seed", label='Reuse seed')
with FormRow(visible=True, elem_id=f"{tab}_subseed_row", variant="compact"):
subseed = gr.Number(label='Variation seed', value=-1, elem_id=f"{tab}_subseed", container=True)
subseed = gr.Number(label='Variation', value=-1, elem_id=f"{tab}_subseed", container=True)
random_subseed = ToolButton(symbols.random, elem_id=f"{tab}_random_subseed")
reuse_subseed = ToolButton(symbols.reuse, elem_id=f"{tab}_reuse_subseed")
subseed_strength = gr.Slider(label='Variation strength', value=0.0, minimum=0, maximum=1, step=0.01, elem_id=f"{tab}_subseed_strength")
+1 -1
View File
@@ -27,7 +27,7 @@ def save_style(name, prompt, negative_prompt):
def delete_style(name):
if name == "":
return
return '', '', ''
shared.prompt_styles.styles.pop(name, None)
shared.prompt_styles.save_styles('')
return '', '', ''