Skip to content

Commit 2ec6e9e

Browse files
authored
Merge pull request #3328 from vladmandic/dev
merge
2 parents 4a03368 + 8e170f5 commit 2ec6e9e

File tree

5 files changed

+33
-29
lines changed

5 files changed

+33
-29
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ This release is primary service release with cumulative fixes and several improv
6767
- fix control input type video
6868
- fix reset pipeline at the end of each iteration
6969
- fix faceswap when no faces detected
70+
- fix civitai search
7071
- multiple ModernUI fixes
7172

7273
## Update for 2024-06-23

modules/model_kolors.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
import torch
2-
import transformers
32
import diffusers
43

54

65
repo_id = 'Kwai-Kolors/Kolors'
7-
encoder_id = 'THUDM/chatglm3-6b'
86

97

108
def load_kolors(_checkpoint_info, diffusers_load_config={}):
119
from modules import shared, devices, modelloader
1210
modelloader.hf_login()
1311
diffusers_load_config['variant'] = "fp16"
1412
if 'torch_dtype' not in diffusers_load_config:
15-
diffusers_load_config['torch_dtype'] = 'torch.float16'
13+
diffusers_load_config['torch_dtype'] = torch.float16
1614

17-
text_encoder = transformers.AutoModel.from_pretrained(encoder_id, torch_dtype=torch.float16, trust_remote_code=True, cache_dir=shared.opts.diffusers_dir)
15+
# import torch
16+
# import transformers
17+
# encoder_id = 'THUDM/chatglm3-6b'
18+
# text_encoder = transformers.AutoModel.from_pretrained(encoder_id, torch_dtype=torch.float16, trust_remote_code=True, cache_dir=shared.opts.diffusers_dir)
1819
# text_encoder = transformers.AutoModel.from_pretrained("THUDM/chatglm3-6b", torch_dtype=torch.float16, trust_remote_code=True).quantize(4).cuda()
19-
tokenizer = transformers.AutoTokenizer.from_pretrained(encoder_id, trust_remote_code=True, cache_dir=shared.opts.diffusers_dir)
20-
pipe = diffusers.StableDiffusionXLPipeline.from_pretrained(
20+
# tokenizer = transformers.AutoTokenizer.from_pretrained(encoder_id, trust_remote_code=True, cache_dir=shared.opts.diffusers_dir)
21+
pipe = diffusers.KolorsPipeline.from_pretrained(
2122
repo_id,
22-
tokenizer=tokenizer,
23-
text_encoder=text_encoder,
2423
cache_dir = shared.opts.diffusers_dir,
2524
**diffusers_load_config,
2625
)

modules/modelloader.py

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def download_civit_model_thread(model_name, model_url, model_path, model_type, t
101101
elif model_type == 'Embedding':
102102
model_file = os.path.join(shared.opts.embeddings_dir, model_path, model_name)
103103
temp_file = os.path.join(shared.opts.embeddings_dir, model_path, temp_file)
104+
elif model_type == 'VAE':
105+
model_file = os.path.join(shared.opts.vae_dir, model_path, model_name)
106+
temp_file = os.path.join(shared.opts.vae_dir, model_path, temp_file)
104107
else:
105108
model_file = os.path.join(shared.opts.ckpt_dir, model_path, model_name)
106109
temp_file = os.path.join(shared.opts.ckpt_dir, model_path, temp_file)

modules/textual_inversion/textual_inversion.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def insert_tokens(embeddings: list, tokenizers: list):
121121
"""
122122
tokens = []
123123
for embedding in embeddings:
124-
tokens += embedding.tokens
124+
if embedding is not None:
125+
tokens += embedding.tokens
125126
for tokenizer in tokenizers:
126127
tokenizer.add_tokens(tokens)
127128

@@ -295,7 +296,8 @@ def load_diffusers_embedding(self, filename: Union[str, List[str]] = None, data:
295296
(len(embedding.vector_sizes) < len(hiddensizes) and len(embedding.vector_sizes) != 2)): # SD3 no T5
296297
embedding.tokens = []
297298
self.skipped_embeddings[embedding.name] = embedding
298-
except Exception:
299+
except Exception as e:
300+
shared.log.error(f'Embedding invalid: name="{embedding.name}" fn="{filename}" {e}')
299301
self.skipped_embeddings[embedding.name] = embedding
300302
if overwrite:
301303
shared.log.info(f"Loading Bundled embeddings: {list(data.keys())}")

modules/ui_models.py

+18-19
Original file line numberDiff line numberDiff line change
@@ -418,41 +418,41 @@ def hf_download_model(hub_id: str, token, variant, revision, mirror, custom_pipe
418418
def civit_search_model(name, tag, model_type):
419419
# types = 'LORA' if model_type == 'LoRA' else 'Checkpoint'
420420
url = 'https://civitai.com/api/v1/models?limit=25&Sort=Newest'
421-
if model_type == 'SD 1.5' or model_type == 'SD XL':
421+
if model_type == 'Model':
422422
url += '&types=Checkpoint'
423423
elif model_type == 'LoRA':
424-
url += '&types=LORA'
424+
url += '&types=LORA&types=DoRA&types=LoCon'
425425
elif model_type == 'Embedding':
426426
url += '&types=TextualInversion'
427+
elif model_type == 'VAE':
428+
url += '&types=VAE'
427429
if name is not None and len(name) > 0:
428430
url += f'&query={name}'
429431
if tag is not None and len(tag) > 0:
430432
url += f'&tag={tag}'
431433
r = req(url)
432434
log.debug(f'CivitAI search: name="{name}" tag={tag or "none"} url="{url}" status={r.status_code}')
433435
if r.status_code != 200:
436+
log.warning(f'CivitAI search: name="{name}" tag={tag} status={r.status_code}')
437+
return [], gr.update(visible=False, value=[]), gr.update(visible=False, value=None), gr.update(visible=False, value=None)
438+
try:
439+
body = r.json()
440+
except Exception as e:
441+
log.error(f'CivitAI search: name="{name}" tag={tag} {e}')
434442
return [], gr.update(visible=False, value=[]), gr.update(visible=False, value=None), gr.update(visible=False, value=None)
435-
body = r.json()
436443
nonlocal data
437444
data = body.get('items', [])
438445
data1 = []
439446
for model in data:
440447
found = 0
441-
if model_type == 'LoRA' and model['type'] in ['LORA', 'LoCon']:
448+
if model_type == 'LoRA' and model['type'].lower() in ['lora', 'locon', 'dora', 'lycoris']:
442449
found += 1
443-
elif model_type == 'Embedding' and model['type'] == 'TextualInversion':
450+
elif model_type == 'Embedding' and model['type'].lower() in ['textualinversion', 'embedding']:
451+
found += 1
452+
elif model_type == 'Model' and model['type'].lower() in ['checkpoint']:
453+
found += 1
454+
elif model_type == 'VAE' and model['type'].lower() in ['vae']:
444455
found += 1
445-
elif model_type.startswith('SD') and model['type'] == 'Checkpoint':
446-
for variant in model['modelVersions']:
447-
if model_type == 'SD 1.5':
448-
if 'SD 1.' in variant['baseModel']:
449-
found += 1
450-
if model_type == 'SD XL':
451-
if 'SDXL' in variant['baseModel']:
452-
found += 1
453-
else:
454-
if 'SD 1.' not in variant['baseModel'] and 'SDXL' not in variant['baseModel']:
455-
found += 1
456456
elif model_type == 'Other':
457457
found += 1
458458
if found > 0:
@@ -464,8 +464,7 @@ def civit_search_model(name, tag, model_type):
464464
model['stats']['rating']
465465
])
466466
res = f'Search result: name={name} tag={tag or "none"} type={model_type} models={len(data1)}'
467-
return res, gr.update(visible=len(data1) > 0, value=data1 if len(data1) > 0 else []), gr.update(
468-
visible=False, value=None), gr.update(visible=False, value=None)
467+
return res, gr.update(visible=len(data1) > 0, value=data1 if len(data1) > 0 else []), gr.update(visible=False, value=None), gr.update(visible=False, value=None)
469468

470469
def civit_select1(evt: gr.SelectData, in_data):
471470
model_id = in_data[evt.index[0]][0]
@@ -596,7 +595,7 @@ def civit_search_metadata(rehash, title):
596595
gr.HTML('<h2>Search for models</h2>')
597596
with gr.Row():
598597
with gr.Column(scale=1):
599-
civit_model_type = gr.Dropdown(label='Model type', choices=['SD 1.5', 'SD XL', 'LoRA', 'Embedding', 'Other'], value='LoRA')
598+
civit_model_type = gr.Dropdown(label='Model type', choices=['Model', 'LoRA', 'Embedding', 'VAE', 'Other'], value='Model')
600599
with gr.Column(scale=15):
601600
with gr.Row():
602601
civit_search_text = gr.Textbox('', label='Search models', placeholder='keyword')

0 commit comments

Comments
 (0)