-
Notifications
You must be signed in to change notification settings - Fork 1
feat(AT-39): add lora by user from interface #9
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
base: main
Are you sure you want to change the base?
Changes from all commits
876b3b2
c9095b7
9af1dc6
6c6bc51
ac49166
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import numpy as np | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from PIL import Image | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import modules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def load_torch_file(ckpt, safe_load=False, device=None): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if device is None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| device = torch.device("cpu") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -459,3 +461,34 @@ def update_absolute(self, value, total=None, preview=None): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def update(self, value): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self.update_absolute(self.current + value) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def move_lora(filepath: str, username: str) -> bool: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Takes a valid filepath as an input (supposed to be a LoRA file) and a username | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and moves the file to the user's LoRA directory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns True if the copy succeeded, False otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import shutil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filepath = Path(filepath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"FILEPATH: {filepath} and USERNAME: {username} and PATHS_LORAS: {modules.config.paths_loras}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| destination_dir = Path(modules.config.paths_loras[0]) / username | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f"User {username} requested to move {filepath}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if filepath.is_file(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not destination_dir.exists(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Prevent parent creation to be safe with folder creation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| destination_dir.mkdir(parents=False, exist_ok=True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shutil.copy(filepath, destination_dir.as_posix()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| os.remove(filepath) # Deleting temp file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Error while copying uploaded LoRA:", e) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+465
to
+494
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Harden
- destination_dir = Path(modules.config.paths_loras[0]) / username
+ safe_user = Path(username).name # remove path traversal
+ destination_dir = Path(modules.config.paths_loras[0]) / safe_user
- print(f"FILEPATH: {filepath} and USERNAME: {username} and PATHS_LORAS: {modules.config.paths_loras}")
- ...
- if not destination_dir.exists():
- # Prevent parent creation to be safe with folder creation
- destination_dir.mkdir(parents=False, exist_ok=True)
+ # Avoid verbose printing in production; use logging if required
+ if not destination_dir.exists():
+ destination_dir.mkdir(parents=True, exist_ok=True)
- shutil.copy(filepath, destination_dir.as_posix())
- os.remove(filepath) # Deleting temp file
+ shutil.move(filepath, destination_dir / filepath.name)These tweaks tighten security and robustness. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -163,6 +163,26 @@ def get_path_output() -> str: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print('Loading support files...') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return path_output | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_loras_path() -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| global config_dict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_loras = [f'{path_models_root}/loras/', '../models/loras/'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if args_manager.args.path_loras: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if isinstance(args_manager.args.path_loras, list): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_loras = args_manager.args.path_loras | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_loras = [args_manager.args.path_loras, args_manager.args.path_loras] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| config_dict['path_loras'] = args_manager.args.path_loras | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif 'path_loras' in config_dict and config_dict['path_loras']: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if isinstance(config_dict['path_loras'], list): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_loras = config_dict['path_loras'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_loras = [config_dict['path_loras'], config_dict['path_loras']] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_loras = get_dir_or_set_default('path_loras', path_loras, True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print(f'Loras will be stored in path: {path_loras}') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return path_loras | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+166
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Fix type-hint, ensure directory creation & align with new “common” sub-folder Several issues in
A compact patch: -def get_loras_path() -> str:
+def get_loras_path() -> list[str]:
@@
- path_loras = [f'{path_models_root}/loras/', '../models/loras/']
+ # Default to the new 'common' namespace
+ path_loras = [f'{path_models_root}/loras/common/', '../models/loras/common/']
@@
- config_dict['path_loras'] = args_manager.args.path_loras
+ config_dict['path_loras'] = args_manager.args.path_loras
@@
- elif 'path_loras' in config_dict and config_dict['path_loras']:
+ elif 'path_loras' in config_dict and config_dict['path_loras']:
@@
-
- path_loras = get_dir_or_set_default('path_loras', path_loras, True)
-
- print(f'Loras will be stored in path: {path_loras}')
- return path_loras
+ # Always validate / create directories
+ path_loras = get_dir_or_set_default('path_loras', path_loras, True, make_directory=True)
+ print(f'Loras will be stored in path: {path_loras}')
+ return path_loras📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def get_path_models_root() -> str: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| global config_dict | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| models_root = 'models' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -223,7 +243,8 @@ def get_dir_or_set_default(key, default_value, as_array=False, make_directory=Fa | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_models_root = get_path_models_root() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| paths_checkpoints = get_dir_or_set_default('path_checkpoints', [f'{path_models_root}/checkpoints/', '../models/checkpoints/'], True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| paths_loras = get_dir_or_set_default('path_loras', [f'{path_models_root}/loras/', '../models/loras/'], True) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| paths_loras = get_loras_path() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| paths_performance_loras = [f'{path_models_root}/loras/performance/', '../models/loras/performance/'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_embeddings = get_dir_or_set_default('path_embeddings', f'{path_models_root}/embeddings/') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+247
to
248
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion
-paths_performance_loras = [f'{path_models_root}/loras/performance/', '../models/loras/performance/']
+paths_performance_loras = get_dir_or_set_default(
+ 'path_performance_loras',
+ [f'{path_models_root}/loras/performance/', '../models/loras/performance/'],
+ as_array=True,
+ make_directory=True
+)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_vae_approx = get_dir_or_set_default('path_vae_approx', f'{path_models_root}/vae_approx/') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| path_vae = get_dir_or_set_default('path_vae', f'{path_models_root}/vae/') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1002,11 +1023,11 @@ def get_base_model_list(engine='Fooocus', task_method=None): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| base_model_list = [f for f in base_model_list if ("hyp8" in f or "hyp16" in f or "flux" in f) and f.endswith("gguf")] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return base_model_list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def update_files(engine='Fooocus', task_method=None): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def update_files(engine='Fooocus', task_method=None, user: str = None): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| global modelsinfo, model_filenames, lora_filenames, vae_filenames, wildcard_filenames, available_presets | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| modelsinfo.refresh_from_path() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_filenames = get_base_model_list(engine, task_method) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lora_filenames = modelsinfo.get_model_names('loras') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lora_filenames = modelsinfo.get_model_names('loras', user=user) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| vae_filenames = modelsinfo.get_model_names('vae') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wildcard_filenames = get_files_from_folder(path_wildcards, ['.txt']) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| available_presets = get_presets() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1054,28 +1075,28 @@ def downloading_inpaint_models(v): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def downloading_sdxl_lcm_lora(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| load_file_from_url( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url='https://huggingface.co/lllyasviel/misc/resolve/main/sdxl_lcm_lora.safetensors', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_dir=paths_loras[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_dir=paths_performance_loras[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file_name=modules.flags.PerformanceLoRA.EXTREME_SPEED.value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return modules.flags.PerformanceLoRA.EXTREME_SPEED.value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"{modules.flags.PerformanceLoRA.EXTREME_SPEED.value}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def downloading_sdxl_lightning_lora(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| load_file_from_url( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url='https://huggingface.co/mashb1t/misc/resolve/main/sdxl_lightning_4step_lora.safetensors', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_dir=paths_loras[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_dir=paths_performance_loras[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file_name=modules.flags.PerformanceLoRA.LIGHTNING.value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return modules.flags.PerformanceLoRA.LIGHTNING.value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"{modules.flags.PerformanceLoRA.LIGHTNING.value}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def downloading_sdxl_hyper_sd_lora(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| load_file_from_url( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url='https://huggingface.co/mashb1t/misc/resolve/main/sdxl_hyper_sd_4step_lora.safetensors', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_dir=paths_loras[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model_dir=paths_performance_loras[0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file_name=modules.flags.PerformanceLoRA.HYPER_SD.value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return modules.flags.PerformanceLoRA.HYPER_SD.value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return f"{modules.flags.PerformanceLoRA.HYPER_SD.value}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
1075
to
1100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainDownload helpers now return just the file-name, breaking previous callers
return f"{modules.flags.PerformanceLoRA.EXTREME_SPEED.value}"Down-stream code expecting Either restore the old behaviour: - return f"{modules.flags.PerformanceLoRA.EXTREME_SPEED.value}"
+ return os.path.join(paths_performance_loras[0], modules.flags.PerformanceLoRA.EXTREME_SPEED.value)and similarly for the other two helpers, or audit every call-site. Also ensure the parent directory exists (issue noted in a previous comment). 🏁 Script executed: #!/bin/bash
set -e
echo "🔍 Searching for call‐sites of downloading_sdxl_*_lora()..."
rg -n "downloading_sdxl_(lcm|lightning|hyper)_lora" .
echo
echo "🔍 Locating load_file_from_url definition to inspect its return value..."
rg -n "def load_file_from_url" -A10 .Length of output: 4600 Restore full file path in download helpers The • File: modules/config.py (around lines 1075–1100) def downloading_sdxl_lcm_lora():
- load_file_from_url(
+ return load_file_from_url(
url='https://huggingface.co/lllyasviel/misc/resolve/main/sdxl_lcm_lora.safetensors',
model_dir=paths_performance_loras[0],
file_name=modules.flags.PerformanceLoRA.EXTREME_SPEED.value
)
- return f"{modules.flags.PerformanceLoRA.EXTREME_SPEED.value}"Apply the same pattern to 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def downloading_controlnet_canny(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,10 +81,18 @@ def refresh_loras(self, loras): | |
| if os.path.exists(filename): | ||
| lora_filename = filename | ||
| else: | ||
| lora_filename = get_file_from_folder_list(filename, modules.config.paths_loras) | ||
| loras_paths = [] | ||
| if isinstance(modules.config.paths_loras, list): | ||
| loras_paths.extend(modules.config.paths_loras) | ||
| else: | ||
| loras_paths.append(modules.config.paths_loras) | ||
| if isinstance(modules.config.paths_performance_loras, list): | ||
| loras_paths.extend(modules.config.paths_performance_loras) | ||
| else: | ||
| loras_paths.append(modules.config.paths_performance_loras) | ||
| lora_filename = get_file_from_folder_list(filename, loras_paths) | ||
|
|
||
|
Comment on lines
+84
to
94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard against
- lora_filename = get_file_from_folder_list(filename, loras_paths)
-
- if not os.path.exists(lora_filename):
+ lora_filename = get_file_from_folder_list(filename, loras_paths)
+
+ # Abort early if lookup failed
+ if not lora_filename or not os.path.exists(lora_filename):
continueOptionally build
🤖 Prompt for AI Agents |
||
| if not os.path.exists(lora_filename): | ||
| print(f'Lora file not found: {lora_filename}') | ||
| continue | ||
|
|
||
| loras_to_load.append((lora_filename, weight)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,10 +11,10 @@ def create_model_structure(): | |||||||||||||||||
| os.makedirs(config.paths_checkpoints[0] + '\SD3x', exist_ok=True) | ||||||||||||||||||
|
|
||||||||||||||||||
| # ensure that the special LoRA directories exist | ||||||||||||||||||
| os.makedirs(config.paths_loras[0] + '\Alternative', exist_ok=True) | ||||||||||||||||||
| os.makedirs(config.paths_loras[0] + '\Flux', exist_ok=True) | ||||||||||||||||||
| os.makedirs(config.paths_loras[0] + '\Pony', exist_ok=True) | ||||||||||||||||||
| os.makedirs(config.paths_loras[0] + '\SD1.5', exist_ok=True) | ||||||||||||||||||
| os.makedirs(config.paths_loras[0] + '\SD3x', exist_ok=True) | ||||||||||||||||||
| os.makedirs(config.paths_loras[0] + '\common\Alternative', exist_ok=True) | ||||||||||||||||||
| os.makedirs(config.paths_loras[0] + '\common\Flux', exist_ok=True) | ||||||||||||||||||
| os.makedirs(config.paths_loras[0] + '\common\Pony', exist_ok=True) | ||||||||||||||||||
| os.makedirs(config.paths_loras[0] + '\common\SD1.5', exist_ok=True) | ||||||||||||||||||
| os.makedirs(config.paths_loras[0] + '\common\SD3x', exist_ok=True) | ||||||||||||||||||
|
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Windows-only path separators will break on Linux / macOS
-os.makedirs(config.paths_loras[0] + '\common\Alternative', exist_ok=True)
-os.makedirs(config.paths_loras[0] + '\common\Flux', exist_ok=True)
-…
+base = config.paths_loras[0]
+for sub in ("Alternative", "Flux", "Pony", "SD1.5", "SD3x"):
+ os.makedirs(os.path.join(base, "common", sub), exist_ok=True)Please replace the string concatenation with 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| return | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,32 @@ | ||
| { | ||
| "preset category": "LowVRAM", | ||
| "Download manually from": "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors", | ||
| "default_model": "LowVRAM\\sdxl4GB2GBImprovedFP8_fp8FullCheckpoint.safetensors", | ||
| "default_refiner": "None", | ||
| "default_refiner_switch": 0.75, | ||
| "default_loras": [ | ||
| [ | ||
| true, | ||
| "sd_xl_offset_example-lora_1.0.safetensors", | ||
| 0.5 | ||
| ], | ||
| [ | ||
| true, | ||
| "None", | ||
| 1.0 | ||
| ], | ||
| [ | ||
| true, | ||
| "None", | ||
| 1.0 | ||
| ], | ||
| [ | ||
| true, | ||
| "None", | ||
| 1.0 | ||
| ], | ||
| [ | ||
| true, | ||
| "None", | ||
| 1.0 | ||
| ] | ||
| ], | ||
| "default_cfg_scale": 7.0, | ||
| "default_sample_sharpness": 2.0, | ||
| "default_sampler": "dpmpp_2m_sde_gpu", | ||
| "default_scheduler": "karras", | ||
| "default_performance": "Speed", | ||
| "default_prompt": "", | ||
| "default_prompt_negative": "", | ||
| "default_styles": [ | ||
| "Fooocus V2", | ||
| "Fooocus Enhance" | ||
| ], | ||
| "default_aspect_ratio": "1024*1024", | ||
| "default_overwrite_step": -1, | ||
| "checkpoint_downloads": { | ||
| "LowVRAM\\sdxl4GB2GBImprovedFP8_fp8FullCheckpoint.safetensors": "https://civitai.com/api/download/models/971447?type=Model&format=SafeTensor&size=full&fp=fp8&token=b9c06333099ba600ef8e993a5e97f31a" | ||
| }, | ||
| "embeddings_downloads": {}, | ||
| "lora_downloads": { | ||
| "sd_xl_offset_example-lora_1.0.safetensors": "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors" | ||
| }, | ||
| "previous_default_models": [] | ||
| "preset category": "LowVRAM", | ||
| "Download manually from": "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors", | ||
| "default_model": "LowVRAM\\sdxl4GB2GBImprovedFP8_fp8FullCheckpoint.safetensors", | ||
| "default_refiner": "None", | ||
| "default_refiner_switch": 0.75, | ||
| "default_loras": [ | ||
| [true, "common\\sd_xl_offset_example-lora_1.0.safetensors", 0.5], | ||
| [true, "None", 1.0], | ||
| [true, "None", 1.0], | ||
| [true, "None", 1.0], | ||
| [true, "None", 1.0] | ||
| ], | ||
| "default_cfg_scale": 7.0, | ||
| "default_sample_sharpness": 2.0, | ||
| "default_sampler": "dpmpp_2m_sde_gpu", | ||
| "default_scheduler": "karras", | ||
| "default_performance": "Speed", | ||
| "default_prompt": "", | ||
| "default_prompt_negative": "", | ||
| "default_styles": ["Fooocus V2", "Fooocus Enhance"], | ||
| "default_aspect_ratio": "1024*1024", | ||
| "default_overwrite_step": -1, | ||
| "checkpoint_downloads": { | ||
| "LowVRAM\\sdxl4GB2GBImprovedFP8_fp8FullCheckpoint.safetensors": "https://civitai.com/api/download/models/971447?type=Model&format=SafeTensor&size=full&fp=fp8&token=b9c06333099ba600ef8e993a5e97f31a" | ||
| }, | ||
| "embeddings_downloads": {}, | ||
| "lora_downloads": { | ||
| "sd_xl_offset_example-lora_1.0.safetensors": "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors" | ||
| }, | ||
| "previous_default_models": [] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,31 @@ | ||
| { | ||
| "preset category": "LowVRAM", | ||
| "Download manually from": "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors", | ||
| "default_model": "LowVRAM\\4gbPONY4STEP2GB_fp8FullCheckpoint.safetensors", | ||
| "default_refiner": "None", | ||
| "default_refiner_switch": 0.6, | ||
| "default_loras": [ | ||
| [ | ||
| true, | ||
| "None", | ||
| 1.0 | ||
| ], | ||
| [ | ||
| true, | ||
| "None", | ||
| 1.0 | ||
| ], | ||
| [ | ||
| true, | ||
| "None", | ||
| 1.0 | ||
| ], | ||
| [ | ||
| true, | ||
| "None", | ||
| 1.0 | ||
| ], | ||
| [ | ||
| true, | ||
| "None", | ||
| 1.0 | ||
| ] | ||
| ], | ||
| "default_cfg_scale": 7.0, | ||
| "default_sample_sharpness": 2.0, | ||
| "default_sampler": "dpmpp_2m_sde_gpu", | ||
| "default_scheduler": "karras", | ||
| "default_performance": "Speed", | ||
| "default_prompt": "", | ||
| "default_prompt_negative": "", | ||
| "default_styles": [ | ||
| "Pony Real" | ||
| ], | ||
| "default_aspect_ratio": "1024*1024", | ||
| "default_overwrite_step": -1, | ||
| "default_inpaint_engine_version": "None", | ||
| "checkpoint_downloads": { | ||
| "4gbPONY4STEP2GB_fp8FullCheckpoint.safetensors": "https://civitai.com/api/download/models/968654?type=Model&format=SafeTensor&size=full&fp=fp8&token=b9c06333099ba600ef8e993a5e97f31a" | ||
| }, | ||
| "embeddings_downloads": {}, | ||
| "lora_downloads": {}, | ||
| "vae_downloads": {} | ||
| "preset category": "LowVRAM", | ||
| "Download manually from": "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_offset_example-lora_1.0.safetensors", | ||
| "default_model": "LowVRAM\\4gbPONY4STEP2GB_fp8FullCheckpoint.safetensors", | ||
| "default_refiner": "None", | ||
| "default_refiner_switch": 0.6, | ||
| "default_loras": [ | ||
| [true, "None", 1.0], | ||
| [true, "None", 1.0], | ||
| [true, "None", 1.0], | ||
| [true, "None", 1.0], | ||
| [true, "None", 1.0] | ||
| ], | ||
| "default_cfg_scale": 7.0, | ||
| "default_sample_sharpness": 2.0, | ||
| "default_sampler": "dpmpp_2m_sde_gpu", | ||
| "default_scheduler": "karras", | ||
| "default_performance": "Speed", | ||
| "default_prompt": "", | ||
| "default_prompt_negative": "", | ||
| "default_styles": ["Pony Real"], | ||
| "default_aspect_ratio": "1024*1024", | ||
| "default_overwrite_step": -1, | ||
| "default_inpaint_engine_version": "None", | ||
| "checkpoint_downloads": { | ||
| "4gbPONY4STEP2GB_fp8FullCheckpoint.safetensors": "https://civitai.com/api/download/models/968654?type=Model&format=SafeTensor&size=full&fp=fp8&token=b9c06333099ba600ef8e993a5e97f31a" | ||
| }, | ||
| "embeddings_downloads": {}, | ||
| "lora_downloads": {}, | ||
| "vae_downloads": {} | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
❓ Verification inconclusive
Hard-coding the
"common"sub-folder scatters path logic and risks duplicationThe same
"common"suffix is now appended here, inmodules/model_structure.create_model_structure(), and (implicitly) in several preset JSON files. When the convention changes again (e.g. per-user folders, a different tier like"public"), every call-site must be audited.Consider adding a helper such as
config.get_common_lora_paths()(or re-using one if it already exists) so the rule lives in exactly one module.Extract “common” path logic into a single helper
To avoid scattering the
"common"suffix in multiple places, centralize it in one method onconfig.• In launch.py (lines 147–149) and in modules/model_structure.py you’re appending
"common"to each entry inconfig.paths_loras.• Preset JSON files also hard‐code the
"common"folder.Proposed changes:
This keeps the convention in one place and prevents divergence when folder tiers change.
🤖 Prompt for AI Agents