Instructions to use na1taneja2821/diffusers with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use na1taneja2821/diffusers with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.bfloat16, device_map="cuda") pipe.load_lora_weights("na1taneja2821/diffusers") prompt = "a photo of sks dog" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
ํ๋กฌํํธ์ ๊ฐ์ค์น ๋ถ์ฌํ๊ธฐ
[[open-in-colab]]
ํ ์คํธ ๊ฐ์ด๋ ๊ธฐ๋ฐ์ diffusion ๋ชจ๋ธ์ ์ฃผ์ด์ง ํ ์คํธ ํ๋กฌํํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ด๋ฏธ์ง๋ฅผ ์์ฑํฉ๋๋ค. ํ ์คํธ ํ๋กฌํํธ์๋ ๋ชจ๋ธ์ด ์์ฑํด์ผ ํ๋ ์ฌ๋ฌ ๊ฐ๋ ์ด ํฌํจ๋ ์ ์์ผ๋ฉฐ ํ๋กฌํํธ์ ํน์ ๋ถ๋ถ์ ๊ฐ์ค์น๋ฅผ ๋ถ์ฌํ๋ ๊ฒ์ด ๋ฐ๋์งํ ๊ฒฝ์ฐ๊ฐ ๋ง์ต๋๋ค.
Diffusion ๋ชจ๋ธ์ ๋ฌธ๋งฅํ๋ ํ ์คํธ ์๋ฒ ๋ฉ์ผ๋ก diffusion ๋ชจ๋ธ์ cross attention ๋ ์ด์ด๋ฅผ ์กฐ์ ํจ์ผ๋ก์จ ์๋ํฉ๋๋ค. (๋ ๋ง์ ์ ๋ณด๋ฅผ ์ํ Stable Diffusion Guide๋ฅผ ์ฐธ๊ณ ํ์ธ์). ๋ฐ๋ผ์ ํ๋กฌํํธ์ ํน์ ๋ถ๋ถ์ ๊ฐ์กฐํ๋(๋๋ ๊ฐ์กฐํ์ง ์๋) ๊ฐ๋จํ ๋ฐฉ๋ฒ์ ํ๋กฌํํธ์ ๊ด๋ จ ๋ถ๋ถ์ ํด๋นํ๋ ํ ์คํธ ์๋ฒ ๋ฉ ๋ฒกํฐ์ ํฌ๊ธฐ๋ฅผ ๋๋ฆฌ๊ฑฐ๋ ์ค์ด๋ ๊ฒ์ ๋๋ค. ์ด๊ฒ์ "ํ๋กฌํํธ ๊ฐ์ค์น ๋ถ์ฌ" ๋ผ๊ณ ํ๋ฉฐ, ์ปค๋ฎค๋ํฐ์์ ๊ฐ์ฅ ์๊ตฌํ๋ ๊ธฐ๋ฅ์ ๋๋ค.(์ด๊ณณ์ issue๋ฅผ ๋ณด์ธ์ ).
Diffusers์์ ํ๋กฌํํธ ๊ฐ์ค์น ๋ถ์ฌํ๋ ๋ฐฉ๋ฒ
์ฐ๋ฆฌ๋ diffusers์ ์ญํ ์ด ๋ค๋ฅธ ํ๋ก์ ํธ๋ฅผ ๊ฐ๋ฅํ๊ฒ ํ๋ ํ์์ ์ธ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ toolbex๋ผ๊ณ ์๊ฐํฉ๋๋ค.
InvokeAI ๋ diffuzers ๊ฐ์ ๊ฐ๋ ฅํ UI๋ฅผ ๊ตฌ์ถํ ์ ์์ต๋๋ค.
ํ๋กฌํํธ๋ฅผ ์กฐ์ํ๋ ๋ฐฉ๋ฒ์ ์ง์ํ๊ธฐ ์ํด, diffusers ๋
StableDiffusionPipeline์ ๊ฐ์
๋ง์ ํ์ดํ๋ผ์ธ์ prompt_embeds
์ธ์๋ฅผ ๋
ธ์ถ์์ผ, "prompt-weighted"/์ถ์ฒ๋ ํ
์คํธ ์๋ฒ ๋ฉ์ ํ์ดํ๋ผ์ธ์ ๋ฐ๋ก ์ ๋ฌํ ์ ์๊ฒ ํฉ๋๋ค.
Compel ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ํ๋กฌํํธ์ ์ผ๋ถ๋ฅผ ๊ฐ์กฐํ๊ฑฐ๋ ๊ฐ์กฐํ์ง ์์ ์ ์๋ ์ฌ์ด ๋ฐฉ๋ฒ์ ์ ๊ณตํฉ๋๋ค. ์๋ฒ ๋ฉ์ ์ง์ ์ค๋นํ๋ ๊ฒ ๋์ ์ด ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ ๊ฒ์ ๊ฐ๋ ฅํ ์ถ์ฒํฉ๋๋ค.
๊ฐ๋จํ ์์ ๋ฅผ ์ดํด๋ณด๊ฒ ์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ด "๊ณต์ ๊ฐ๊ณ ๋
ธ๋ ๋ถ์์ ๊ณ ์์ด" ์ด๋ฏธ์ง๋ฅผ ์์ฑํ๊ณ ์ถ์ต๋๋ค:
from diffusers import StableDiffusionPipeline, UniPCMultistepScheduler
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
prompt = "a red cat playing with a ball"
generator = torch.Generator(device="cpu").manual_seed(33)
image = pipe(prompt, generator=generator, num_inference_steps=20).images[0]
image
์์ฑ๋ ์ด๋ฏธ์ง:
์ฌ์ง์์ ์ ์ ์๋ฏ์ด, "๊ณต"์ ์ด๋ฏธ์ง์ ์์ต๋๋ค. ์ด ๋ถ๋ถ์ ๊ฐ์กฐํด ๋ณผ๊น์!
๋จผ์ compel ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํด์ผํฉ๋๋ค:
pip install compel
๊ทธ๋ฐ ๋ค์์๋ Compel ์ค๋ธ์ ํธ๋ฅผ ์์ฑํฉ๋๋ค:
from compel import Compel
compel_proc = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)
์ด์ "++" ๋ฅผ ์ฌ์ฉํด์ "๊ณต" ์ ๊ฐ์กฐํด ๋ด
์๋ค:
prompt = "a red cat playing with a ball++"
๊ทธ๋ฆฌ๊ณ ์ด ํ๋กฌํํธ๋ฅผ ํ์ดํ๋ผ์ธ์ ๋ฐ๋ก ์ ๋ฌํ์ง ์๊ณ , compel_proc ๋ฅผ ์ฌ์ฉํ์ฌ ์ฒ๋ฆฌํด์ผํฉ๋๋ค:
prompt_embeds = compel_proc(prompt)
ํ์ดํ๋ผ์ธ์ prompt_embeds ๋ฅผ ๋ฐ๋ก ์ ๋ฌํ ์ ์์ต๋๋ค:
generator = torch.Generator(device="cpu").manual_seed(33)
images = pipe(prompt_embeds=prompt_embeds, generator=generator, num_inference_steps=20).images[0]
image
์ด์ "๊ณต"์ด ์๋ ๊ทธ๋ฆผ์ ์ถ๋ ฅํ ์ ์์ต๋๋ค!
๋ง์ฐฌ๊ฐ์ง๋ก -- ์ ๋ฏธ์ฌ๋ฅผ ๋จ์ด์ ์ฌ์ฉํ์ฌ ๋ฌธ์ฅ์ ์ผ๋ถ๋ฅผ ๊ฐ์กฐํ์ง ์์ ์ ์์ต๋๋ค. ํ๋ฒ ์๋ํด ๋ณด์ธ์!
์ฆ๊ฒจ์ฐพ๋ ํ์ดํ๋ผ์ธ์ prompt_embeds ์
๋ ฅ์ด ์๋ ๊ฒฝ์ฐ issue๋ฅผ ์๋ก ๋ง๋ค์ด์ฃผ์ธ์.
Diffusers ํ์ ์ต๋ํ ๋์ํ๋ ค๊ณ ๋
ธ๋ ฅํฉ๋๋ค.
Compel 1.1.6 ๋ textual inversions์ ์ฌ์ฉํ์ฌ ๋จ์ํํ๋ ์ ํฐ๋ฆดํฐ ํด๋์ค๋ฅผ ์ถ๊ฐํฉ๋๋ค.
DiffusersTextualInversionManager๋ฅผ ์ธ์คํด์คํ ํ ํ ์ด๋ฅผ Compel init์ ์ ๋ฌํฉ๋๋ค:
textual_inversion_manager = DiffusersTextualInversionManager(pipe)
compel = Compel(
tokenizer=pipe.tokenizer,
text_encoder=pipe.text_encoder,
textual_inversion_manager=textual_inversion_manager)
๋ ๋ง์ ์ ๋ณด๋ฅผ ์ป๊ณ ์ถ๋ค๋ฉด compel ๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ฌธ์๋ฅผ ์ฐธ๊ณ ํ์ธ์.

