Upamanyu098's picture
End of training
ef4d689 verified
|
raw
history blame
10.9 kB
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
-->
# ๋‹ค์–‘ํ•œ Stable Diffusion ํฌ๋งท ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
Stable Diffusion ๋ชจ๋ธ๋“ค์€ ํ•™์Šต ๋ฐ ์ €์žฅ๋œ ํ”„๋ ˆ์ž„์›Œํฌ์™€ ๋‹ค์šด๋กœ๋“œ ์œ„์น˜์— ๋”ฐ๋ผ ๋‹ค์–‘ํ•œ ํ˜•์‹์œผ๋กœ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ํ˜•์‹์„ ๐Ÿค— Diffusers์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ณ€ํ™˜ํ•˜๋ฉด ์ถ”๋ก ์„ ์œ„ํ•œ [๋‹ค์–‘ํ•œ ์Šค์ผ€์ค„๋Ÿฌ ์‚ฌ์šฉ](schedulers), ์‚ฌ์šฉ์ž ์ง€์ • ํŒŒ์ดํ”„๋ผ์ธ ๊ตฌ์ถ•, ์ถ”๋ก  ์†๋„ ์ตœ์ ํ™”๋ฅผ ์œ„ํ•œ ๋‹ค์–‘ํ•œ ๊ธฐ๋ฒ•๊ณผ ๋ฐฉ๋ฒ• ๋“ฑ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์—์„œ ์ง€์›ํ•˜๋Š” ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
<Tip>
์šฐ๋ฆฌ๋Š” `.safetensors` ํ˜•์‹์„ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค. ์™œ๋ƒํ•˜๋ฉด ๊ธฐ์กด์˜ pickled ํŒŒ์ผ์€ ์ทจ์•ฝํ•˜๊ณ  ๋จธ์‹ ์—์„œ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•  ๋•Œ ์•…์šฉ๋  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์— ๋น„ํ•ด ํ›จ์”ฌ ๋” ์•ˆ์ „ํ•ฉ๋‹ˆ๋‹ค. (safetensors ๋ถˆ๋Ÿฌ์˜ค๊ธฐ ๊ฐ€์ด๋“œ์—์„œ ์ž์„ธํžˆ ์•Œ์•„๋ณด์„ธ์š”.)
</Tip>
์ด ๊ฐ€์ด๋“œ์—์„œ๋Š” ๋‹ค๋ฅธ Stable Diffusion ํ˜•์‹์„ ๐Ÿค— Diffusers์™€ ํ˜ธํ™˜๋˜๋„๋ก ๋ณ€ํ™˜ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.
## PyTorch .ckpt
์ฒดํฌํฌ์ธํŠธ ๋˜๋Š” `.ckpt` ํ˜•์‹์€ ์ผ๋ฐ˜์ ์œผ๋กœ ๋ชจ๋ธ์„ ์ €์žฅํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. `.ckpt` ํŒŒ์ผ์€ ์ „์ฒด ๋ชจ๋ธ์„ ํฌํ•จํ•˜๋ฉฐ ์ผ๋ฐ˜์ ์œผ๋กœ ํฌ๊ธฐ๊ฐ€ ๋ช‡ GB์ž…๋‹ˆ๋‹ค. `.ckpt` ํŒŒ์ผ์„ [~StableDiffusionPipeline.from_ckpt] ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ง์ ‘ ๋ถˆ๋Ÿฌ์™€์„œ ์‚ฌ์šฉํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ, ์ผ๋ฐ˜์ ์œผ๋กœ ๋‘ ๊ฐ€์ง€ ํ˜•์‹์„ ๋ชจ๋‘ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก `.ckpt` ํŒŒ์ผ์„ ๐Ÿค— Diffusers๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฒƒ์ด ๋” ์ข‹์Šต๋‹ˆ๋‹ค.
`.ckpt` ํŒŒ์ผ์„ ๋ณ€ํ™˜ํ•˜๋Š” ๋‘ ๊ฐ€์ง€ ์˜ต์…˜์ด ์žˆ์Šต๋‹ˆ๋‹ค. Space๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฒดํฌํฌ์ธํŠธ๋ฅผ ๋ณ€ํ™˜ํ•˜๊ฑฐ๋‚˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ `.ckpt` ํŒŒ์ผ์„ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
### Space๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ
`.ckpt` ํŒŒ์ผ์„ ๋ณ€ํ™˜ํ•˜๋Š” ๊ฐ€์žฅ ์‰ฝ๊ณ  ํŽธ๋ฆฌํ•œ ๋ฐฉ๋ฒ•์€ SD์—์„œ Diffusers๋กœ ์ŠคํŽ˜์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. Space์˜ ์ง€์นจ์— ๋”ฐ๋ผ .ckpt ํŒŒ์ผ์„ ๋ณ€ํ™˜ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด ์ ‘๊ทผ ๋ฐฉ์‹์€ ๊ธฐ๋ณธ ๋ชจ๋ธ์—์„œ๋Š” ์ž˜ ์ž‘๋™ํ•˜์ง€๋งŒ ๋” ๋งŽ์€ ์‚ฌ์šฉ์ž ์ •์˜ ๋ชจ๋ธ์—์„œ๋Š” ์–ด๋ ค์›€์„ ๊ฒช์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋นˆ pull request๋‚˜ ์˜ค๋ฅ˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด Space๊ฐ€ ์‹คํŒจํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
์ด ๊ฒฝ์šฐ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ `.ckpt` ํŒŒ์ผ์„ ๋ณ€ํ™˜ํ•ด ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
### ์Šคํฌ๋ฆฝํŠธ๋กœ ๋ณ€ํ™˜ํ•˜๊ธฐ
๐Ÿค— Diffusers๋Š” `.ckpt`ย  ํŒŒ์ผ ๋ณ€ํ™˜์„ ์œ„ํ•œ ๋ณ€ํ™˜ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ด ์ ‘๊ทผ ๋ฐฉ์‹์€ ์œ„์˜ Space๋ณด๋‹ค ๋” ์•ˆ์ •์ ์ž…๋‹ˆ๋‹ค.
์‹œ์ž‘ํ•˜๊ธฐ ์ „์— ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•  ๐Ÿค— Diffusers์˜ ๋กœ์ปฌ ํด๋ก (clone)์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  Hugging Face ๊ณ„์ •์— ๋กœ๊ทธ์ธํ•˜์—ฌ pull request๋ฅผ ์—ด๊ณ  ๋ณ€ํ™˜๋œ ๋ชจ๋ธ์„ ํ—ˆ๋ธŒ์— ํ‘ธ์‹œํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜์„ธ์š”.
```bash
huggingface-cli login
```
์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด:
1. ๋ณ€ํ™˜ํ•˜๋ ค๋Š” `.ckpt`ย  ํŒŒ์ผ์ด ํฌํ•จ๋œ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ Git์œผ๋กœ ํด๋ก (clone)ํ•ฉ๋‹ˆ๋‹ค.
์ด ์˜ˆ์ œ์—์„œ๋Š” TemporalNet .ckpt ํŒŒ์ผ์„ ๋ณ€ํ™˜ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค:
```bash
git lfs install
git clone https://huggingface.co/CiaraRowles/TemporalNet
```
2. ์ฒดํฌํฌ์ธํŠธ๋ฅผ ๋ณ€ํ™˜ํ•  ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ pull request๋ฅผ ์—ฝ๋‹ˆ๋‹ค:
```bash
cd TemporalNet && git fetch origin refs/pr/13:pr/13
git checkout pr/13
```
3. ๋ณ€ํ™˜ ์Šคํฌ๋ฆฝํŠธ์—์„œ ๊ตฌ์„ฑํ•  ์ž…๋ ฅ ์ธ์ˆ˜๋Š” ์—ฌ๋Ÿฌ ๊ฐ€์ง€๊ฐ€ ์žˆ์ง€๋งŒ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์ธ์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:
- `checkpoint_path`: ๋ณ€ํ™˜ํ•  `.ckpt` ํŒŒ์ผ์˜ ๊ฒฝ๋กœ๋ฅผ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.
- `original_config_file`: ์›๋ž˜ ์•„ํ‚คํ…์ฒ˜์˜ ๊ตฌ์„ฑ์„ ์ •์˜ํ•˜๋Š” YAML ํŒŒ์ผ์ž…๋‹ˆ๋‹ค. ์ด ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ `.ckpt` ํŒŒ์ผ์„ ์ฐพ์€ GitHub ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ YAML ํŒŒ์ผ์„ ๊ฒ€์ƒ‰ํ•ด ๋ณด์„ธ์š”.
- `dump_path`: ๋ณ€ํ™˜๋œ ๋ชจ๋ธ์˜ ๊ฒฝ๋กœ
์˜ˆ๋ฅผ ๋“ค์–ด, TemporalNet ๋ชจ๋ธ์€ Stable Diffusion v1.5 ๋ฐ ControlNet ๋ชจ๋ธ์ด๊ธฐ ๋•Œ๋ฌธ์— ControlNet ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์—์„œ cldm_v15.yaml ํŒŒ์ผ์„ ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
4. ์ด์ œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜์—ฌ .ckpt ํŒŒ์ผ์„ ๋ณ€ํ™˜ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```bash
python ../diffusers/scripts/convert_original_stable_diffusion_to_diffusers.py --checkpoint_path temporalnetv3.ckpt --original_config_file cldm_v15.yaml --dump_path ./ --controlnet
```
5. ๋ณ€ํ™˜์ด ์™„๋ฃŒ๋˜๋ฉด ๋ณ€ํ™˜๋œ ๋ชจ๋ธ์„ ์—…๋กœ๋“œํ•˜๊ณ  ๊ฒฐ๊ณผ๋ฌผ์„ pull requestย [pull request](https://huggingface.co/CiaraRowles/TemporalNet/discussions/13)๋ฅผ ํ…Œ์ŠคํŠธํ•˜์„ธ์š”!
```bash
git push origin pr/13:refs/pr/13
```
## **Keras .pb or .h5**
๐Ÿงช ์ด ๊ธฐ๋Šฅ์€ ์‹คํ—˜์ ์ธ ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค. ํ˜„์žฌ๋กœ์„œ๋Š” Stable Diffusion v1 ์ฒดํฌํฌ์ธํŠธ๋งŒ ๋ณ€ํ™˜ KerasCV Space์—์„œ ์ง€์›๋ฉ๋‹ˆ๋‹ค.
[KerasCV](https://keras.io/keras_cv/)๋Š” [Stable Diffusion](https://github.com/keras-team/keras-cv/blob/master/keras_cv/models/stable_diffusion)ย  v1 ๋ฐ v2์— ๋Œ€ํ•œ ํ•™์Šต์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์ถ”๋ก  ๋ฐ ๋ฐฐํฌ๋ฅผ ์œ„ํ•œ Stable Diffusion ๋ชจ๋ธ ์‹คํ—˜์„ ์ œํ•œ์ ์œผ๋กœ ์ง€์›ํ•˜๋Š” ๋ฐ˜๋ฉด, ๐Ÿค— Diffusers๋Š” ๋‹ค์–‘ํ•œ [noise schedulers](https://huggingface.co/docs/diffusers/using-diffusers/schedulers),ย [flash attention](https://huggingface.co/docs/diffusers/optimization/xformers), andย [other optimization techniques](https://huggingface.co/docs/diffusers/optimization/fp16) ๋“ฑ ์ด๋Ÿฌํ•œ ๋ชฉ์ ์„ ์œ„ํ•œ ๋ณด๋‹ค ์™„๋ฒฝํ•œ ๊ธฐ๋Šฅ์„ ๊ฐ–์ถ”๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
[Convert KerasCV](https://huggingface.co/spaces/sayakpaul/convert-kerascv-sd-diffusers)ย Space ๋ณ€ํ™˜์€ `.pb`ย ๋˜๋Š”ย `.h5`์„ PyTorch๋กœ ๋ณ€ํ™˜ํ•œ ๋‹ค์Œ, ์ถ”๋ก ํ•  ์ˆ˜ ์žˆ๋„๋ก [`StableDiffusionPipeline`] ์œผ๋กœ ๊ฐ์‹ธ์„œ ์ค€๋น„ํ•ฉ๋‹ˆ๋‹ค. ๋ณ€ํ™˜๋œ ์ฒดํฌํฌ์ธํŠธ๋Š” Hugging Face Hub์˜ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
์˜ˆ์ œ๋กœ, textual-inversion์œผ๋กœ ํ•™์Šต๋œ `[sayakpaul/textual-inversion-kerasio](https://huggingface.co/sayakpaul/textual-inversion-kerasio/tree/main)`ย ์ฒดํฌํฌ์ธํŠธ๋ฅผ ๋ณ€ํ™˜ํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ํŠน์ˆ˜ ํ† ํฐ ย `<my-funny-cat>`์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ณ ์–‘์ด๋กœ ์ด๋ฏธ์ง€๋ฅผ ๊ฐœ์ธํ™”ํ•ฉ๋‹ˆ๋‹ค.
KerasCV Space ๋ณ€ํ™˜์—์„œ๋Š” ๋‹ค์Œ์„ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
- Hugging Face ํ† ํฐ.
- UNet ๊ณผ ํ…์ŠคํŠธ ์ธ์ฝ”๋”(text encoder) ๊ฐ€์ค‘์น˜๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๋Š” ๊ฒฝ๋กœ์ž…๋‹ˆ๋‹ค. ๋ชจ๋ธ์„ ์–ด๋–ป๊ฒŒ ํ•™์Šตํ• ์ง€ ๋ฐฉ์‹์— ๋”ฐ๋ผ, UNet๊ณผ ํ…์ŠคํŠธ ์ธ์ฝ”๋”์˜ ๊ฒฝ๋กœ๋ฅผ ๋ชจ๋‘ ์ œ๊ณตํ•  ํ•„์š”๋Š” ์—†์Šต๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, textual-inversion์—๋Š” ํ…์ŠคํŠธ ์ธ์ฝ”๋”์˜ ์ž„๋ฒ ๋”ฉ๋งŒ ํ•„์š”ํ•˜๊ณ  ํ…์ŠคํŠธ-์ด๋ฏธ์ง€(text-to-image) ๋ชจ๋ธ ๋ณ€ํ™˜์—๋Š” UNet ๊ฐ€์ค‘์น˜๋งŒ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
- Placeholder ํ† ํฐ์€ textual-inversion ๋ชจ๋ธ์—๋งŒ ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.
- `output_repo_prefix`๋Š” ๋ณ€ํ™˜๋œ ๋ชจ๋ธ์ด ์ €์žฅ๋˜๋Š” ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.
**Submit**ย (์ œ์ถœ) ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜๋ฉด KerasCV ์ฒดํฌํฌ์ธํŠธ๊ฐ€ ์ž๋™์œผ๋กœ ๋ณ€ํ™˜๋ฉ๋‹ˆ๋‹ค! ์ฒดํฌํฌ์ธํŠธ๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ๋ณ€ํ™˜๋˜๋ฉด, ๋ณ€ํ™˜๋œ ์ฒดํฌํฌ์ธํŠธ๊ฐ€ ํฌํ•จ๋œ ์ƒˆ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋กœ ์—ฐ๊ฒฐ๋˜๋Š” ๋งํฌ๊ฐ€ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค. ์ƒˆ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋กœ ์—ฐ๊ฒฐ๋˜๋Š” ๋งํฌ๋ฅผ ๋”ฐ๋ผ๊ฐ€๋ฉด ๋ณ€ํ™˜๋œ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•ด ๋ณผ ์ˆ˜ ์žˆ๋Š” ์ถ”๋ก  ์œ„์ ฏ์ด ํฌํ•จ๋œ ๋ชจ๋ธ ์นด๋“œ๊ฐ€ ์ƒ์„ฑ๋œ KerasCV Space ๋ณ€ํ™˜์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ฝ”๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ถ”๋ก ์„ ์‹คํ–‰ํ•˜๋ ค๋ฉด ๋ชจ๋ธ ์นด๋“œ์˜ ์˜ค๋ฅธ์ชฝ ์ƒ๋‹จ ๋ชจ์„œ๋ฆฌ์— ์žˆ๋Š” **Use in Diffusers**ย  ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ ์˜ˆ์‹œ ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ ๋ถ™์—ฌ๋„ฃ์Šต๋‹ˆ๋‹ค:
```py
from diffusers import DiffusionPipeline
pipeline = DiffusionPipeline.from_pretrained("sayakpaul/textual-inversion-cat-kerascv_sd_diffusers_pipeline")
```
๊ทธ๋Ÿฌ๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```py
from diffusers import DiffusionPipeline
pipeline = DiffusionPipeline.from_pretrained("sayakpaul/textual-inversion-cat-kerascv_sd_diffusers_pipeline")
pipeline.to("cuda")
placeholder_token = "<my-funny-cat-token>"
prompt = f"two {placeholder_token} getting married, photorealistic, high quality"
image = pipeline(prompt, num_inference_steps=50).images[0]
```
## **A1111 LoRA files**
[Automatic1111](https://github.com/AUTOMATIC1111/stable-diffusion-webui)ย (A1111)์€ Stable Diffusion์„ ์œ„ํ•ด ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ์›น UI๋กœ,ย [Civitai](https://civitai.com/) ์™€ ๊ฐ™์€ ๋ชจ๋ธ ๊ณต์œ  ํ”Œ๋žซํผ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค. ํŠนํžˆ LoRA ๊ธฐ๋ฒ•์œผ๋กœ ํ•™์Šต๋œ ๋ชจ๋ธ์€ ํ•™์Šต ์†๋„๊ฐ€ ๋น ๋ฅด๊ณ  ์™„์ „ํžˆ ํŒŒ์ธํŠœ๋‹๋œ ๋ชจ๋ธ๋ณด๋‹ค ํŒŒ์ผ ํฌ๊ธฐ๊ฐ€ ํ›จ์”ฌ ์ž‘๊ธฐ ๋•Œ๋ฌธ์— ์ธ๊ธฐ๊ฐ€ ๋†’์Šต๋‹ˆ๋‹ค.
๐Ÿค— Diffusers๋Š” [`~loaders.LoraLoaderMixin.load_lora_weights`]:๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ A1111 LoRA ์ฒดํฌํฌ์ธํŠธ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค:
```py
from diffusers import DiffusionPipeline, UniPCMultistepScheduler
import torch
pipeline = DiffusionPipeline.from_pretrained(
"andite/anything-v4.0", torch_dtype=torch.float16, safety_checker=None
).to("cuda")
pipeline.scheduler = UniPCMultistepScheduler.from_config(pipeline.scheduler.config)
```
Civitai์—์„œ LoRA ์ฒดํฌํฌ์ธํŠธ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜์„ธ์š”; ์ด ์˜ˆ์ œ์—์„œ๋Š” ย [Howls Moving Castle,Interior/Scenery LoRA (Ghibli Stlye)](https://civitai.com/models/14605?modelVersionId=19998) ์ฒดํฌํฌ์ธํŠธ๋ฅผ ์‚ฌ์šฉํ–ˆ์ง€๋งŒ, ์–ด๋–ค LoRA ์ฒดํฌํฌ์ธํŠธ๋“  ์ž์œ ๋กญ๊ฒŒ ์‚ฌ์šฉํ•ด ๋ณด์„ธ์š”!
```bash
!wget https://civitai.com/api/download/models/19998 -O howls_moving_castle.safetensors
```
๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํŒŒ์ดํ”„๋ผ์ธ์— LoRA ์ฒดํฌํฌ์ธํŠธ๋ฅผ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค:
```py
pipeline.load_lora_weights(".", weight_name="howls_moving_castle.safetensors")
```
์ด์ œ ํŒŒ์ดํ”„๋ผ์ธ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:
```py
prompt = "masterpiece, illustration, ultra-detailed, cityscape, san francisco, golden gate bridge, california, bay area, in the snow, beautiful detailed starry sky"
negative_prompt = "lowres, cropped, worst quality, low quality, normal quality, artifacts, signature, watermark, username, blurry, more than one bridge, bad architecture"
images = pipeline(
prompt=prompt,
negative_prompt=negative_prompt,
width=512,
height=512,
num_inference_steps=25,
num_images_per_prompt=4,
generator=torch.manual_seed(0),
).images
```
๋งˆ์ง€๋ง‰์œผ๋กœ, ๋””์Šคํ”Œ๋ ˆ์ด์— ์ด๋ฏธ์ง€๋ฅผ ํ‘œ์‹œํ•˜๋Š” ํ—ฌํผ ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค:
```py
from PIL import Image
def image_grid(imgs, rows=2, cols=2):
w, h = imgs[0].size
grid = Image.new("RGB", size=(cols * w, rows * h))
for i, img in enumerate(imgs):
grid.paste(img, box=(i % cols * w, i // cols * h))
return grid
image_grid(images)
```
<div class="flex justify-center">
<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/a1111-lora-sf.png" />
</div>