Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] save name of last model to disk whenever model changes #3102

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ldm/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from diffusers.pipeline_utils import DiffusionPipeline
from diffusers.utils.import_utils import is_xformers_available
from omegaconf import OmegaConf
from pathlib import Path
from PIL import Image, ImageOps
from pytorch_lightning import logging, seed_everything

Expand Down Expand Up @@ -991,8 +992,17 @@ def set_model(self, model_name):

self.model_name = model_name
self._set_sampler() # requires self.model_name to be set first
self._save_last_used_model(model_name)
return self.model

def _save_last_used_model(self,model_name:str):
"""
Save name of the last model used.
"""
model_file_path = Path(Globals.root,'.last_model')
with open(model_file_path,'w') as f:
f.write(model_name)

def load_huggingface_concepts(self, concepts: list[str]):
self.model.textual_inversion_manager.load_huggingface_concepts(concepts)

Expand Down
10 changes: 0 additions & 10 deletions ldm/invoke/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ def main():
# web server loops forever
if opt.web or opt.gui:
invoke_ai_web_server_loop(gen, gfpgan, codeformer, esrgan)
save_last_used_model(gen.model_name)
sys.exit(0)

if not infile:
Expand Down Expand Up @@ -502,7 +501,6 @@ def image_writer(
print(
f'\nGoodbye!\nYou can start InvokeAI again by running the "invoke.bat" (or "invoke.sh") script from {Globals.root}'
)
save_last_used_model(gen.model_name)


# TO DO: remove repetitive code and the awkward command.replace() trope
Expand Down Expand Up @@ -1300,14 +1298,6 @@ def retrieve_last_used_model()->str:
with open(model_file_path,'r') as f:
return f.readline()

def save_last_used_model(model_name:str):
"""
Save name of the last model used.
"""
model_file_path = Path(Globals.root,'.last_model')
with open(model_file_path,'w') as f:
f.write(model_name)

# This routine performs any patch-ups needed after installation
def run_patches():
install_missing_config_files()
Expand Down