Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,8 @@ def get_lora_sd_pipeline(
|
|
24 |
base_model_name_or_path=model_id_default,
|
25 |
dtype=torch_dtype,
|
26 |
device=device,
|
27 |
-
adapter_name="default"
|
|
|
28 |
):
|
29 |
unet_sub_dir = os.path.join(ckpt_dir, "unet")
|
30 |
text_encoder_sub_dir = os.path.join(ckpt_dir, "text_encoder")
|
@@ -38,6 +39,9 @@ def get_lora_sd_pipeline(
|
|
38 |
pipe = StableDiffusionPipeline.from_pretrained(base_model_name_or_path, torch_dtype=dtype).to(device)
|
39 |
pipe.unet = PeftModel.from_pretrained(pipe.unet, unet_sub_dir, adapter_name=adapter_name)
|
40 |
pipe.unet.set_adapter(adapter_name)
|
|
|
|
|
|
|
41 |
|
42 |
if os.path.exists(text_encoder_sub_dir):
|
43 |
pipe.text_encoder = PeftModel.from_pretrained(
|
@@ -93,11 +97,12 @@ def infer(
|
|
93 |
):
|
94 |
generator = torch.Generator(device).manual_seed(seed)
|
95 |
pipe = get_lora_sd_pipeline(base_model_name_or_path=model_id,
|
96 |
-
adapter_name="sticker_of_funny_cat_Pusheen"
|
|
|
97 |
pipe = pipe.to(device)
|
98 |
prompt_embeds = encode_prompt(prompt, pipe.tokenizer, pipe.text_encoder)
|
99 |
negative_prompt_embeds = encode_prompt(negative_prompt, pipe.tokenizer, pipe.text_encoder)
|
100 |
-
pipe.fuse_lora(lora_scale=lora_scale)
|
101 |
|
102 |
image = pipe(
|
103 |
prompt_embeds=prompt_embeds,
|
|
|
24 |
base_model_name_or_path=model_id_default,
|
25 |
dtype=torch_dtype,
|
26 |
device=device,
|
27 |
+
adapter_name="default",
|
28 |
+
lora_scale=0.8
|
29 |
):
|
30 |
unet_sub_dir = os.path.join(ckpt_dir, "unet")
|
31 |
text_encoder_sub_dir = os.path.join(ckpt_dir, "text_encoder")
|
|
|
39 |
pipe = StableDiffusionPipeline.from_pretrained(base_model_name_or_path, torch_dtype=dtype).to(device)
|
40 |
pipe.unet = PeftModel.from_pretrained(pipe.unet, unet_sub_dir, adapter_name=adapter_name)
|
41 |
pipe.unet.set_adapter(adapter_name)
|
42 |
+
pipe.unet.set_peft_model_state_dict(
|
43 |
+
{k: v*lora_scale for k, v in pipe.unet.state_dict().items()}
|
44 |
+
)
|
45 |
|
46 |
if os.path.exists(text_encoder_sub_dir):
|
47 |
pipe.text_encoder = PeftModel.from_pretrained(
|
|
|
97 |
):
|
98 |
generator = torch.Generator(device).manual_seed(seed)
|
99 |
pipe = get_lora_sd_pipeline(base_model_name_or_path=model_id,
|
100 |
+
adapter_name="sticker_of_funny_cat_Pusheen",
|
101 |
+
lora_scale=lora_scale)
|
102 |
pipe = pipe.to(device)
|
103 |
prompt_embeds = encode_prompt(prompt, pipe.tokenizer, pipe.text_encoder)
|
104 |
negative_prompt_embeds = encode_prompt(negative_prompt, pipe.tokenizer, pipe.text_encoder)
|
105 |
+
# pipe.fuse_lora(lora_scale=lora_scale)
|
106 |
|
107 |
image = pipe(
|
108 |
prompt_embeds=prompt_embeds,
|