diff --git a/ldm/invoke/config/model_install.py b/ldm/invoke/config/model_install.py index 77de6cee21..9c4a4d0e61 100644 --- a/ldm/invoke/config/model_install.py +++ b/ldm/invoke/config/model_install.py @@ -243,7 +243,7 @@ class addModelsForm(npyscreen.FormMultiPageAction): # URLs and the like self.parentApp.import_model_paths = self.import_model_paths.value.split() - self.parentApp.convert_to_diffusers = self.convert_models.value != 0 + self.parentApp.convert_to_diffusers = self.convert_models.value == 1 # big chunk of dead code # was intended to be a status area in which output of installation steps (including tqdm) was logged in real time diff --git a/ldm/invoke/config/model_install_backend.py b/ldm/invoke/config/model_install_backend.py index 6a50dc5fcb..451e9b7e2b 100644 --- a/ldm/invoke/config/model_install_backend.py +++ b/ldm/invoke/config/model_install_backend.py @@ -68,8 +68,8 @@ def install_requested_models( purge_deleted: bool = False, config_file_path: Path = None, ): - config_file_path =config_file_path or default_config_file() - model_manager = ModelManager(OmegaConf.load(config_file_path),precision=precision) + config_file_path=config_file_path or default_config_file() + model_manager= ModelManager(OmegaConf.load(config_file_path),precision=precision) if remove_models and len(remove_models) > 0: print("== DELETING UNCHECKED STARTER MODELS ==") @@ -92,12 +92,17 @@ def install_requested_models( if external_models and len(external_models)>0: print("== INSTALLING EXTERNAL MODELS ==") for path_url_or_repo in external_models: - model_manager.heuristic_import( - path_url_or_repo, - convert=convert_to_diffusers, - commit_to_conf=config_file_path - ) - + try: + model_manager.heuristic_import( + path_url_or_repo, + convert=convert_to_diffusers, + commit_to_conf=config_file_path + ) + except KeyboardInterrupt: + sys.exit(-1) + except Exception: + pass + # ------------------------------------- def yes_or_no(prompt: str, default_yes=True): default = "y" if default_yes else "n" diff --git a/ldm/invoke/generator/diffusers_pipeline.py b/ldm/invoke/generator/diffusers_pipeline.py index 24626247cf..3bf777e23d 100644 --- a/ldm/invoke/generator/diffusers_pipeline.py +++ b/ldm/invoke/generator/diffusers_pipeline.py @@ -2,6 +2,7 @@ from __future__ import annotations import dataclasses import inspect +import psutil import secrets import sys from dataclasses import dataclass, field diff --git a/ldm/invoke/model_manager.py b/ldm/invoke/model_manager.py index 3f42161045..49213c29c7 100644 --- a/ldm/invoke/model_manager.py +++ b/ldm/invoke/model_manager.py @@ -643,7 +643,7 @@ class ModelManager(object): self.add_model(model_name, new_config, True) if commit_to_conf: self.commit(commit_to_conf) - return True + return model_name def import_ckpt_model( self, @@ -709,6 +709,8 @@ class ModelManager(object): ): model_path = None thing = path_url_or_repo # to save typing + + print(f'here i am; thing={thing}, convert={convert}') if thing.startswith(('http:','https:','ftp:')): print(f'* {thing} appears to be a URL') @@ -720,17 +722,23 @@ class ModelManager(object): elif Path(thing).is_dir() and Path(thing, 'model_index.json').exists(): print(f'* {thing} appears to be a diffusers file on disk') - self.import_diffusers_model(thing, commit_to_conf=commit_to_conf) + model_name = self.import_diffusers_model( + thing, + vae=dict(repo_id='stabilityai/sd-vae-ft-mse'), + commit_to_conf=commit_to_conf + ) elif Path(thing).is_dir(): print(f'* {thing} appears to be a directory. Will scan for models to import') for m in list(Path(thing).rglob('*.ckpt')) + list(Path(thing).rglob('*.safetensors')): - self.heuristic_import(m, convert, commit_to_conf=commit_to_conf) + print('***',m) + self.heuristic_import(str(m), convert, commit_to_conf=commit_to_conf) return elif re.match(r'^[\w.+-]+/[\w.+-]+$', thing): print(f'* {thing} appears to be a HuggingFace diffusers repo_id') - self.import_diffuser_model(thing, commit_to_conf=commit_to_conf) + model_name = self.import_diffuser_model(thing, commit_to_conf=commit_to_conf) + pipeline,_,_,_ = self._load_diffusers_model(self.config[model_name]) else: print(f"* {thing}: Unknown thing. Please provide a URL, file path, directory or HuggingFace repo_id") @@ -749,7 +757,7 @@ class ModelManager(object): print(f'* {thing} appears to be an SD-v2 model; model will be converted to diffusers format') model_config_file = Path(Globals.root,'configs/stable-diffusion/v2-inference-v.yaml') convert = True - elif re.search('inpaint', model_path, flags=re.IGNORECASE): + elif re.search('inpaint', str(model_path), flags=re.IGNORECASE): print(f'* {thing} appears to be an SD-v1 inpainting model') model_config_file = Path(Globals.root,'configs/stable-diffusion/v1-inpainting-inference.yaml') else: @@ -833,7 +841,7 @@ class ModelManager(object): return model_name = model_name or diffusers_path.name - model_description = model_description or "Optimized version of {model_name}" + model_description = model_description or f"Optimized version of {model_name}" print(f">> Optimizing {model_name} (30-60s)") try: # By passing the specified VAE to the conversion function, the autoencoder diff --git a/ldm/util.py b/ldm/util.py index d6d2c9e170..1bdcaba0d3 100644 --- a/ldm/util.py +++ b/ldm/util.py @@ -318,8 +318,6 @@ def download_with_resume(url: str, dest: Path, access_token: str = None) -> Path else: dest.parent.mkdir(parents=True, exist_ok=True) - print(f'DEBUG: after many manipulations, dest={dest}') - header = {"Authorization": f"Bearer {access_token}"} if access_token else {} open_mode = "wb" exist_size = 0