# 개요

🤗 Diffusers는 자체 diffusion 모델을 학습할 수 있도록 다양한 학습 스크립트를 제공합니다. 모든 학습 스크립트는 [diffusers/examples](https://github.com/huggingface/diffusers/tree/main/examples)에서 찾을 수 있습니다.

각 학습 스크립트는 다음과 같습니다:

- **자기 완결형**: 학습 스크립트는 로컬 파일에 의존하지 않으며, 스크립트 실행에 필요한 모든 패키지는 `requirements.txt` 파일에서 설치됩니다.
- **손쉽게 조정 가능**: 학습 스크립트는 특정 작업을 위해 diffusion 모델을 학습하는 방법을 보여주는 예시이며, 모든 학습 시나리오에서 바로 사용할 수 없습니다. 사용자의 특정 사용 사례에 맞게 학습 스크립트를 수정해야 할 가능성이 높습니다. 이를 돕기 위해 데이터 전처리 코드와 학습 루프를 완전히 공개하여 사용자가 직접 수정할 수 있도록 했습니다.
- **입문자 친화적**: 학습 스크립트는 최신 최첨단 기법을 포함하여 가장 경쟁력 있는 결과를 내는 것보다는, 입문자가 이해하기 쉽고 접근하기 쉽도록 설계되었습니다. 너무 복잡하다고 판단되는 학습 기법은 의도적으로 제외됩니다.
- **단일 목적**: 각 학습 스크립트는 가독성과 이해도를 높이기 위해 오직 하나의 작업만을 수행하도록 명시적으로 설계되어 있습니다.

현재 제공되는 학습 스크립트 목록은 다음과 같습니다:

| 학습 | SDXL 지원 | LoRA 지원 |
|---|---|---|
| [무조건적 이미지 생성](https://github.com/huggingface/diffusers/tree/main/examples/unconditional_image_generation) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/training_example.ipynb) |  |  |
| [텍스트-이미지](https://github.com/huggingface/diffusers/tree/main/examples/text_to_image) | 👍 | 👍 |
| [텍스추얼 인버전](https://github.com/huggingface/diffusers/tree/main/examples/textual_inversion) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/sd_textual_inversion_training.ipynb) |  |  |
| [DreamBooth](https://github.com/huggingface/diffusers/tree/main/examples/dreambooth) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/sd_dreambooth_training.ipynb) | 👍 | 👍 |
| [ControlNet](https://github.com/huggingface/diffusers/tree/main/examples/controlnet) | 👍 |  |
| [InstructPix2Pix](https://github.com/huggingface/diffusers/tree/main/examples/instruct_pix2pix) | 👍 |  |
| [커스텀 디퓨전](https://github.com/huggingface/diffusers/tree/main/examples/custom_diffusion) |  |  |
| [T2I-Adapters](https://github.com/huggingface/diffusers/tree/main/examples/t2i_adapter) | 👍 |  |
| [Kandinsky 2.2](https://github.com/huggingface/diffusers/tree/main/examples/kandinsky2_2/text_to_image) |  | 👍 |

이 예제들은 **적극적으로** 유지 관리되고 있으므로, 예상대로 작동하지 않는 경우 이슈를 열어 주시기 바랍니다. 다른 학습 예제가 포함되어야 한다고 생각하신다면, [Feature Request](https://github.com/huggingface/diffusers/issues/new?assignees=&labels=&template=feature_request.md&title=)를 시작하여 기능 아이디어를 논의하고, 독립적이며, 쉽게 수정할 수 있으며, 초보자에게 친화적이며, 단일 목적이라는 우리의 기준을 충족하는지 확인해 보시기 바랍니다.

## 설치

새 가상 환경에서 소스에서 라이브러리를 설치하여 최신 버전의 예제 스크립트를 성공적으로 실행할 수 있는지 확인하세요:

```bash
git clone https://github.com/huggingface/diffusers
cd diffusers
pip install .
```

이후 학습 스크립트 폴더(예: [DreamBooth](https://github.com/huggingface/diffusers/tree/main/examples/dreambooth))로 이동하여 `requirements.txt` 파일을 설치합니다. 일부 학습 스크립트는 SDXL 또는 LoRA를 위한 전용 요구 사항 파일이 있습니다. 이러한 스크립트 중 하나를 사용하는 경우, 해당 스크립트에 대응하는 요구 사항 파일을 설치했는지 확인하세요.

```bash
cd examples/dreambooth
pip install -r requirements.txt
# to train SDXL with DreamBooth
pip install -r requirements_sdxl.txt
```

학습 속도를 높이고 메모리 사용량을 줄이기 위해 다음을 권장합니다:

- PyTorch 2.0 이상을 사용하여 학습 중에 [scaled dot product attention](../optimization/fp16#scaled-dot-product-attention)을 자동으로 사용하도록 설정합니다(학습 코드를 수정할 필요가 없습니다).
- 메모리 효율적인 어텐션을 활성화하기 위해 [xFormers](../optimization/attention_backends) 설치

