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

Allow loading of .sft VAE files for Flux #1827

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def read_arbitrary_config(directory):
def load_torch_file(ckpt, safe_load=False, device=None):
if device is None:
device = torch.device("cpu")
if ckpt.lower().endswith(".safetensors"):
if ckpt.lower().endswith(".safetensors") or ckpt.lower().endswith(".sft"):
sd = safetensors.torch.load_file(ckpt, device=device.type)
elif ckpt.lower().endswith(".gguf"):
reader = gguf.GGUFReader(ckpt)
Expand Down
13 changes: 7 additions & 6 deletions modules/sd_vae.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os
import collections
from dataclasses import dataclass

from modules import paths, shared, devices, script_callbacks, sd_models, extra_networks, lowvram, sd_hijack, hashes

import glob
import os
from copy import deepcopy
from backend.utils import load_torch_file
from dataclasses import dataclass

from modules import paths, shared, sd_models, extra_networks, hashes

vae_path = os.path.abspath(os.path.join(paths.models_path, "VAE"))
vae_ignore_keys = {"model_ema.decay", "model_ema.num_updates"}
Expand Down Expand Up @@ -77,23 +74,27 @@ def refresh_vae_list():
os.path.join(sd_models.model_path, '**/*.vae.ckpt'),
os.path.join(sd_models.model_path, '**/*.vae.pt'),
os.path.join(sd_models.model_path, '**/*.vae.safetensors'),
os.path.join(sd_models.model_path, '**/*.vae.sft'),
os.path.join(vae_path, '**/*.ckpt'),
os.path.join(vae_path, '**/*.pt'),
os.path.join(vae_path, '**/*.safetensors'),
os.path.join(vae_path, '**/*.sft'),
]

if shared.cmd_opts.ckpt_dir is not None and os.path.isdir(shared.cmd_opts.ckpt_dir):
paths += [
os.path.join(shared.cmd_opts.ckpt_dir, '**/*.vae.ckpt'),
os.path.join(shared.cmd_opts.ckpt_dir, '**/*.vae.pt'),
os.path.join(shared.cmd_opts.ckpt_dir, '**/*.vae.safetensors'),
os.path.join(shared.cmd_opts.ckpt_dir, '**/*.vae.sft'),
]

if shared.cmd_opts.vae_dir is not None and os.path.isdir(shared.cmd_opts.vae_dir):
paths += [
os.path.join(shared.cmd_opts.vae_dir, '**/*.ckpt'),
os.path.join(shared.cmd_opts.vae_dir, '**/*.pt'),
os.path.join(shared.cmd_opts.vae_dir, '**/*.safetensors'),
os.path.join(shared.cmd_opts.vae_dir, '**/*.sft'),
]

candidates = []
Expand Down
4 changes: 2 additions & 2 deletions modules_forge/main_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def refresh_models():
shared_items.refresh_checkpoints()
ckpt_list = shared_items.list_checkpoint_tiles(shared.opts.sd_checkpoint_dropdown_use_short)

file_extensions = ['ckpt', 'pt', 'bin', 'safetensors', 'gguf']
vae_file_extensions = ['ckpt', 'pt', 'bin', 'safetensors', 'gguf', 'sft']

module_list.clear()

Expand All @@ -157,7 +157,7 @@ def refresh_models():
module_paths.append(os.path.abspath(shared.cmd_opts.text_encoder_dir))

for vae_path in module_paths:
vae_files = find_files_with_extensions(vae_path, file_extensions)
vae_files = find_files_with_extensions(vae_path, vae_file_extensions)
module_list.update(vae_files)

return ckpt_list, module_list.keys()
Expand Down