danielpikl commited on
Commit
af7c068
1 Parent(s): 886ebeb

Add stable diffusion weights

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .github/ISSUE_TEMPLATE/bug-report.yml +36 -0
  2. .github/ISSUE_TEMPLATE/config.yml +4 -0
  3. .github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. .github/ISSUE_TEMPLATE/feedback.md +12 -0
  5. .github/ISSUE_TEMPLATE/new-model-addition.yml +31 -0
  6. .github/actions/setup-miniconda/action.yml +146 -0
  7. .github/workflows/build_docker_images.yml +50 -0
  8. .github/workflows/build_documentation.yml +17 -0
  9. .github/workflows/build_pr_documentation.yml +16 -0
  10. .github/workflows/delete_doc_comment.yml +13 -0
  11. .github/workflows/pr_quality.yml +50 -0
  12. .github/workflows/pr_tests.yml +150 -0
  13. .github/workflows/push_tests.yml +154 -0
  14. .github/workflows/stale.yml +27 -0
  15. .github/workflows/typos.yml +14 -0
  16. .gitignore +168 -0
  17. CODE_OF_CONDUCT.md +129 -0
  18. CONTRIBUTING.md +294 -0
  19. LICENSE +201 -0
  20. MANIFEST.in +2 -0
  21. Makefile +96 -0
  22. README.md +492 -3
  23. _typos.toml +13 -0
  24. docker/diffusers-flax-cpu/Dockerfile +42 -0
  25. docker/diffusers-flax-tpu/Dockerfile +44 -0
  26. docker/diffusers-onnxruntime-cpu/Dockerfile +42 -0
  27. docker/diffusers-onnxruntime-cuda/Dockerfile +42 -0
  28. docker/diffusers-pytorch-cpu/Dockerfile +41 -0
  29. docker/diffusers-pytorch-cuda/Dockerfile +41 -0
  30. docs/source/_toctree.yml +122 -0
  31. docs/source/api/configuration.mdx +23 -0
  32. docs/source/api/diffusion_pipeline.mdx +42 -0
  33. docs/source/api/experimental/rl.mdx +15 -0
  34. docs/source/api/logging.mdx +98 -0
  35. docs/source/api/models.mdx +77 -0
  36. docs/source/api/outputs.mdx +55 -0
  37. docs/source/api/pipelines/alt_diffusion.mdx +83 -0
  38. docs/source/api/pipelines/cycle_diffusion.mdx +99 -0
  39. docs/source/api/pipelines/dance_diffusion.mdx +33 -0
  40. docs/source/api/pipelines/ddim.mdx +35 -0
  41. docs/source/api/pipelines/ddpm.mdx +36 -0
  42. docs/source/api/pipelines/latent_diffusion.mdx +47 -0
  43. docs/source/api/pipelines/latent_diffusion_uncond.mdx +41 -0
  44. docs/source/api/pipelines/overview.mdx +191 -0
  45. docs/source/api/pipelines/pndm.mdx +35 -0
  46. docs/source/api/pipelines/repaint.mdx +77 -0
  47. docs/source/api/pipelines/score_sde_ve.mdx +36 -0
  48. docs/source/api/pipelines/stable_diffusion.mdx +90 -0
  49. docs/source/api/pipelines/stochastic_karras_ve.mdx +35 -0
  50. docs/source/api/pipelines/vq_diffusion.mdx +34 -0
.github/ISSUE_TEMPLATE/bug-report.yml ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "\U0001F41B Bug Report"
2
+ description: Report a bug on diffusers
3
+ labels: [ "bug" ]
4
+ body:
5
+ - type: markdown
6
+ attributes:
7
+ value: |
8
+ Thanks for taking the time to fill out this bug report!
9
+ - type: textarea
10
+ id: bug-description
11
+ attributes:
12
+ label: Describe the bug
13
+ description: A clear and concise description of what the bug is. If you intend to submit a pull request for this issue, tell us in the description. Thanks!
14
+ placeholder: Bug description
15
+ validations:
16
+ required: true
17
+ - type: textarea
18
+ id: reproduction
19
+ attributes:
20
+ label: Reproduction
21
+ description: Please provide a minimal reproducible code which we can copy/paste and reproduce the issue.
22
+ placeholder: Reproduction
23
+ - type: textarea
24
+ id: logs
25
+ attributes:
26
+ label: Logs
27
+ description: "Please include the Python logs if you can."
28
+ render: shell
29
+ - type: textarea
30
+ id: system-info
31
+ attributes:
32
+ label: System Info
33
+ description: Please share your system info with us. You can run the command `diffusers-cli env` and copy-paste its output below.
34
+ placeholder: diffusers version, platform, python version, ...
35
+ validations:
36
+ required: true
.github/ISSUE_TEMPLATE/config.yml ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ contact_links:
2
+ - name: Blank issue
3
+ url: https://github.com/huggingface/diffusers/issues/new
4
+ about: General usage questions and community discussions
.github/ISSUE_TEMPLATE/feature_request.md ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: "\U0001F680 Feature request"
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
.github/ISSUE_TEMPLATE/feedback.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ name: "💬 Feedback about API Design"
3
+ about: Give feedback about the current API design
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **What API design would you like to have changed or added to the library? Why?**
11
+
12
+ **What use case would this enable or better enable? Can you give us a code example?**
.github/ISSUE_TEMPLATE/new-model-addition.yml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: "\U0001F31F New model/pipeline/scheduler addition"
2
+ description: Submit a proposal/request to implement a new diffusion model / pipeline / scheduler
3
+ labels: [ "New model/pipeline/scheduler" ]
4
+
5
+ body:
6
+ - type: textarea
7
+ id: description-request
8
+ validations:
9
+ required: true
10
+ attributes:
11
+ label: Model/Pipeline/Scheduler description
12
+ description: |
13
+ Put any and all important information relative to the model/pipeline/scheduler
14
+
15
+ - type: checkboxes
16
+ id: information-tasks
17
+ attributes:
18
+ label: Open source status
19
+ description: |
20
+ Please note that if the model implementation isn't available or if the weights aren't open-source, we are less likely to implement it in `diffusers`.
21
+ options:
22
+ - label: "The model implementation is available"
23
+ - label: "The model weights are available (Only relevant if addition is not a scheduler)."
24
+
25
+ - type: textarea
26
+ id: additional-info
27
+ attributes:
28
+ label: Provide useful links for the implementation
29
+ description: |
30
+ Please provide information regarding the implementation, the weights, and the authors.
31
+ Please mention the authors by @gh-username if you're aware of their usernames.
.github/actions/setup-miniconda/action.yml ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Set up conda environment for testing
2
+
3
+ description: Sets up miniconda in your ${RUNNER_TEMP} environment and gives you the ${CONDA_RUN} environment variable so you don't have to worry about polluting non-empeheral runners anymore
4
+
5
+ inputs:
6
+ python-version:
7
+ description: If set to any value, dont use sudo to clean the workspace
8
+ required: false
9
+ type: string
10
+ default: "3.9"
11
+ miniconda-version:
12
+ description: Miniconda version to install
13
+ required: false
14
+ type: string
15
+ default: "4.12.0"
16
+ environment-file:
17
+ description: Environment file to install dependencies from
18
+ required: false
19
+ type: string
20
+ default: ""
21
+
22
+ runs:
23
+ using: composite
24
+ steps:
25
+ # Use the same trick from https://github.com/marketplace/actions/setup-miniconda
26
+ # to refresh the cache daily. This is kind of optional though
27
+ - name: Get date
28
+ id: get-date
29
+ shell: bash
30
+ run: echo "::set-output name=today::$(/bin/date -u '+%Y%m%d')d"
31
+ - name: Setup miniconda cache
32
+ id: miniconda-cache
33
+ uses: actions/cache@v2
34
+ with:
35
+ path: ${{ runner.temp }}/miniconda
36
+ key: miniconda-${{ runner.os }}-${{ runner.arch }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.today }}
37
+ - name: Install miniconda (${{ inputs.miniconda-version }})
38
+ if: steps.miniconda-cache.outputs.cache-hit != 'true'
39
+ env:
40
+ MINICONDA_VERSION: ${{ inputs.miniconda-version }}
41
+ shell: bash -l {0}
42
+ run: |
43
+ MINICONDA_INSTALL_PATH="${RUNNER_TEMP}/miniconda"
44
+ mkdir -p "${MINICONDA_INSTALL_PATH}"
45
+ case ${RUNNER_OS}-${RUNNER_ARCH} in
46
+ Linux-X64)
47
+ MINICONDA_ARCH="Linux-x86_64"
48
+ ;;
49
+ macOS-ARM64)
50
+ MINICONDA_ARCH="MacOSX-arm64"
51
+ ;;
52
+ macOS-X64)
53
+ MINICONDA_ARCH="MacOSX-x86_64"
54
+ ;;
55
+ *)
56
+ echo "::error::Platform ${RUNNER_OS}-${RUNNER_ARCH} currently unsupported using this action"
57
+ exit 1
58
+ ;;
59
+ esac
60
+ MINICONDA_URL="https://repo.anaconda.com/miniconda/Miniconda3-py39_${MINICONDA_VERSION}-${MINICONDA_ARCH}.sh"
61
+ curl -fsSL "${MINICONDA_URL}" -o "${MINICONDA_INSTALL_PATH}/miniconda.sh"
62
+ bash "${MINICONDA_INSTALL_PATH}/miniconda.sh" -b -u -p "${MINICONDA_INSTALL_PATH}"
63
+ rm -rf "${MINICONDA_INSTALL_PATH}/miniconda.sh"
64
+ - name: Update GitHub path to include miniconda install
65
+ shell: bash
66
+ run: |
67
+ MINICONDA_INSTALL_PATH="${RUNNER_TEMP}/miniconda"
68
+ echo "${MINICONDA_INSTALL_PATH}/bin" >> $GITHUB_PATH
69
+ - name: Setup miniconda env cache (with env file)
70
+ id: miniconda-env-cache-env-file
71
+ if: ${{ runner.os }} == 'macOS' && ${{ inputs.environment-file }} != ''
72
+ uses: actions/cache@v2
73
+ with:
74
+ path: ${{ runner.temp }}/conda-python-${{ inputs.python-version }}
75
+ key: miniconda-env-${{ runner.os }}-${{ runner.arch }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.today }}-${{ hashFiles(inputs.environment-file) }}
76
+ - name: Setup miniconda env cache (without env file)
77
+ id: miniconda-env-cache
78
+ if: ${{ runner.os }} == 'macOS' && ${{ inputs.environment-file }} == ''
79
+ uses: actions/cache@v2
80
+ with:
81
+ path: ${{ runner.temp }}/conda-python-${{ inputs.python-version }}
82
+ key: miniconda-env-${{ runner.os }}-${{ runner.arch }}-${{ inputs.python-version }}-${{ steps.get-date.outputs.today }}
83
+ - name: Setup conda environment with python (v${{ inputs.python-version }})
84
+ if: steps.miniconda-env-cache-env-file.outputs.cache-hit != 'true' && steps.miniconda-env-cache.outputs.cache-hit != 'true'
85
+ shell: bash
86
+ env:
87
+ PYTHON_VERSION: ${{ inputs.python-version }}
88
+ ENV_FILE: ${{ inputs.environment-file }}
89
+ run: |
90
+ CONDA_BASE_ENV="${RUNNER_TEMP}/conda-python-${PYTHON_VERSION}"
91
+ ENV_FILE_FLAG=""
92
+ if [[ -f "${ENV_FILE}" ]]; then
93
+ ENV_FILE_FLAG="--file ${ENV_FILE}"
94
+ elif [[ -n "${ENV_FILE}" ]]; then
95
+ echo "::warning::Specified env file (${ENV_FILE}) not found, not going to include it"
96
+ fi
97
+ conda create \
98
+ --yes \
99
+ --prefix "${CONDA_BASE_ENV}" \
100
+ "python=${PYTHON_VERSION}" \
101
+ ${ENV_FILE_FLAG} \
102
+ cmake=3.22 \
103
+ conda-build=3.21 \
104
+ ninja=1.10 \
105
+ pkg-config=0.29 \
106
+ wheel=0.37
107
+ - name: Clone the base conda environment and update GitHub env
108
+ shell: bash
109
+ env:
110
+ PYTHON_VERSION: ${{ inputs.python-version }}
111
+ CONDA_BASE_ENV: ${{ runner.temp }}/conda-python-${{ inputs.python-version }}
112
+ run: |
113
+ CONDA_ENV="${RUNNER_TEMP}/conda_environment_${GITHUB_RUN_ID}"
114
+ conda create \
115
+ --yes \
116
+ --prefix "${CONDA_ENV}" \
117
+ --clone "${CONDA_BASE_ENV}"
118
+ # TODO: conda-build could not be cloned because it hardcodes the path, so it
119
+ # could not be cached
120
+ conda install --yes -p ${CONDA_ENV} conda-build=3.21
121
+ echo "CONDA_ENV=${CONDA_ENV}" >> "${GITHUB_ENV}"
122
+ echo "CONDA_RUN=conda run -p ${CONDA_ENV} --no-capture-output" >> "${GITHUB_ENV}"
123
+ echo "CONDA_BUILD=conda run -p ${CONDA_ENV} conda-build" >> "${GITHUB_ENV}"
124
+ echo "CONDA_INSTALL=conda install -p ${CONDA_ENV}" >> "${GITHUB_ENV}"
125
+ - name: Get disk space usage and throw an error for low disk space
126
+ shell: bash
127
+ run: |
128
+ echo "Print the available disk space for manual inspection"
129
+ df -h
130
+ # Set the minimum requirement space to 4GB
131
+ MINIMUM_AVAILABLE_SPACE_IN_GB=4
132
+ MINIMUM_AVAILABLE_SPACE_IN_KB=$(($MINIMUM_AVAILABLE_SPACE_IN_GB * 1024 * 1024))
133
+ # Use KB to avoid floating point warning like 3.1GB
134
+ df -k | tr -s ' ' | cut -d' ' -f 4,9 | while read -r LINE;
135
+ do
136
+ AVAIL=$(echo $LINE | cut -f1 -d' ')
137
+ MOUNT=$(echo $LINE | cut -f2 -d' ')
138
+ if [ "$MOUNT" = "/" ]; then
139
+ if [ "$AVAIL" -lt "$MINIMUM_AVAILABLE_SPACE_IN_KB" ]; then
140
+ echo "There is only ${AVAIL}KB free space left in $MOUNT, which is less than the minimum requirement of ${MINIMUM_AVAILABLE_SPACE_IN_KB}KB. Please help create an issue to PyTorch Release Engineering via https://github.com/pytorch/test-infra/issues and provide the link to the workflow run."
141
+ exit 1;
142
+ else
143
+ echo "There is ${AVAIL}KB free space left in $MOUNT, continue"
144
+ fi
145
+ fi
146
+ done
.github/workflows/build_docker_images.yml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build Docker images (nightly)
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ schedule:
6
+ - cron: "0 0 * * *" # every day at midnight
7
+
8
+ concurrency:
9
+ group: docker-image-builds
10
+ cancel-in-progress: false
11
+
12
+ env:
13
+ REGISTRY: diffusers
14
+
15
+ jobs:
16
+ build-docker-images:
17
+ runs-on: ubuntu-latest
18
+
19
+ permissions:
20
+ contents: read
21
+ packages: write
22
+
23
+ strategy:
24
+ fail-fast: false
25
+ matrix:
26
+ image-name:
27
+ - diffusers-pytorch-cpu
28
+ - diffusers-pytorch-cuda
29
+ - diffusers-flax-cpu
30
+ - diffusers-flax-tpu
31
+ - diffusers-onnxruntime-cpu
32
+ - diffusers-onnxruntime-cuda
33
+
34
+ steps:
35
+ - name: Checkout repository
36
+ uses: actions/checkout@v3
37
+
38
+ - name: Login to Docker Hub
39
+ uses: docker/login-action@v2
40
+ with:
41
+ username: ${{ env.REGISTRY }}
42
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
43
+
44
+ - name: Build and push
45
+ uses: docker/build-push-action@v3
46
+ with:
47
+ no-cache: true
48
+ context: ./docker/${{ matrix.image-name }}
49
+ push: true
50
+ tags: ${{ env.REGISTRY }}/${{ matrix.image-name }}:latest
.github/workflows/build_documentation.yml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build documentation
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - doc-builder*
8
+ - v*-release
9
+
10
+ jobs:
11
+ build:
12
+ uses: huggingface/doc-builder/.github/workflows/build_main_documentation.yml@main
13
+ with:
14
+ commit_sha: ${{ github.sha }}
15
+ package: diffusers
16
+ secrets:
17
+ token: ${{ secrets.HUGGINGFACE_PUSH }}
.github/workflows/build_pr_documentation.yml ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Build PR Documentation
2
+
3
+ on:
4
+ pull_request:
5
+
6
+ concurrency:
7
+ group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
8
+ cancel-in-progress: true
9
+
10
+ jobs:
11
+ build:
12
+ uses: huggingface/doc-builder/.github/workflows/build_pr_documentation.yml@main
13
+ with:
14
+ commit_sha: ${{ github.event.pull_request.head.sha }}
15
+ pr_number: ${{ github.event.number }}
16
+ package: diffusers
.github/workflows/delete_doc_comment.yml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Delete dev documentation
2
+
3
+ on:
4
+ pull_request:
5
+ types: [ closed ]
6
+
7
+
8
+ jobs:
9
+ delete:
10
+ uses: huggingface/doc-builder/.github/workflows/delete_doc_comment.yml@main
11
+ with:
12
+ pr_number: ${{ github.event.number }}
13
+ package: diffusers
.github/workflows/pr_quality.yml ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Run code quality checks
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - main
7
+ push:
8
+ branches:
9
+ - main
10
+
11
+ concurrency:
12
+ group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
13
+ cancel-in-progress: true
14
+
15
+ jobs:
16
+ check_code_quality:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+ - name: Set up Python
21
+ uses: actions/setup-python@v4
22
+ with:
23
+ python-version: "3.7"
24
+ - name: Install dependencies
25
+ run: |
26
+ python -m pip install --upgrade pip
27
+ pip install .[quality]
28
+ - name: Check quality
29
+ run: |
30
+ black --check --preview examples tests src utils scripts
31
+ isort --check-only examples tests src utils scripts
32
+ flake8 examples tests src utils scripts
33
+ doc-builder style src/diffusers docs/source --max_len 119 --check_only --path_to_docs docs/source
34
+
35
+ check_repository_consistency:
36
+ runs-on: ubuntu-latest
37
+ steps:
38
+ - uses: actions/checkout@v3
39
+ - name: Set up Python
40
+ uses: actions/setup-python@v4
41
+ with:
42
+ python-version: "3.7"
43
+ - name: Install dependencies
44
+ run: |
45
+ python -m pip install --upgrade pip
46
+ pip install .[quality]
47
+ - name: Check quality
48
+ run: |
49
+ python utils/check_copies.py
50
+ python utils/check_dummies.py
.github/workflows/pr_tests.yml ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Run fast tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - main
7
+
8
+ concurrency:
9
+ group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
10
+ cancel-in-progress: true
11
+
12
+ env:
13
+ DIFFUSERS_IS_CI: yes
14
+ OMP_NUM_THREADS: 4
15
+ MKL_NUM_THREADS: 4
16
+ PYTEST_TIMEOUT: 60
17
+ MPS_TORCH_VERSION: 1.13.0
18
+
19
+ jobs:
20
+ run_fast_tests:
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ config:
25
+ - name: Fast PyTorch CPU tests on Ubuntu
26
+ framework: pytorch
27
+ runner: docker-cpu
28
+ image: diffusers/diffusers-pytorch-cpu
29
+ report: torch_cpu
30
+ - name: Fast Flax CPU tests on Ubuntu
31
+ framework: flax
32
+ runner: docker-cpu
33
+ image: diffusers/diffusers-flax-cpu
34
+ report: flax_cpu
35
+ - name: Fast ONNXRuntime CPU tests on Ubuntu
36
+ framework: onnxruntime
37
+ runner: docker-cpu
38
+ image: diffusers/diffusers-onnxruntime-cpu
39
+ report: onnx_cpu
40
+
41
+ name: ${{ matrix.config.name }}
42
+
43
+ runs-on: ${{ matrix.config.runner }}
44
+
45
+ container:
46
+ image: ${{ matrix.config.image }}
47
+ options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/
48
+
49
+ defaults:
50
+ run:
51
+ shell: bash
52
+
53
+ steps:
54
+ - name: Checkout diffusers
55
+ uses: actions/checkout@v3
56
+ with:
57
+ fetch-depth: 2
58
+
59
+ - name: Install dependencies
60
+ run: |
61
+ python -m pip install -e .[quality,test]
62
+ python -m pip install git+https://github.com/huggingface/accelerate
63
+
64
+ - name: Environment
65
+ run: |
66
+ python utils/print_env.py
67
+
68
+ - name: Run fast PyTorch CPU tests
69
+ if: ${{ matrix.config.framework == 'pytorch' }}
70
+ run: |
71
+ python -m pytest -n 2 --max-worker-restart=0 --dist=loadfile \
72
+ -s -v -k "not Flax and not Onnx" \
73
+ --make-reports=tests_${{ matrix.config.report }} \
74
+ tests/
75
+
76
+ - name: Run fast Flax TPU tests
77
+ if: ${{ matrix.config.framework == 'flax' }}
78
+ run: |
79
+ python -m pytest -n 2 --max-worker-restart=0 --dist=loadfile \
80
+ -s -v -k "Flax" \
81
+ --make-reports=tests_${{ matrix.config.report }} \
82
+ tests/
83
+
84
+ - name: Run fast ONNXRuntime CPU tests
85
+ if: ${{ matrix.config.framework == 'onnxruntime' }}
86
+ run: |
87
+ python -m pytest -n 2 --max-worker-restart=0 --dist=loadfile \
88
+ -s -v -k "Onnx" \
89
+ --make-reports=tests_${{ matrix.config.report }} \
90
+ tests/
91
+
92
+ - name: Failure short reports
93
+ if: ${{ failure() }}
94
+ run: cat reports/tests_${{ matrix.config.report }}_failures_short.txt
95
+
96
+ - name: Test suite reports artifacts
97
+ if: ${{ always() }}
98
+ uses: actions/upload-artifact@v2
99
+ with:
100
+ name: pr_${{ matrix.config.report }}_test_reports
101
+ path: reports
102
+
103
+ run_fast_tests_apple_m1:
104
+ name: Fast PyTorch MPS tests on MacOS
105
+ runs-on: [ self-hosted, apple-m1 ]
106
+
107
+ steps:
108
+ - name: Checkout diffusers
109
+ uses: actions/checkout@v3
110
+ with:
111
+ fetch-depth: 2
112
+
113
+ - name: Clean checkout
114
+ shell: arch -arch arm64 bash {0}
115
+ run: |
116
+ git clean -fxd
117
+
118
+ - name: Setup miniconda
119
+ uses: ./.github/actions/setup-miniconda
120
+ with:
121
+ python-version: 3.9
122
+
123
+ - name: Install dependencies
124
+ shell: arch -arch arm64 bash {0}
125
+ run: |
126
+ ${CONDA_RUN} python -m pip install --upgrade pip
127
+ ${CONDA_RUN} python -m pip install -e .[quality,test]
128
+ ${CONDA_RUN} python -m pip install --pre torch==${MPS_TORCH_VERSION} --extra-index-url https://download.pytorch.org/whl/test/cpu
129
+ ${CONDA_RUN} python -m pip install git+https://github.com/huggingface/accelerate
130
+
131
+ - name: Environment
132
+ shell: arch -arch arm64 bash {0}
133
+ run: |
134
+ ${CONDA_RUN} python utils/print_env.py
135
+
136
+ - name: Run fast PyTorch tests on M1 (MPS)
137
+ shell: arch -arch arm64 bash {0}
138
+ run: |
139
+ ${CONDA_RUN} python -m pytest -n 0 -s -v --make-reports=tests_torch_mps tests/
140
+
141
+ - name: Failure short reports
142
+ if: ${{ failure() }}
143
+ run: cat reports/tests_torch_mps_failures_short.txt
144
+
145
+ - name: Test suite reports artifacts
146
+ if: ${{ always() }}
147
+ uses: actions/upload-artifact@v2
148
+ with:
149
+ name: pr_torch_mps_test_reports
150
+ path: reports
.github/workflows/push_tests.yml ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Run all tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ env:
9
+ DIFFUSERS_IS_CI: yes
10
+ HF_HOME: /mnt/cache
11
+ OMP_NUM_THREADS: 8
12
+ MKL_NUM_THREADS: 8
13
+ PYTEST_TIMEOUT: 1000
14
+ RUN_SLOW: yes
15
+
16
+ jobs:
17
+ run_slow_tests:
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ config:
22
+ - name: Slow PyTorch CUDA tests on Ubuntu
23
+ framework: pytorch
24
+ runner: docker-gpu
25
+ image: diffusers/diffusers-pytorch-cuda
26
+ report: torch_cuda
27
+ - name: Slow Flax TPU tests on Ubuntu
28
+ framework: flax
29
+ runner: docker-tpu
30
+ image: diffusers/diffusers-flax-tpu
31
+ report: flax_tpu
32
+ - name: Slow ONNXRuntime CUDA tests on Ubuntu
33
+ framework: onnxruntime
34
+ runner: docker-gpu
35
+ image: diffusers/diffusers-onnxruntime-cuda
36
+ report: onnx_cuda
37
+
38
+ name: ${{ matrix.config.name }}
39
+
40
+ runs-on: ${{ matrix.config.runner }}
41
+
42
+ container:
43
+ image: ${{ matrix.config.image }}
44
+ options: --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/ ${{ matrix.config.runner == 'docker-tpu' && '--privileged' || '--gpus 0'}}
45
+
46
+ defaults:
47
+ run:
48
+ shell: bash
49
+
50
+ steps:
51
+ - name: Checkout diffusers
52
+ uses: actions/checkout@v3
53
+ with:
54
+ fetch-depth: 2
55
+
56
+ - name: NVIDIA-SMI
57
+ if : ${{ matrix.config.runner == 'docker-gpu' }}
58
+ run: |
59
+ nvidia-smi
60
+
61
+ - name: Install dependencies
62
+ run: |
63
+ python -m pip install -e .[quality,test]
64
+ python -m pip install git+https://github.com/huggingface/accelerate
65
+
66
+ - name: Environment
67
+ run: |
68
+ python utils/print_env.py
69
+
70
+ - name: Run slow PyTorch CUDA tests
71
+ if: ${{ matrix.config.framework == 'pytorch' }}
72
+ env:
73
+ HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN }}
74
+ run: |
75
+ python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
76
+ -s -v -k "not Flax and not Onnx" \
77
+ --make-reports=tests_${{ matrix.config.report }} \
78
+ tests/
79
+
80
+ - name: Run slow Flax TPU tests
81
+ if: ${{ matrix.config.framework == 'flax' }}
82
+ env:
83
+ HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN }}
84
+ run: |
85
+ python -m pytest -n 0 \
86
+ -s -v -k "Flax" \
87
+ --make-reports=tests_${{ matrix.config.report }} \
88
+ tests/
89
+
90
+ - name: Run slow ONNXRuntime CUDA tests
91
+ if: ${{ matrix.config.framework == 'onnxruntime' }}
92
+ env:
93
+ HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN }}
94
+ run: |
95
+ python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile \
96
+ -s -v -k "Onnx" \
97
+ --make-reports=tests_${{ matrix.config.report }} \
98
+ tests/
99
+
100
+ - name: Failure short reports
101
+ if: ${{ failure() }}
102
+ run: cat reports/tests_${{ matrix.config.report }}_failures_short.txt
103
+
104
+ - name: Test suite reports artifacts
105
+ if: ${{ always() }}
106
+ uses: actions/upload-artifact@v2
107
+ with:
108
+ name: ${{ matrix.config.report }}_test_reports
109
+ path: reports
110
+
111
+ run_examples_tests:
112
+ name: Examples PyTorch CUDA tests on Ubuntu
113
+
114
+ runs-on: docker-gpu
115
+
116
+ container:
117
+ image: diffusers/diffusers-pytorch-cuda
118
+ options: --gpus 0 --shm-size "16gb" --ipc host -v /mnt/hf_cache:/mnt/cache/
119
+
120
+ steps:
121
+ - name: Checkout diffusers
122
+ uses: actions/checkout@v3
123
+ with:
124
+ fetch-depth: 2
125
+
126
+ - name: NVIDIA-SMI
127
+ run: |
128
+ nvidia-smi
129
+
130
+ - name: Install dependencies
131
+ run: |
132
+ python -m pip install -e .[quality,test,training]
133
+ python -m pip install git+https://github.com/huggingface/accelerate
134
+
135
+ - name: Environment
136
+ run: |
137
+ python utils/print_env.py
138
+
139
+ - name: Run example tests on GPU
140
+ env:
141
+ HUGGING_FACE_HUB_TOKEN: ${{ secrets.HUGGING_FACE_HUB_TOKEN }}
142
+ run: |
143
+ python -m pytest -n 1 --max-worker-restart=0 --dist=loadfile -s -v --make-reports=examples_torch_cuda examples/
144
+
145
+ - name: Failure short reports
146
+ if: ${{ failure() }}
147
+ run: cat reports/examples_torch_cuda_failures_short.txt
148
+
149
+ - name: Test suite reports artifacts
150
+ if: ${{ always() }}
151
+ uses: actions/upload-artifact@v2
152
+ with:
153
+ name: examples_test_reports
154
+ path: reports
.github/workflows/stale.yml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Stale Bot
2
+
3
+ on:
4
+ schedule:
5
+ - cron: "0 15 * * *"
6
+
7
+ jobs:
8
+ close_stale_issues:
9
+ name: Close Stale Issues
10
+ if: github.repository == 'huggingface/diffusers'
11
+ runs-on: ubuntu-latest
12
+ env:
13
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+
17
+ - name: Setup Python
18
+ uses: actions/setup-python@v1
19
+ with:
20
+ python-version: 3.7
21
+
22
+ - name: Install requirements
23
+ run: |
24
+ pip install PyGithub
25
+ - name: Close stale issues
26
+ run: |
27
+ python utils/stale.py
.github/workflows/typos.yml ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Check typos
2
+
3
+ on:
4
+ workflow_dispatch:
5
+
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v3
12
+
13
+ - name: typos-action
14
+ uses: crate-ci/[email protected]
.gitignore ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Initially taken from Github's Python gitignore file
2
+
3
+ # Byte-compiled / optimized / DLL files
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+
8
+ # C extensions
9
+ *.so
10
+
11
+ # tests and logs
12
+ tests/fixtures/cached_*_text.txt
13
+ logs/
14
+ lightning_logs/
15
+ lang_code_data/
16
+
17
+ # Distribution / packaging
18
+ .Python
19
+ build/
20
+ develop-eggs/
21
+ dist/
22
+ downloads/
23
+ eggs/
24
+ .eggs/
25
+ lib/
26
+ lib64/
27
+ parts/
28
+ sdist/
29
+ var/
30
+ wheels/
31
+ *.egg-info/
32
+ .installed.cfg
33
+ *.egg
34
+ MANIFEST
35
+
36
+ # PyInstaller
37
+ # Usually these files are written by a python script from a template
38
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
39
+ *.manifest
40
+ *.spec
41
+
42
+ # Installer logs
43
+ pip-log.txt
44
+ pip-delete-this-directory.txt
45
+
46
+ # Unit test / coverage reports
47
+ htmlcov/
48
+ .tox/
49
+ .nox/
50
+ .coverage
51
+ .coverage.*
52
+ .cache
53
+ nosetests.xml
54
+ coverage.xml
55
+ *.cover
56
+ .hypothesis/
57
+ .pytest_cache/
58
+
59
+ # Translations
60
+ *.mo
61
+ *.pot
62
+
63
+ # Django stuff:
64
+ *.log
65
+ local_settings.py
66
+ db.sqlite3
67
+
68
+ # Flask stuff:
69
+ instance/
70
+ .webassets-cache
71
+
72
+ # Scrapy stuff:
73
+ .scrapy
74
+
75
+ # Sphinx documentation
76
+ docs/_build/
77
+
78
+ # PyBuilder
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ .python-version
90
+
91
+ # celery beat schedule file
92
+ celerybeat-schedule
93
+
94
+ # SageMath parsed files
95
+ *.sage.py
96
+
97
+ # Environments
98
+ .env
99
+ .venv
100
+ env/
101
+ venv/
102
+ ENV/
103
+ env.bak/
104
+ venv.bak/
105
+
106
+ # Spyder project settings
107
+ .spyderproject
108
+ .spyproject
109
+
110
+ # Rope project settings
111
+ .ropeproject
112
+
113
+ # mkdocs documentation
114
+ /site
115
+
116
+ # mypy
117
+ .mypy_cache/
118
+ .dmypy.json
119
+ dmypy.json
120
+
121
+ # Pyre type checker
122
+ .pyre/
123
+
124
+ # vscode
125
+ .vs
126
+ .vscode
127
+
128
+ # Pycharm
129
+ .idea
130
+
131
+ # TF code
132
+ tensorflow_code
133
+
134
+ # Models
135
+ proc_data
136
+
137
+ # examples
138
+ runs
139
+ /runs_old
140
+ /wandb
141
+ /examples/runs
142
+ /examples/**/*.args
143
+ /examples/rag/sweep
144
+
145
+ # data
146
+ /data
147
+ serialization_dir
148
+
149
+ # emacs
150
+ *.*~
151
+ debug.env
152
+
153
+ # vim
154
+ .*.swp
155
+
156
+ #ctags
157
+ tags
158
+
159
+ # pre-commit
160
+ .pre-commit*
161
+
162
+ # .lock
163
+ *.lock
164
+
165
+ # DS_Store (MacOS)
166
+ .DS_Store
167
+ # RL pipelines may produce mp4 outputs
168
+ *.mp4
CODE_OF_CONDUCT.md ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Contributor Covenant Code of Conduct
3
+
4
+ ## Our Pledge
5
+
6
+ We as members, contributors, and leaders pledge to make participation in our
7
+ community a harassment-free experience for everyone, regardless of age, body
8
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
9
+ identity and expression, level of experience, education, socio-economic status,
10
+ nationality, personal appearance, race, religion, or sexual identity
11
+ and orientation.
12
+
13
+ We pledge to act and interact in ways that contribute to an open, welcoming,
14
+ diverse, inclusive, and healthy community.
15
+
16
+ ## Our Standards
17
+
18
+ Examples of behavior that contributes to a positive environment for our
19
+ community include:
20
+
21
+ * Demonstrating empathy and kindness toward other people
22
+ * Being respectful of differing opinions, viewpoints, and experiences
23
+ * Giving and gracefully accepting constructive feedback
24
+ * Accepting responsibility and apologizing to those affected by our mistakes,
25
+ and learning from the experience
26
+ * Focusing on what is best not just for us as individuals, but for the
27
+ overall community
28
+
29
+ Examples of unacceptable behavior include:
30
+
31
+ * The use of sexualized language or imagery, and sexual attention or
32
+ advances of any kind
33
+ * Trolling, insulting or derogatory comments, and personal or political attacks
34
+ * Public or private harassment
35
+ * Publishing others' private information, such as a physical or email
36
+ address, without their explicit permission
37
+ * Other conduct which could reasonably be considered inappropriate in a
38
+ professional setting
39
+
40
+ ## Enforcement Responsibilities
41
+
42
+ Community leaders are responsible for clarifying and enforcing our standards of
43
+ acceptable behavior and will take appropriate and fair corrective action in
44
+ response to any behavior that they deem inappropriate, threatening, offensive,
45
+ or harmful.
46
+
47
+ Community leaders have the right and responsibility to remove, edit, or reject
48
+ comments, commits, code, wiki edits, issues, and other contributions that are
49
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
50
+ decisions when appropriate.
51
+
52
+ ## Scope
53
+
54
+ This Code of Conduct applies within all community spaces, and also applies when
55
+ an individual is officially representing the community in public spaces.
56
+ Examples of representing our community include using an official e-mail address,
57
+ posting via an official social media account, or acting as an appointed
58
+ representative at an online or offline event.
59
+
60
+ ## Enforcement
61
+
62
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
63
+ reported to the community leaders responsible for enforcement at
64
65
+ All complaints will be reviewed and investigated promptly and fairly.
66
+
67
+ All community leaders are obligated to respect the privacy and security of the
68
+ reporter of any incident.
69
+
70
+ ## Enforcement Guidelines
71
+
72
+ Community leaders will follow these Community Impact Guidelines in determining
73
+ the consequences for any action they deem in violation of this Code of Conduct:
74
+
75
+ ### 1. Correction
76
+
77
+ **Community Impact**: Use of inappropriate language or other behavior deemed
78
+ unprofessional or unwelcome in the community.
79
+
80
+ **Consequence**: A private, written warning from community leaders, providing
81
+ clarity around the nature of the violation and an explanation of why the
82
+ behavior was inappropriate. A public apology may be requested.
83
+
84
+ ### 2. Warning
85
+
86
+ **Community Impact**: A violation through a single incident or series
87
+ of actions.
88
+
89
+ **Consequence**: A warning with consequences for continued behavior. No
90
+ interaction with the people involved, including unsolicited interaction with
91
+ those enforcing the Code of Conduct, for a specified period of time. This
92
+ includes avoiding interactions in community spaces as well as external channels
93
+ like social media. Violating these terms may lead to a temporary or
94
+ permanent ban.
95
+
96
+ ### 3. Temporary Ban
97
+
98
+ **Community Impact**: A serious violation of community standards, including
99
+ sustained inappropriate behavior.
100
+
101
+ **Consequence**: A temporary ban from any sort of interaction or public
102
+ communication with the community for a specified period of time. No public or
103
+ private interaction with the people involved, including unsolicited interaction
104
+ with those enforcing the Code of Conduct, is allowed during this period.
105
+ Violating these terms may lead to a permanent ban.
106
+
107
+ ### 4. Permanent Ban
108
+
109
+ **Community Impact**: Demonstrating a pattern of violation of community
110
+ standards, including sustained inappropriate behavior, harassment of an
111
+ individual, or aggression toward or disparagement of classes of individuals.
112
+
113
+ **Consequence**: A permanent ban from any sort of public interaction within
114
+ the community.
115
+
116
+ ## Attribution
117
+
118
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
119
+ version 2.0, available at
120
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
121
+
122
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
123
+ enforcement ladder](https://github.com/mozilla/diversity).
124
+
125
+ [homepage]: https://www.contributor-covenant.org
126
+
127
+ For answers to common questions about this code of conduct, see the FAQ at
128
+ https://www.contributor-covenant.org/faq. Translations are available at
129
+ https://www.contributor-covenant.org/translations.
CONTRIBUTING.md ADDED
@@ -0,0 +1,294 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!---
2
+ Copyright 2022 The HuggingFace Team. All rights reserved.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ -->
16
+
17
+ # How to contribute to diffusers?
18
+
19
+ Everyone is welcome to contribute, and we value everybody's contribution. Code
20
+ is thus not the only way to help the community. Answering questions, helping
21
+ others, reaching out and improving the documentations are immensely valuable to
22
+ the community.
23
+
24
+ It also helps us if you spread the word: reference the library from blog posts
25
+ on the awesome projects it made possible, shout out on Twitter every time it has
26
+ helped you, or simply star the repo to say "thank you".
27
+
28
+ Whichever way you choose to contribute, please be mindful to respect our
29
+ [code of conduct](https://github.com/huggingface/diffusers/blob/main/CODE_OF_CONDUCT.md).
30
+
31
+ ## You can contribute in so many ways!
32
+
33
+ There are 4 ways you can contribute to diffusers:
34
+ * Fixing outstanding issues with the existing code;
35
+ * Implementing [new diffusion pipelines](https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines#contribution), [new schedulers](https://github.com/huggingface/diffusers/tree/main/src/diffusers/schedulers) or [new models](https://github.com/huggingface/diffusers/tree/main/src/diffusers/models)
36
+ * [Contributing to the examples](https://github.com/huggingface/diffusers/tree/main/examples) or to the documentation;
37
+ * Submitting issues related to bugs or desired new features.
38
+
39
+ In particular there is a special [Good First Issue](https://github.com/huggingface/diffusers/contribute) listing.
40
+ It will give you a list of open Issues that are open to anybody to work on. Just comment in the issue that you'd like to work on it.
41
+ In that same listing you will also find some Issues with `Good Second Issue` label. These are
42
+ typically slightly more complicated than the Issues with just `Good First Issue` label. But if you
43
+ feel you know what you're doing, go for it.
44
+
45
+ *All are equally valuable to the community.*
46
+
47
+ ## Submitting a new issue or feature request
48
+
49
+ Do your best to follow these guidelines when submitting an issue or a feature
50
+ request. It will make it easier for us to come back to you quickly and with good
51
+ feedback.
52
+
53
+ ### Did you find a bug?
54
+
55
+ The 🧨 Diffusers library is robust and reliable thanks to the users who notify us of
56
+ the problems they encounter. So thank you for reporting an issue.
57
+
58
+ First, we would really appreciate it if you could **make sure the bug was not
59
+ already reported** (use the search bar on Github under Issues).
60
+
61
+ ### Do you want to implement a new diffusion pipeline / diffusion model?
62
+
63
+ Awesome! Please provide the following information:
64
+
65
+ * Short description of the diffusion pipeline and link to the paper;
66
+ * Link to the implementation if it is open-source;
67
+ * Link to the model weights if they are available.
68
+
69
+ If you are willing to contribute the model yourself, let us know so we can best
70
+ guide you.
71
+
72
+ ### Do you want a new feature (that is not a model)?
73
+
74
+ A world-class feature request addresses the following points:
75
+
76
+ 1. Motivation first:
77
+ * Is it related to a problem/frustration with the library? If so, please explain
78
+ why. Providing a code snippet that demonstrates the problem is best.
79
+ * Is it related to something you would need for a project? We'd love to hear
80
+ about it!
81
+ * Is it something you worked on and think could benefit the community?
82
+ Awesome! Tell us what problem it solved for you.
83
+ 2. Write a *full paragraph* describing the feature;
84
+ 3. Provide a **code snippet** that demonstrates its future use;
85
+ 4. In case this is related to a paper, please attach a link;
86
+ 5. Attach any additional information (drawings, screenshots, etc.) you think may help.
87
+
88
+ If your issue is well written we're already 80% of the way there by the time you
89
+ post it.
90
+
91
+ ## Start contributing! (Pull Requests)
92
+
93
+ Before writing code, we strongly advise you to search through the existing PRs or
94
+ issues to make sure that nobody is already working on the same thing. If you are
95
+ unsure, it is always a good idea to open an issue to get some feedback.
96
+
97
+ You will need basic `git` proficiency to be able to contribute to
98
+ 🧨 Diffusers. `git` is not the easiest tool to use but it has the greatest
99
+ manual. Type `git --help` in a shell and enjoy. If you prefer books, [Pro
100
+ Git](https://git-scm.com/book/en/v2) is a very good reference.
101
+
102
+ Follow these steps to start contributing ([supported Python versions](https://github.com/huggingface/diffusers/blob/main/setup.py#L426)):
103
+
104
+ 1. Fork the [repository](https://github.com/huggingface/diffusers) by
105
+ clicking on the 'Fork' button on the repository's page. This creates a copy of the code
106
+ under your GitHub user account.
107
+
108
+ 2. Clone your fork to your local disk, and add the base repository as a remote:
109
+
110
+ ```bash
111
+ $ git clone [email protected]:<your Github handle>/diffusers.git
112
+ $ cd diffusers
113
+ $ git remote add upstream https://github.com/huggingface/diffusers.git
114
+ ```
115
+
116
+ 3. Create a new branch to hold your development changes:
117
+
118
+ ```bash
119
+ $ git checkout -b a-descriptive-name-for-my-changes
120
+ ```
121
+
122
+ **Do not** work on the `main` branch.
123
+
124
+ 4. Set up a development environment by running the following command in a virtual environment:
125
+
126
+ ```bash
127
+ $ pip install -e ".[dev]"
128
+ ```
129
+
130
+ (If diffusers was already installed in the virtual environment, remove
131
+ it with `pip uninstall diffusers` before reinstalling it in editable
132
+ mode with the `-e` flag.)
133
+
134
+ To run the full test suite, you might need the additional dependency on `transformers` and `datasets` which requires a separate source
135
+ install:
136
+
137
+ ```bash
138
+ $ git clone https://github.com/huggingface/transformers
139
+ $ cd transformers
140
+ $ pip install -e .
141
+ ```
142
+
143
+ ```bash
144
+ $ git clone https://github.com/huggingface/datasets
145
+ $ cd datasets
146
+ $ pip install -e .
147
+ ```
148
+
149
+ If you have already cloned that repo, you might need to `git pull` to get the most recent changes in the `datasets`
150
+ library.
151
+
152
+ 5. Develop the features on your branch.
153
+
154
+ As you work on the features, you should make sure that the test suite
155
+ passes. You should run the tests impacted by your changes like this:
156
+
157
+ ```bash
158
+ $ pytest tests/<TEST_TO_RUN>.py
159
+ ```
160
+
161
+ You can also run the full suite with the following command, but it takes
162
+ a beefy machine to produce a result in a decent amount of time now that
163
+ Diffusers has grown a lot. Here is the command for it:
164
+
165
+ ```bash
166
+ $ make test
167
+ ```
168
+
169
+ For more information about tests, check out the
170
+ [dedicated documentation](https://huggingface.co/docs/diffusers/testing)
171
+
172
+ 🧨 Diffusers relies on `black` and `isort` to format its source code
173
+ consistently. After you make changes, apply automatic style corrections and code verifications
174
+ that can't be automated in one go with:
175
+
176
+ ```bash
177
+ $ make style
178
+ ```
179
+
180
+ 🧨 Diffusers also uses `flake8` and a few custom scripts to check for coding mistakes. Quality
181
+ control runs in CI, however you can also run the same checks with:
182
+
183
+ ```bash
184
+ $ make quality
185
+ ```
186
+
187
+ Once you're happy with your changes, add changed files using `git add` and
188
+ make a commit with `git commit` to record your changes locally:
189
+
190
+ ```bash
191
+ $ git add modified_file.py
192
+ $ git commit
193
+ ```
194
+
195
+ It is a good idea to sync your copy of the code with the original
196
+ repository regularly. This way you can quickly account for changes:
197
+
198
+ ```bash
199
+ $ git fetch upstream
200
+ $ git rebase upstream/main
201
+ ```
202
+
203
+ Push the changes to your account using:
204
+
205
+ ```bash
206
+ $ git push -u origin a-descriptive-name-for-my-changes
207
+ ```
208
+
209
+ 6. Once you are satisfied (**and the checklist below is happy too**), go to the
210
+ webpage of your fork on GitHub. Click on 'Pull request' to send your changes
211
+ to the project maintainers for review.
212
+
213
+ 7. It's ok if maintainers ask you for changes. It happens to core contributors
214
+ too! So everyone can see the changes in the Pull request, work in your local
215
+ branch and push the changes to your fork. They will automatically appear in
216
+ the pull request.
217
+
218
+
219
+ ### Checklist
220
+
221
+ 1. The title of your pull request should be a summary of its contribution;
222
+ 2. If your pull request addresses an issue, please mention the issue number in
223
+ the pull request description to make sure they are linked (and people
224
+ consulting the issue know you are working on it);
225
+ 3. To indicate a work in progress please prefix the title with `[WIP]`. These
226
+ are useful to avoid duplicated work, and to differentiate it from PRs ready
227
+ to be merged;
228
+ 4. Make sure existing tests pass;
229
+ 5. Add high-coverage tests. No quality testing = no merge.
230
+ - If you are adding new `@slow` tests, make sure they pass using
231
+ `RUN_SLOW=1 python -m pytest tests/test_my_new_model.py`.
232
+ - If you are adding a new tokenizer, write tests, and make sure
233
+ `RUN_SLOW=1 python -m pytest tests/test_tokenization_{your_model_name}.py` passes.
234
+ CircleCI does not run the slow tests, but github actions does every night!
235
+ 6. All public methods must have informative docstrings that work nicely with sphinx. See `modeling_bert.py` for an
236
+ example.
237
+ 7. Due to the rapidly growing repository, it is important to make sure that no files that would significantly weigh down the repository are added. This includes images, videos and other non-text files. We prefer to leverage a hf.co hosted `dataset` like
238
+ the ones hosted on [`hf-internal-testing`](https://huggingface.co/hf-internal-testing) in which to place these files and reference
239
+ them by URL. We recommend putting them in the following dataset: [huggingface/documentation-images](https://huggingface.co/datasets/huggingface/documentation-images).
240
+ If an external contribution, feel free to add the images to your PR and ask a Hugging Face member to migrate your images
241
+ to this dataset.
242
+
243
+ ### Tests
244
+
245
+ An extensive test suite is included to test the library behavior and several examples. Library tests can be found in
246
+ the [tests folder](https://github.com/huggingface/diffusers/tree/main/tests).
247
+
248
+ We like `pytest` and `pytest-xdist` because it's faster. From the root of the
249
+ repository, here's how to run tests with `pytest` for the library:
250
+
251
+ ```bash
252
+ $ python -m pytest -n auto --dist=loadfile -s -v ./tests/
253
+ ```
254
+
255
+ In fact, that's how `make test` is implemented (sans the `pip install` line)!
256
+
257
+ You can specify a smaller set of tests in order to test only the feature
258
+ you're working on.
259
+
260
+ By default, slow tests are skipped. Set the `RUN_SLOW` environment variable to
261
+ `yes` to run them. This will download many gigabytes of models — make sure you
262
+ have enough disk space and a good Internet connection, or a lot of patience!
263
+
264
+ ```bash
265
+ $ RUN_SLOW=yes python -m pytest -n auto --dist=loadfile -s -v ./tests/
266
+ ```
267
+
268
+ This means `unittest` is fully supported. Here's how to run tests with
269
+ `unittest`:
270
+
271
+ ```bash
272
+ $ python -m unittest discover -s tests -t . -v
273
+ $ python -m unittest discover -s examples -t examples -v
274
+ ```
275
+
276
+
277
+ ### Style guide
278
+
279
+ For documentation strings, 🧨 Diffusers follows the [google style](https://google.github.io/styleguide/pyguide.html).
280
+
281
+ **This guide was heavily inspired by the awesome [scikit-learn guide to contributing](https://github.com/scikit-learn/scikit-learn/blob/main/CONTRIBUTING.md).**
282
+
283
+ ### Syncing forked main with upstream (HuggingFace) main
284
+
285
+ To avoid pinging the upstream repository which adds reference notes to each upstream PR and sends unnecessary notifications to the developers involved in these PRs,
286
+ when syncing the main branch of a forked repository, please, follow these steps:
287
+ 1. When possible, avoid syncing with the upstream using a branch and PR on the forked repository. Instead merge directly into the forked main.
288
+ 2. If a PR is absolutely necessary, use the following steps after checking out your branch:
289
+ ```
290
+ $ git checkout -b your-branch-for-syncing
291
+ $ git pull --squash --no-commit upstream main
292
+ $ git commit -m '<your message without GitHub references>'
293
+ $ git push --set-upstream origin your-branch-for-syncing
294
+ ```
LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
MANIFEST.in ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ include LICENSE
2
+ include src/diffusers/utils/model_card_template.md
Makefile ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .PHONY: deps_table_update modified_only_fixup extra_style_checks quality style fixup fix-copies test test-examples
2
+
3
+ # make sure to test the local checkout in scripts and not the pre-installed one (don't use quotes!)
4
+ export PYTHONPATH = src
5
+
6
+ check_dirs := examples scripts src tests utils
7
+
8
+ modified_only_fixup:
9
+ $(eval modified_py_files := $(shell python utils/get_modified_files.py $(check_dirs)))
10
+ @if test -n "$(modified_py_files)"; then \
11
+ echo "Checking/fixing $(modified_py_files)"; \
12
+ black --preview $(modified_py_files); \
13
+ isort $(modified_py_files); \
14
+ flake8 $(modified_py_files); \
15
+ else \
16
+ echo "No library .py files were modified"; \
17
+ fi
18
+
19
+ # Update src/diffusers/dependency_versions_table.py
20
+
21
+ deps_table_update:
22
+ @python setup.py deps_table_update
23
+
24
+ deps_table_check_updated:
25
+ @md5sum src/diffusers/dependency_versions_table.py > md5sum.saved
26
+ @python setup.py deps_table_update
27
+ @md5sum -c --quiet md5sum.saved || (printf "\nError: the version dependency table is outdated.\nPlease run 'make fixup' or 'make style' and commit the changes.\n\n" && exit 1)
28
+ @rm md5sum.saved
29
+
30
+ # autogenerating code
31
+
32
+ autogenerate_code: deps_table_update
33
+
34
+ # Check that the repo is in a good state
35
+
36
+ repo-consistency:
37
+ python utils/check_dummies.py
38
+ python utils/check_repo.py
39
+ python utils/check_inits.py
40
+
41
+ # this target runs checks on all files
42
+
43
+ quality:
44
+ black --check --preview $(check_dirs)
45
+ isort --check-only $(check_dirs)
46
+ flake8 $(check_dirs)
47
+ doc-builder style src/diffusers docs/source --max_len 119 --check_only --path_to_docs docs/source
48
+
49
+ # Format source code automatically and check is there are any problems left that need manual fixing
50
+
51
+ extra_style_checks:
52
+ python utils/custom_init_isort.py
53
+ doc-builder style src/diffusers docs/source --max_len 119 --path_to_docs docs/source
54
+
55
+ # this target runs checks on all files and potentially modifies some of them
56
+
57
+ style:
58
+ black --preview $(check_dirs)
59
+ isort $(check_dirs)
60
+ ${MAKE} autogenerate_code
61
+ ${MAKE} extra_style_checks
62
+
63
+ # Super fast fix and check target that only works on relevant modified files since the branch was made
64
+
65
+ fixup: modified_only_fixup extra_style_checks autogenerate_code repo-consistency
66
+
67
+ # Make marked copies of snippets of codes conform to the original
68
+
69
+ fix-copies:
70
+ python utils/check_copies.py --fix_and_overwrite
71
+ python utils/check_dummies.py --fix_and_overwrite
72
+
73
+ # Run tests for the library
74
+
75
+ test:
76
+ python -m pytest -n auto --dist=loadfile -s -v ./tests/
77
+
78
+ # Run tests for examples
79
+
80
+ test-examples:
81
+ python -m pytest -n auto --dist=loadfile -s -v ./examples/pytorch/
82
+
83
+
84
+ # Release stuff
85
+
86
+ pre-release:
87
+ python utils/release.py
88
+
89
+ pre-patch:
90
+ python utils/release.py --patch
91
+
92
+ post-release:
93
+ python utils/release.py --post_release
94
+
95
+ post-patch:
96
+ python utils/release.py --post_release --patch
README.md CHANGED
@@ -1,3 +1,492 @@
1
- ---
2
- license: openrail
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p align="center">
2
+ <br>
3
+ <img src="https://github.com/huggingface/diffusers/raw/main/docs/source/imgs/diffusers_library.jpg" width="400"/>
4
+ <br>
5
+ <p>
6
+ <p align="center">
7
+ <a href="https://github.com/huggingface/diffusers/blob/main/LICENSE">
8
+ <img alt="GitHub" src="https://img.shields.io/github/license/huggingface/datasets.svg?color=blue">
9
+ </a>
10
+ <a href="https://github.com/huggingface/diffusers/releases">
11
+ <img alt="GitHub release" src="https://img.shields.io/github/release/huggingface/diffusers.svg">
12
+ </a>
13
+ <a href="CODE_OF_CONDUCT.md">
14
+ <img alt="Contributor Covenant" src="https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg">
15
+ </a>
16
+ </p>
17
+
18
+ 🤗 Diffusers provides pretrained diffusion models across multiple modalities, such as vision and audio, and serves
19
+ as a modular toolbox for inference and training of diffusion models.
20
+
21
+ More precisely, 🤗 Diffusers offers:
22
+
23
+ - State-of-the-art diffusion pipelines that can be run in inference with just a couple of lines of code (see [src/diffusers/pipelines](https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines)). Check [this overview](https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines/README.md#pipelines-summary) to see all supported pipelines and their corresponding official papers.
24
+ - Various noise schedulers that can be used interchangeably for the preferred speed vs. quality trade-off in inference (see [src/diffusers/schedulers](https://github.com/huggingface/diffusers/tree/main/src/diffusers/schedulers)).
25
+ - Multiple types of models, such as UNet, can be used as building blocks in an end-to-end diffusion system (see [src/diffusers/models](https://github.com/huggingface/diffusers/tree/main/src/diffusers/models)).
26
+ - Training examples to show how to train the most popular diffusion model tasks (see [examples](https://github.com/huggingface/diffusers/tree/main/examples), *e.g.* [unconditional-image-generation](https://github.com/huggingface/diffusers/tree/main/examples/unconditional_image_generation)).
27
+
28
+ ## Installation
29
+
30
+ ### For PyTorch
31
+
32
+ **With `pip`**
33
+
34
+ ```bash
35
+ pip install --upgrade diffusers[torch]
36
+ ```
37
+
38
+ **With `conda`**
39
+
40
+ ```sh
41
+ conda install -c conda-forge diffusers
42
+ ```
43
+
44
+ ### For Flax
45
+
46
+ **With `pip`**
47
+
48
+ ```bash
49
+ pip install --upgrade diffusers[flax]
50
+ ```
51
+
52
+ **Apple Silicon (M1/M2) support**
53
+
54
+ Please, refer to [the documentation](https://huggingface.co/docs/diffusers/optimization/mps).
55
+
56
+ ## Contributing
57
+
58
+ We ❤️ contributions from the open-source community!
59
+ If you want to contribute to this library, please check out our [Contribution guide](https://github.com/huggingface/diffusers/blob/main/CONTRIBUTING.md).
60
+ You can look out for [issues](https://github.com/huggingface/diffusers/issues) you'd like to tackle to contribute to the library.
61
+ - See [Good first issues](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22) for general opportunities to contribute
62
+ - See [New model/pipeline](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+pipeline%2Fmodel%22) to contribute exciting new diffusion models / diffusion pipelines
63
+ - See [New scheduler](https://github.com/huggingface/diffusers/issues?q=is%3Aopen+is%3Aissue+label%3A%22New+scheduler%22)
64
+
65
+ Also, say 👋 in our public Discord channel <a href="https://discord.gg/G7tWnz98XR"><img alt="Join us on Discord" src="https://img.shields.io/discord/823813159592001537?color=5865F2&logo=discord&logoColor=white"></a>. We discuss the hottest trends about diffusion models, help each other with contributions, personal projects or
66
+ just hang out ☕.
67
+
68
+ ## Quickstart
69
+
70
+ In order to get started, we recommend taking a look at two notebooks:
71
+
72
+ - The [Getting started with Diffusers](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/diffusers_intro.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/diffusers_intro.ipynb) notebook, which showcases an end-to-end example of usage for diffusion models, schedulers and pipelines.
73
+ Take a look at this notebook to learn how to use the pipeline abstraction, which takes care of everything (model, scheduler, noise handling) for you, and also to understand each independent building block in the library.
74
+ - The [Training a diffusers model](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/training_example.ipynb) [![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) notebook summarizes diffusion models training methods. This notebook takes a step-by-step approach to training your
75
+ diffusion models on an image dataset, with explanatory graphics.
76
+
77
+ ## Stable Diffusion is fully compatible with `diffusers`!
78
+
79
+ Stable Diffusion is a text-to-image latent diffusion model created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/), [LAION](https://laion.ai/) and [RunwayML](https://runwayml.com/). It's trained on 512x512 images from a subset of the [LAION-5B](https://laion.ai/blog/laion-5b/) database. This model uses a frozen CLIP ViT-L/14 text encoder to condition the model on text prompts. With its 860M UNet and 123M text encoder, the model is relatively lightweight and runs on a GPU with at least 4GB VRAM.
80
+ See the [model card](https://huggingface.co/CompVis/stable-diffusion) for more information.
81
+
82
+ You need to accept the model license before downloading or using the Stable Diffusion weights. Please, visit the [model card](https://huggingface.co/runwayml/stable-diffusion-v1-5), read the license carefully and tick the checkbox if you agree. You have to be a registered user in 🤗 Hugging Face Hub, and you'll also need to use an access token for the code to work. For more information on access tokens, please refer to [this section](https://huggingface.co/docs/hub/security-tokens) of the documentation.
83
+
84
+
85
+ ### Text-to-Image generation with Stable Diffusion
86
+
87
+ First let's install
88
+ ```bash
89
+ pip install --upgrade diffusers transformers scipy
90
+ ```
91
+
92
+ Run this command to log in with your HF Hub token if you haven't before (you can skip this step if you prefer to run the model locally, follow [this](#running-the-model-locally) instead)
93
+ ```bash
94
+ huggingface-cli login
95
+ ```
96
+
97
+ We recommend using the model in [half-precision (`fp16`)](https://pytorch.org/blog/accelerating-training-on-nvidia-gpus-with-pytorch-automatic-mixed-precision/) as it gives almost always the same results as full
98
+ precision while being roughly twice as fast and requiring half the amount of GPU RAM.
99
+
100
+ ```python
101
+ import torch
102
+ from diffusers import StableDiffusionPipeline
103
+
104
+ pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, revision="fp16")
105
+ pipe = pipe.to("cuda")
106
+
107
+ prompt = "a photo of an astronaut riding a horse on mars"
108
+ image = pipe(prompt).images[0]
109
+ ```
110
+
111
+ #### Running the model locally
112
+ If you don't want to login to Hugging Face, you can also simply download the model folder
113
+ (after having [accepted the license](https://huggingface.co/runwayml/stable-diffusion-v1-5)) and pass
114
+ the path to the local folder to the `StableDiffusionPipeline`.
115
+
116
+ ```
117
+ git lfs install
118
+ git clone https://huggingface.co/runwayml/stable-diffusion-v1-5
119
+ ```
120
+
121
+ Assuming the folder is stored locally under `./stable-diffusion-v1-5`, you can also run stable diffusion
122
+ without requiring an authentication token:
123
+
124
+ ```python
125
+ pipe = StableDiffusionPipeline.from_pretrained("./stable-diffusion-v1-5")
126
+ pipe = pipe.to("cuda")
127
+
128
+ prompt = "a photo of an astronaut riding a horse on mars"
129
+ image = pipe(prompt).images[0]
130
+ ```
131
+
132
+ If you are limited by GPU memory, you might want to consider chunking the attention computation in addition
133
+ to using `fp16`.
134
+ The following snippet should result in less than 4GB VRAM.
135
+
136
+ ```python
137
+ pipe = StableDiffusionPipeline.from_pretrained(
138
+ "runwayml/stable-diffusion-v1-5",
139
+ revision="fp16",
140
+ torch_dtype=torch.float16,
141
+ )
142
+ pipe = pipe.to("cuda")
143
+
144
+ prompt = "a photo of an astronaut riding a horse on mars"
145
+ pipe.enable_attention_slicing()
146
+ image = pipe(prompt).images[0]
147
+ ```
148
+
149
+ If you wish to use a different scheduler (e.g.: DDIM, LMS, PNDM/PLMS), you can instantiate
150
+ it before the pipeline and pass it to `from_pretrained`.
151
+
152
+ ```python
153
+ from diffusers import LMSDiscreteScheduler
154
+
155
+ pipe.scheduler = LMSDiscreteScheduler.from_config(pipe.scheduler.config)
156
+
157
+ prompt = "a photo of an astronaut riding a horse on mars"
158
+ image = pipe(prompt).images[0]
159
+
160
+ image.save("astronaut_rides_horse.png")
161
+ ```
162
+
163
+ If you want to run Stable Diffusion on CPU or you want to have maximum precision on GPU,
164
+ please run the model in the default *full-precision* setting:
165
+
166
+ ```python
167
+ # make sure you're logged in with `huggingface-cli login`
168
+ from diffusers import StableDiffusionPipeline
169
+
170
+ pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
171
+
172
+ # disable the following line if you run on CPU
173
+ pipe = pipe.to("cuda")
174
+
175
+ prompt = "a photo of an astronaut riding a horse on mars"
176
+ image = pipe(prompt).images[0]
177
+
178
+ image.save("astronaut_rides_horse.png")
179
+ ```
180
+
181
+ ### JAX/Flax
182
+
183
+ Diffusers offers a JAX / Flax implementation of Stable Diffusion for very fast inference. JAX shines specially on TPU hardware because each TPU server has 8 accelerators working in parallel, but it runs great on GPUs too.
184
+
185
+ Running the pipeline with the default PNDMScheduler:
186
+
187
+ ```python
188
+ import jax
189
+ import numpy as np
190
+ from flax.jax_utils import replicate
191
+ from flax.training.common_utils import shard
192
+
193
+ from diffusers import FlaxStableDiffusionPipeline
194
+
195
+ pipeline, params = FlaxStableDiffusionPipeline.from_pretrained(
196
+ "runwayml/stable-diffusion-v1-5", revision="flax", dtype=jax.numpy.bfloat16
197
+ )
198
+
199
+ prompt = "a photo of an astronaut riding a horse on mars"
200
+
201
+ prng_seed = jax.random.PRNGKey(0)
202
+ num_inference_steps = 50
203
+
204
+ num_samples = jax.device_count()
205
+ prompt = num_samples * [prompt]
206
+ prompt_ids = pipeline.prepare_inputs(prompt)
207
+
208
+ # shard inputs and rng
209
+ params = replicate(params)
210
+ prng_seed = jax.random.split(prng_seed, jax.device_count())
211
+ prompt_ids = shard(prompt_ids)
212
+
213
+ images = pipeline(prompt_ids, params, prng_seed, num_inference_steps, jit=True).images
214
+ images = pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-3:])))
215
+ ```
216
+
217
+ **Note**:
218
+ If you are limited by TPU memory, please make sure to load the `FlaxStableDiffusionPipeline` in `bfloat16` precision instead of the default `float32` precision as done above. You can do so by telling diffusers to load the weights from "bf16" branch.
219
+
220
+ ```python
221
+ import jax
222
+ import numpy as np
223
+ from flax.jax_utils import replicate
224
+ from flax.training.common_utils import shard
225
+
226
+ from diffusers import FlaxStableDiffusionPipeline
227
+
228
+ pipeline, params = FlaxStableDiffusionPipeline.from_pretrained(
229
+ "runwayml/stable-diffusion-v1-5", revision="bf16", dtype=jax.numpy.bfloat16
230
+ )
231
+
232
+ prompt = "a photo of an astronaut riding a horse on mars"
233
+
234
+ prng_seed = jax.random.PRNGKey(0)
235
+ num_inference_steps = 50
236
+
237
+ num_samples = jax.device_count()
238
+ prompt = num_samples * [prompt]
239
+ prompt_ids = pipeline.prepare_inputs(prompt)
240
+
241
+ # shard inputs and rng
242
+ params = replicate(params)
243
+ prng_seed = jax.random.split(prng_seed, jax.device_count())
244
+ prompt_ids = shard(prompt_ids)
245
+
246
+ images = pipeline(prompt_ids, params, prng_seed, num_inference_steps, jit=True).images
247
+ images = pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-3:])))
248
+ ```
249
+
250
+ ### Image-to-Image text-guided generation with Stable Diffusion
251
+
252
+ The `StableDiffusionImg2ImgPipeline` lets you pass a text prompt and an initial image to condition the generation of new images.
253
+
254
+ ```python
255
+ import requests
256
+ import torch
257
+ from PIL import Image
258
+ from io import BytesIO
259
+
260
+ from diffusers import StableDiffusionImg2ImgPipeline
261
+
262
+ # load the pipeline
263
+ device = "cuda"
264
+ model_id_or_path = "runwayml/stable-diffusion-v1-5"
265
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
266
+ model_id_or_path,
267
+ revision="fp16",
268
+ torch_dtype=torch.float16,
269
+ )
270
+ # or download via git clone https://huggingface.co/runwayml/stable-diffusion-v1-5
271
+ # and pass `model_id_or_path="./stable-diffusion-v1-5"`.
272
+ pipe = pipe.to(device)
273
+
274
+ # let's download an initial image
275
+ url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
276
+
277
+ response = requests.get(url)
278
+ init_image = Image.open(BytesIO(response.content)).convert("RGB")
279
+ init_image = init_image.resize((768, 512))
280
+
281
+ prompt = "A fantasy landscape, trending on artstation"
282
+
283
+ images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5).images
284
+
285
+ images[0].save("fantasy_landscape.png")
286
+ ```
287
+ You can also run this example on colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/image_2_image_using_diffusers.ipynb)
288
+
289
+ ### In-painting using Stable Diffusion
290
+
291
+ The `StableDiffusionInpaintPipeline` lets you edit specific parts of an image by providing a mask and a text prompt. It uses a model optimized for this particular task, whose license you need to accept before use.
292
+
293
+ Please, visit the [model card](https://huggingface.co/runwayml/stable-diffusion-inpainting), read the license carefully and tick the checkbox if you agree. Note that this is an additional license, you need to accept it even if you accepted the text-to-image Stable Diffusion license in the past. You have to be a registered user in 🤗 Hugging Face Hub, and you'll also need to use an access token for the code to work. For more information on access tokens, please refer to [this section](https://huggingface.co/docs/hub/security-tokens) of the documentation.
294
+
295
+
296
+ ```python
297
+ import PIL
298
+ import requests
299
+ import torch
300
+ from io import BytesIO
301
+
302
+ from diffusers import StableDiffusionInpaintPipeline
303
+
304
+ def download_image(url):
305
+ response = requests.get(url)
306
+ return PIL.Image.open(BytesIO(response.content)).convert("RGB")
307
+
308
+ img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
309
+ mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
310
+
311
+ init_image = download_image(img_url).resize((512, 512))
312
+ mask_image = download_image(mask_url).resize((512, 512))
313
+
314
+ pipe = StableDiffusionInpaintPipeline.from_pretrained(
315
+ "runwayml/stable-diffusion-inpainting",
316
+ revision="fp16",
317
+ torch_dtype=torch.float16,
318
+ )
319
+ pipe = pipe.to("cuda")
320
+
321
+ prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
322
+ image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
323
+ ```
324
+
325
+ ### Tweak prompts reusing seeds and latents
326
+
327
+ You can generate your own latents to reproduce results, or tweak your prompt on a specific result you liked. [This notebook](https://github.com/pcuenca/diffusers-examples/blob/main/notebooks/stable-diffusion-seeds.ipynb) shows how to do it step by step. You can also run it in Google Colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pcuenca/diffusers-examples/blob/main/notebooks/stable-diffusion-seeds.ipynb).
328
+
329
+
330
+ For more details, check out [the Stable Diffusion notebook](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/stable_diffusion.ipynb) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/stable_diffusion.ipynb)
331
+ and have a look into the [release notes](https://github.com/huggingface/diffusers/releases/tag/v0.2.0).
332
+
333
+ ## Fine-Tuning Stable Diffusion
334
+
335
+ Fine-tuning techniques make it possible to adapt Stable Diffusion to your own dataset, or add new subjects to it. These are some of the techniques supported in `diffusers`:
336
+
337
+ Textual Inversion is a technique for capturing novel concepts from a small number of example images in a way that can later be used to control text-to-image pipelines. It does so by learning new 'words' in the embedding space of the pipeline's text encoder. These special words can then be used within text prompts to achieve very fine-grained control of the resulting images.
338
+
339
+ - Textual Inversion. Capture novel concepts from a small set of sample images, and associate them with new "words" in the embedding space of the text encoder. Please, refer to [our training examples](https://github.com/huggingface/diffusers/tree/main/examples/textual_inversion) or [documentation](https://huggingface.co/docs/diffusers/training/text_inversion) to try for yourself.
340
+
341
+ - Dreambooth. Another technique to capture new concepts in Stable Diffusion. This method fine-tunes the UNet (and, optionally, also the text encoder) of the pipeline to achieve impressive results. Please, refer to [our training example](https://github.com/huggingface/diffusers/tree/main/examples/dreambooth) and [training report](https://huggingface.co/blog/dreambooth) for additional details and training recommendations.
342
+
343
+ - Full Stable Diffusion fine-tuning. If you have a more sizable dataset with a specific look or style, you can fine-tune Stable Diffusion so that it outputs images following those examples. This was the approach taken to create [a Pokémon Stable Diffusion model](https://huggingface.co/justinpinkney/pokemon-stable-diffusion) (by Justing Pinkney / Lambda Labs), [a Japanese specific version of Stable Diffusion](https://huggingface.co/spaces/rinna/japanese-stable-diffusion) (by [Rinna Co.](https://github.com/rinnakk/japanese-stable-diffusion/) and others. You can start at [our text-to-image fine-tuning example](https://github.com/huggingface/diffusers/tree/main/examples/text_to_image) and go from there.
344
+
345
+
346
+ ## Stable Diffusion Community Pipelines
347
+
348
+ The release of Stable Diffusion as an open source model has fostered a lot of interesting ideas and experimentation.
349
+ Our [Community Examples folder](https://github.com/huggingface/diffusers/tree/main/examples/community) contains many ideas worth exploring, like interpolating to create animated videos, using CLIP Guidance for additional prompt fidelity, term weighting, and much more! [Take a look](https://huggingface.co/docs/diffusers/using-diffusers/custom_pipeline_overview) and [contribute your own](https://huggingface.co/docs/diffusers/using-diffusers/contribute_pipeline).
350
+
351
+ ## Other Examples
352
+
353
+ There are many ways to try running Diffusers! Here we outline code-focused tools (primarily using `DiffusionPipeline`s and Google Colab) and interactive web-tools.
354
+
355
+ ### Running Code
356
+
357
+ If you want to run the code yourself 💻, you can try out:
358
+ - [Text-to-Image Latent Diffusion](https://huggingface.co/CompVis/ldm-text2im-large-256)
359
+ ```python
360
+ # !pip install diffusers["torch"] transformers
361
+ from diffusers import DiffusionPipeline
362
+
363
+ device = "cuda"
364
+ model_id = "CompVis/ldm-text2im-large-256"
365
+
366
+ # load model and scheduler
367
+ ldm = DiffusionPipeline.from_pretrained(model_id)
368
+ ldm = ldm.to(device)
369
+
370
+ # run pipeline in inference (sample random noise and denoise)
371
+ prompt = "A painting of a squirrel eating a burger"
372
+ image = ldm([prompt], num_inference_steps=50, eta=0.3, guidance_scale=6).images[0]
373
+
374
+ # save image
375
+ image.save("squirrel.png")
376
+ ```
377
+ - [Unconditional Diffusion with discrete scheduler](https://huggingface.co/google/ddpm-celebahq-256)
378
+ ```python
379
+ # !pip install diffusers["torch"]
380
+ from diffusers import DDPMPipeline, DDIMPipeline, PNDMPipeline
381
+
382
+ model_id = "google/ddpm-celebahq-256"
383
+ device = "cuda"
384
+
385
+ # load model and scheduler
386
+ ddpm = DDPMPipeline.from_pretrained(model_id) # you can replace DDPMPipeline with DDIMPipeline or PNDMPipeline for faster inference
387
+ ddpm.to(device)
388
+
389
+ # run pipeline in inference (sample random noise and denoise)
390
+ image = ddpm().images[0]
391
+
392
+ # save image
393
+ image.save("ddpm_generated_image.png")
394
+ ```
395
+ - [Unconditional Latent Diffusion](https://huggingface.co/CompVis/ldm-celebahq-256)
396
+ - [Unconditional Diffusion with continuous scheduler](https://huggingface.co/google/ncsnpp-ffhq-1024)
397
+
398
+ **Other Image Notebooks**:
399
+ * [image-to-image generation with Stable Diffusion](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/image_2_image_using_diffusers.ipynb) ![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg),
400
+ * [tweak images via repeated Stable Diffusion seeds](https://colab.research.google.com/github/pcuenca/diffusers-examples/blob/main/notebooks/stable-diffusion-seeds.ipynb) ![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg),
401
+
402
+ **Diffusers for Other Modalities**:
403
+ * [Molecule conformation generation](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/geodiff_molecule_conformation.ipynb) ![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg),
404
+ * [Model-based reinforcement learning](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/reinforcement_learning_with_diffusers.ipynb) ![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg),
405
+
406
+ ### Web Demos
407
+ If you just want to play around with some web demos, you can try out the following 🚀 Spaces:
408
+ | Model | Hugging Face Spaces |
409
+ |-------------------------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
410
+ | Text-to-Image Latent Diffusion | [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/CompVis/text2img-latent-diffusion) |
411
+ | Faces generator | [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/CompVis/celeba-latent-diffusion) |
412
+ | DDPM with different schedulers | [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/fusing/celeba-diffusion) |
413
+ | Conditional generation from sketch | [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/huggingface/diffuse-the-rest) |
414
+ | Composable diffusion | [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/Shuang59/Composable-Diffusion) |
415
+
416
+ ## Definitions
417
+
418
+ **Models**: Neural network that models $p_\theta(\mathbf{x}_{t-1}|\mathbf{x}_t)$ (see image below) and is trained end-to-end to *denoise* a noisy input to an image.
419
+ *Examples*: UNet, Conditioned UNet, 3D UNet, Transformer UNet
420
+
421
+ <p align="center">
422
+ <img src="https://user-images.githubusercontent.com/10695622/174349667-04e9e485-793b-429a-affe-096e8199ad5b.png" width="800"/>
423
+ <br>
424
+ <em> Figure from DDPM paper (https://arxiv.org/abs/2006.11239). </em>
425
+ <p>
426
+
427
+ **Schedulers**: Algorithm class for both **inference** and **training**.
428
+ The class provides functionality to compute previous image according to alpha, beta schedule as well as predict noise for training. Also known as **Samplers**.
429
+ *Examples*: [DDPM](https://arxiv.org/abs/2006.11239), [DDIM](https://arxiv.org/abs/2010.02502), [PNDM](https://arxiv.org/abs/2202.09778), [DEIS](https://arxiv.org/abs/2204.13902)
430
+
431
+ <p align="center">
432
+ <img src="https://user-images.githubusercontent.com/10695622/174349706-53d58acc-a4d1-4cda-b3e8-432d9dc7ad38.png" width="800"/>
433
+ <br>
434
+ <em> Sampling and training algorithms. Figure from DDPM paper (https://arxiv.org/abs/2006.11239). </em>
435
+ <p>
436
+
437
+
438
+ **Diffusion Pipeline**: End-to-end pipeline that includes multiple diffusion models, possible text encoders, ...
439
+ *Examples*: Glide, Latent-Diffusion, Imagen, DALL-E 2
440
+
441
+ <p align="center">
442
+ <img src="https://user-images.githubusercontent.com/10695622/174348898-481bd7c2-5457-4830-89bc-f0907756f64c.jpeg" width="550"/>
443
+ <br>
444
+ <em> Figure from ImageGen (https://imagen.research.google/). </em>
445
+ <p>
446
+
447
+ ## Philosophy
448
+
449
+ - Readability and clarity is preferred over highly optimized code. A strong importance is put on providing readable, intuitive and elementary code design. *E.g.*, the provided [schedulers](https://github.com/huggingface/diffusers/tree/main/src/diffusers/schedulers) are separated from the provided [models](https://github.com/huggingface/diffusers/tree/main/src/diffusers/models) and provide well-commented code that can be read alongside the original paper.
450
+ - Diffusers is **modality independent** and focuses on providing pretrained models and tools to build systems that generate **continuous outputs**, *e.g.* vision and audio.
451
+ - Diffusion models and schedulers are provided as concise, elementary building blocks. In contrast, diffusion pipelines are a collection of end-to-end diffusion systems that can be used out-of-the-box, should stay as close as possible to their original implementation and can include components of another library, such as text-encoders. Examples for diffusion pipelines are [Glide](https://github.com/openai/glide-text2im) and [Latent Diffusion](https://github.com/CompVis/latent-diffusion).
452
+
453
+ ## In the works
454
+
455
+ For the first release, 🤗 Diffusers focuses on text-to-image diffusion techniques. However, diffusers can be used for much more than that! Over the upcoming releases, we'll be focusing on:
456
+
457
+ - Diffusers for audio
458
+ - Diffusers for reinforcement learning (initial work happening in https://github.com/huggingface/diffusers/pull/105).
459
+ - Diffusers for video generation
460
+ - Diffusers for molecule generation (initial work happening in https://github.com/huggingface/diffusers/pull/54)
461
+
462
+ A few pipeline components are already being worked on, namely:
463
+
464
+ - BDDMPipeline for spectrogram-to-sound vocoding
465
+ - GLIDEPipeline to support OpenAI's GLIDE model
466
+ - Grad-TTS for text to audio generation / conditional audio generation
467
+
468
+ We want diffusers to be a toolbox useful for diffusers models in general; if you find yourself limited in any way by the current API, or would like to see additional models, schedulers, or techniques, please open a [GitHub issue](https://github.com/huggingface/diffusers/issues) mentioning what you would like to see.
469
+
470
+ ## Credits
471
+
472
+ This library concretizes previous work by many different authors and would not have been possible without their great research and implementations. We'd like to thank, in particular, the following implementations which have helped us in our development and without which the API could not have been as polished today:
473
+
474
+ - @CompVis' latent diffusion models library, available [here](https://github.com/CompVis/latent-diffusion)
475
+ - @hojonathanho original DDPM implementation, available [here](https://github.com/hojonathanho/diffusion) as well as the extremely useful translation into PyTorch by @pesser, available [here](https://github.com/pesser/pytorch_diffusion)
476
+ - @ermongroup's DDIM implementation, available [here](https://github.com/ermongroup/ddim).
477
+ - @yang-song's Score-VE and Score-VP implementations, available [here](https://github.com/yang-song/score_sde_pytorch)
478
+
479
+ We also want to thank @heejkoo for the very helpful overview of papers, code and resources on diffusion models, available [here](https://github.com/heejkoo/Awesome-Diffusion-Models) as well as @crowsonkb and @rromb for useful discussions and insights.
480
+
481
+ ## Citation
482
+
483
+ ```bibtex
484
+ @misc{von-platen-etal-2022-diffusers,
485
+ author = {Patrick von Platen and Suraj Patil and Anton Lozhkov and Pedro Cuenca and Nathan Lambert and Kashif Rasul and Mishig Davaadorj and Thomas Wolf},
486
+ title = {Diffusers: State-of-the-art diffusion models},
487
+ year = {2022},
488
+ publisher = {GitHub},
489
+ journal = {GitHub repository},
490
+ howpublished = {\url{https://github.com/huggingface/diffusers}}
491
+ }
492
+ ```
_typos.toml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Files for typos
2
+ # Instruction: https://github.com/marketplace/actions/typos-action#getting-started
3
+
4
+ [default.extend-identifiers]
5
+
6
+ [default.extend-words]
7
+ NIN="NIN" # NIN is used in scripts/convert_ncsnpp_original_checkpoint_to_diffusers.py
8
+ nd="np" # nd may be np (numpy)
9
+ parms="parms" # parms is used in scripts/convert_original_stable_diffusion_to_diffusers.py
10
+
11
+
12
+ [files]
13
+ extend-exclude = ["_typos.toml"]
docker/diffusers-flax-cpu/Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:20.04
2
+ LABEL maintainer="Hugging Face"
3
+ LABEL repository="diffusers"
4
+
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+
7
+ RUN apt update && \
8
+ apt install -y bash \
9
+ build-essential \
10
+ git \
11
+ git-lfs \
12
+ curl \
13
+ ca-certificates \
14
+ python3.8 \
15
+ python3-pip \
16
+ python3.8-venv && \
17
+ rm -rf /var/lib/apt/lists
18
+
19
+ # make sure to use venv
20
+ RUN python3 -m venv /opt/venv
21
+ ENV PATH="/opt/venv/bin:$PATH"
22
+
23
+ # pre-install the heavy dependencies (these can later be overridden by the deps from setup.py)
24
+ # follow the instructions here: https://cloud.google.com/tpu/docs/run-in-container#train_a_jax_model_in_a_docker_container
25
+ RUN python3 -m pip install --no-cache-dir --upgrade pip && \
26
+ python3 -m pip install --upgrade --no-cache-dir \
27
+ clu \
28
+ "jax[cpu]>=0.2.16,!=0.3.2" \
29
+ "flax>=0.4.1" \
30
+ "jaxlib>=0.1.65" && \
31
+ python3 -m pip install --no-cache-dir \
32
+ accelerate \
33
+ datasets \
34
+ hf-doc-builder \
35
+ huggingface-hub \
36
+ modelcards \
37
+ numpy \
38
+ scipy \
39
+ tensorboard \
40
+ transformers
41
+
42
+ CMD ["/bin/bash"]
docker/diffusers-flax-tpu/Dockerfile ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:20.04
2
+ LABEL maintainer="Hugging Face"
3
+ LABEL repository="diffusers"
4
+
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+
7
+ RUN apt update && \
8
+ apt install -y bash \
9
+ build-essential \
10
+ git \
11
+ git-lfs \
12
+ curl \
13
+ ca-certificates \
14
+ python3.8 \
15
+ python3-pip \
16
+ python3.8-venv && \
17
+ rm -rf /var/lib/apt/lists
18
+
19
+ # make sure to use venv
20
+ RUN python3 -m venv /opt/venv
21
+ ENV PATH="/opt/venv/bin:$PATH"
22
+
23
+ # pre-install the heavy dependencies (these can later be overridden by the deps from setup.py)
24
+ # follow the instructions here: https://cloud.google.com/tpu/docs/run-in-container#train_a_jax_model_in_a_docker_container
25
+ RUN python3 -m pip install --no-cache-dir --upgrade pip && \
26
+ python3 -m pip install --no-cache-dir \
27
+ "jax[tpu]>=0.2.16,!=0.3.2" \
28
+ -f https://storage.googleapis.com/jax-releases/libtpu_releases.html && \
29
+ python3 -m pip install --upgrade --no-cache-dir \
30
+ clu \
31
+ "flax>=0.4.1" \
32
+ "jaxlib>=0.1.65" && \
33
+ python3 -m pip install --no-cache-dir \
34
+ accelerate \
35
+ datasets \
36
+ hf-doc-builder \
37
+ huggingface-hub \
38
+ modelcards \
39
+ numpy \
40
+ scipy \
41
+ tensorboard \
42
+ transformers
43
+
44
+ CMD ["/bin/bash"]
docker/diffusers-onnxruntime-cpu/Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:20.04
2
+ LABEL maintainer="Hugging Face"
3
+ LABEL repository="diffusers"
4
+
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+
7
+ RUN apt update && \
8
+ apt install -y bash \
9
+ build-essential \
10
+ git \
11
+ git-lfs \
12
+ curl \
13
+ ca-certificates \
14
+ python3.8 \
15
+ python3-pip \
16
+ python3.8-venv && \
17
+ rm -rf /var/lib/apt/lists
18
+
19
+ # make sure to use venv
20
+ RUN python3 -m venv /opt/venv
21
+ ENV PATH="/opt/venv/bin:$PATH"
22
+
23
+ # pre-install the heavy dependencies (these can later be overridden by the deps from setup.py)
24
+ RUN python3 -m pip install --no-cache-dir --upgrade pip && \
25
+ python3 -m pip install --no-cache-dir \
26
+ torch \
27
+ torchvision \
28
+ torchaudio \
29
+ onnxruntime \
30
+ --extra-index-url https://download.pytorch.org/whl/cpu && \
31
+ python3 -m pip install --no-cache-dir \
32
+ accelerate \
33
+ datasets \
34
+ hf-doc-builder \
35
+ huggingface-hub \
36
+ modelcards \
37
+ numpy \
38
+ scipy \
39
+ tensorboard \
40
+ transformers
41
+
42
+ CMD ["/bin/bash"]
docker/diffusers-onnxruntime-cuda/Dockerfile ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.6.2-cudnn8-devel-ubuntu20.04
2
+ LABEL maintainer="Hugging Face"
3
+ LABEL repository="diffusers"
4
+
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+
7
+ RUN apt update && \
8
+ apt install -y bash \
9
+ build-essential \
10
+ git \
11
+ git-lfs \
12
+ curl \
13
+ ca-certificates \
14
+ python3.8 \
15
+ python3-pip \
16
+ python3.8-venv && \
17
+ rm -rf /var/lib/apt/lists
18
+
19
+ # make sure to use venv
20
+ RUN python3 -m venv /opt/venv
21
+ ENV PATH="/opt/venv/bin:$PATH"
22
+
23
+ # pre-install the heavy dependencies (these can later be overridden by the deps from setup.py)
24
+ RUN python3 -m pip install --no-cache-dir --upgrade pip && \
25
+ python3 -m pip install --no-cache-dir \
26
+ torch \
27
+ torchvision \
28
+ torchaudio \
29
+ "onnxruntime-gpu>=1.13.1" \
30
+ --extra-index-url https://download.pytorch.org/whl/cu117 && \
31
+ python3 -m pip install --no-cache-dir \
32
+ accelerate \
33
+ datasets \
34
+ hf-doc-builder \
35
+ huggingface-hub \
36
+ modelcards \
37
+ numpy \
38
+ scipy \
39
+ tensorboard \
40
+ transformers
41
+
42
+ CMD ["/bin/bash"]
docker/diffusers-pytorch-cpu/Dockerfile ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ubuntu:20.04
2
+ LABEL maintainer="Hugging Face"
3
+ LABEL repository="diffusers"
4
+
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+
7
+ RUN apt update && \
8
+ apt install -y bash \
9
+ build-essential \
10
+ git \
11
+ git-lfs \
12
+ curl \
13
+ ca-certificates \
14
+ python3.8 \
15
+ python3-pip \
16
+ python3.8-venv && \
17
+ rm -rf /var/lib/apt/lists
18
+
19
+ # make sure to use venv
20
+ RUN python3 -m venv /opt/venv
21
+ ENV PATH="/opt/venv/bin:$PATH"
22
+
23
+ # pre-install the heavy dependencies (these can later be overridden by the deps from setup.py)
24
+ RUN python3 -m pip install --no-cache-dir --upgrade pip && \
25
+ python3 -m pip install --no-cache-dir \
26
+ torch \
27
+ torchvision \
28
+ torchaudio \
29
+ --extra-index-url https://download.pytorch.org/whl/cpu && \
30
+ python3 -m pip install --no-cache-dir \
31
+ accelerate \
32
+ datasets \
33
+ hf-doc-builder \
34
+ huggingface-hub \
35
+ modelcards \
36
+ numpy \
37
+ scipy \
38
+ tensorboard \
39
+ transformers
40
+
41
+ CMD ["/bin/bash"]
docker/diffusers-pytorch-cuda/Dockerfile ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu20.04
2
+ LABEL maintainer="Hugging Face"
3
+ LABEL repository="diffusers"
4
+
5
+ ENV DEBIAN_FRONTEND=noninteractive
6
+
7
+ RUN apt update && \
8
+ apt install -y bash \
9
+ build-essential \
10
+ git \
11
+ git-lfs \
12
+ curl \
13
+ ca-certificates \
14
+ python3.8 \
15
+ python3-pip \
16
+ python3.8-venv && \
17
+ rm -rf /var/lib/apt/lists
18
+
19
+ # make sure to use venv
20
+ RUN python3 -m venv /opt/venv
21
+ ENV PATH="/opt/venv/bin:$PATH"
22
+
23
+ # pre-install the heavy dependencies (these can later be overridden by the deps from setup.py)
24
+ RUN python3 -m pip install --no-cache-dir --upgrade pip && \
25
+ python3 -m pip install --no-cache-dir \
26
+ torch \
27
+ torchvision \
28
+ torchaudio \
29
+ --extra-index-url https://download.pytorch.org/whl/cu117 && \
30
+ python3 -m pip install --no-cache-dir \
31
+ accelerate \
32
+ datasets \
33
+ hf-doc-builder \
34
+ huggingface-hub \
35
+ modelcards \
36
+ numpy \
37
+ scipy \
38
+ tensorboard \
39
+ transformers
40
+
41
+ CMD ["/bin/bash"]
docs/source/_toctree.yml ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ - sections:
2
+ - local: index
3
+ title: "🧨 Diffusers"
4
+ - local: quicktour
5
+ title: "Quicktour"
6
+ - local: installation
7
+ title: "Installation"
8
+ title: "Get started"
9
+ - sections:
10
+ - sections:
11
+ - local: using-diffusers/loading
12
+ title: "Loading Pipelines, Models, and Schedulers"
13
+ - local: using-diffusers/schedulers
14
+ title: "Using different Schedulers"
15
+ - local: using-diffusers/configuration
16
+ title: "Configuring Pipelines, Models, and Schedulers"
17
+ - local: using-diffusers/custom_pipeline_overview
18
+ title: "Loading and Adding Custom Pipelines"
19
+ title: "Loading & Hub"
20
+ - sections:
21
+ - local: using-diffusers/unconditional_image_generation
22
+ title: "Unconditional Image Generation"
23
+ - local: using-diffusers/conditional_image_generation
24
+ title: "Text-to-Image Generation"
25
+ - local: using-diffusers/img2img
26
+ title: "Text-Guided Image-to-Image"
27
+ - local: using-diffusers/inpaint
28
+ title: "Text-Guided Image-Inpainting"
29
+ - local: using-diffusers/custom_pipeline_examples
30
+ title: "Community Pipelines"
31
+ - local: using-diffusers/contribute_pipeline
32
+ title: "How to contribute a Pipeline"
33
+ title: "Pipelines for Inference"
34
+ - sections:
35
+ - local: using-diffusers/rl
36
+ title: "Reinforcement Learning"
37
+ - local: using-diffusers/audio
38
+ title: "Audio"
39
+ - local: using-diffusers/other-modalities
40
+ title: "Other Modalities"
41
+ title: "Taking Diffusers Beyond Images"
42
+ title: "Using Diffusers"
43
+ - sections:
44
+ - local: optimization/fp16
45
+ title: "Memory and Speed"
46
+ - local: optimization/onnx
47
+ title: "ONNX"
48
+ - local: optimization/open_vino
49
+ title: "OpenVINO"
50
+ - local: optimization/mps
51
+ title: "MPS"
52
+ title: "Optimization/Special Hardware"
53
+ - sections:
54
+ - local: training/overview
55
+ title: "Overview"
56
+ - local: training/unconditional_training
57
+ title: "Unconditional Image Generation"
58
+ - local: training/text_inversion
59
+ title: "Textual Inversion"
60
+ - local: training/dreambooth
61
+ title: "Dreambooth"
62
+ - local: training/text2image
63
+ title: "Text-to-image fine-tuning"
64
+ title: "Training"
65
+ - sections:
66
+ - local: conceptual/stable_diffusion
67
+ title: "Stable Diffusion"
68
+ - local: conceptual/philosophy
69
+ title: "Philosophy"
70
+ - local: conceptual/contribution
71
+ title: "How to contribute?"
72
+ title: "Conceptual Guides"
73
+ - sections:
74
+ - sections:
75
+ - local: api/models
76
+ title: "Models"
77
+ - local: api/schedulers
78
+ title: "Schedulers"
79
+ - local: api/diffusion_pipeline
80
+ title: "Diffusion Pipeline"
81
+ - local: api/logging
82
+ title: "Logging"
83
+ - local: api/configuration
84
+ title: "Configuration"
85
+ - local: api/outputs
86
+ title: "Outputs"
87
+ title: "Main Classes"
88
+ - sections:
89
+ - local: api/pipelines/overview
90
+ title: "Overview"
91
+ - local: api/pipelines/alt_diffusion
92
+ title: "AltDiffusion"
93
+ - local: api/pipelines/cycle_diffusion
94
+ title: "Cycle Diffusion"
95
+ - local: api/pipelines/ddim
96
+ title: "DDIM"
97
+ - local: api/pipelines/ddpm
98
+ title: "DDPM"
99
+ - local: api/pipelines/latent_diffusion
100
+ title: "Latent Diffusion"
101
+ - local: api/pipelines/latent_diffusion_uncond
102
+ title: "Unconditional Latent Diffusion"
103
+ - local: api/pipelines/pndm
104
+ title: "PNDM"
105
+ - local: api/pipelines/score_sde_ve
106
+ title: "Score SDE VE"
107
+ - local: api/pipelines/stable_diffusion
108
+ title: "Stable Diffusion"
109
+ - local: api/pipelines/stochastic_karras_ve
110
+ title: "Stochastic Karras VE"
111
+ - local: api/pipelines/dance_diffusion
112
+ title: "Dance Diffusion"
113
+ - local: api/pipelines/vq_diffusion
114
+ title: "VQ Diffusion"
115
+ - local: api/pipelines/repaint
116
+ title: "RePaint"
117
+ title: "Pipelines"
118
+ - sections:
119
+ - local: api/experimental/rl
120
+ title: "RL Planning"
121
+ title: "Experimental Features"
122
+ title: "API"
docs/source/api/configuration.mdx ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Configuration
14
+
15
+ In Diffusers, schedulers of type [`schedulers.scheduling_utils.SchedulerMixin`], and models of type [`ModelMixin`] inherit from [`ConfigMixin`] which conveniently takes care of storing all parameters that are
16
+ passed to the respective `__init__` methods in a JSON-configuration file.
17
+
18
+ ## ConfigMixin
19
+
20
+ [[autodoc]] ConfigMixin
21
+ - load_config
22
+ - from_config
23
+ - save_config
docs/source/api/diffusion_pipeline.mdx ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Pipelines
14
+
15
+ The [`DiffusionPipeline`] is the easiest way to load any pretrained diffusion pipeline from the [Hub](https://huggingface.co/models?library=diffusers) and to use it in inference.
16
+
17
+ <Tip>
18
+
19
+ One should not use the Diffusion Pipeline class for training or fine-tuning a diffusion model. Individual
20
+ components of diffusion pipelines are usually trained individually, so we suggest to directly work
21
+ with [`UNetModel`] and [`UNetConditionModel`].
22
+
23
+ </Tip>
24
+
25
+ Any diffusion pipeline that is loaded with [`~DiffusionPipeline.from_pretrained`] will automatically
26
+ detect the pipeline type, *e.g.* [`StableDiffusionPipeline`] and consequently load each component of the
27
+ pipeline and pass them into the `__init__` function of the pipeline, *e.g.* [`~StableDiffusionPipeline.__init__`].
28
+
29
+ Any pipeline object can be saved locally with [`~DiffusionPipeline.save_pretrained`].
30
+
31
+ ## DiffusionPipeline
32
+ [[autodoc]] DiffusionPipeline
33
+ - from_pretrained
34
+ - save_pretrained
35
+ - to
36
+ - device
37
+ - components
38
+
39
+ ## ImagePipelineOutput
40
+ By default diffusion pipelines return an object of class
41
+
42
+ [[autodoc]] pipeline_utils.ImagePipelineOutput
docs/source/api/experimental/rl.mdx ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # TODO
14
+
15
+ Coming soon!
docs/source/api/logging.mdx ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2020 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Logging
14
+
15
+ 🧨 Diffusers has a centralized logging system, so that you can setup the verbosity of the library easily.
16
+
17
+ Currently the default verbosity of the library is `WARNING`.
18
+
19
+ To change the level of verbosity, just use one of the direct setters. For instance, here is how to change the verbosity
20
+ to the INFO level.
21
+
22
+ ```python
23
+ import diffusers
24
+
25
+ diffusers.logging.set_verbosity_info()
26
+ ```
27
+
28
+ You can also use the environment variable `DIFFUSERS_VERBOSITY` to override the default verbosity. You can set it
29
+ to one of the following: `debug`, `info`, `warning`, `error`, `critical`. For example:
30
+
31
+ ```bash
32
+ DIFFUSERS_VERBOSITY=error ./myprogram.py
33
+ ```
34
+
35
+ Additionally, some `warnings` can be disabled by setting the environment variable
36
+ `DIFFUSERS_NO_ADVISORY_WARNINGS` to a true value, like *1*. This will disable any warning that is logged using
37
+ [`logger.warning_advice`]. For example:
38
+
39
+ ```bash
40
+ DIFFUSERS_NO_ADVISORY_WARNINGS=1 ./myprogram.py
41
+ ```
42
+
43
+ Here is an example of how to use the same logger as the library in your own module or script:
44
+
45
+ ```python
46
+ from diffusers.utils import logging
47
+
48
+ logging.set_verbosity_info()
49
+ logger = logging.get_logger("diffusers")
50
+ logger.info("INFO")
51
+ logger.warning("WARN")
52
+ ```
53
+
54
+
55
+ All the methods of this logging module are documented below, the main ones are
56
+ [`logging.get_verbosity`] to get the current level of verbosity in the logger and
57
+ [`logging.set_verbosity`] to set the verbosity to the level of your choice. In order (from the least
58
+ verbose to the most verbose), those levels (with their corresponding int values in parenthesis) are:
59
+
60
+ - `diffusers.logging.CRITICAL` or `diffusers.logging.FATAL` (int value, 50): only report the most
61
+ critical errors.
62
+ - `diffusers.logging.ERROR` (int value, 40): only report errors.
63
+ - `diffusers.logging.WARNING` or `diffusers.logging.WARN` (int value, 30): only reports error and
64
+ warnings. This the default level used by the library.
65
+ - `diffusers.logging.INFO` (int value, 20): reports error, warnings and basic information.
66
+ - `diffusers.logging.DEBUG` (int value, 10): report all information.
67
+
68
+ By default, `tqdm` progress bars will be displayed during model download. [`logging.disable_progress_bar`] and [`logging.enable_progress_bar`] can be used to suppress or unsuppress this behavior.
69
+
70
+ ## Base setters
71
+
72
+ [[autodoc]] logging.set_verbosity_error
73
+
74
+ [[autodoc]] logging.set_verbosity_warning
75
+
76
+ [[autodoc]] logging.set_verbosity_info
77
+
78
+ [[autodoc]] logging.set_verbosity_debug
79
+
80
+ ## Other functions
81
+
82
+ [[autodoc]] logging.get_verbosity
83
+
84
+ [[autodoc]] logging.set_verbosity
85
+
86
+ [[autodoc]] logging.get_logger
87
+
88
+ [[autodoc]] logging.enable_default_handler
89
+
90
+ [[autodoc]] logging.disable_default_handler
91
+
92
+ [[autodoc]] logging.enable_explicit_format
93
+
94
+ [[autodoc]] logging.reset_format
95
+
96
+ [[autodoc]] logging.enable_progress_bar
97
+
98
+ [[autodoc]] logging.disable_progress_bar
docs/source/api/models.mdx ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Models
14
+
15
+ Diffusers contains pretrained models for popular algorithms and modules for creating the next set of diffusion models.
16
+ The primary function of these models is to denoise an input sample, by modeling the distribution $p_\theta(\mathbf{x}_{t-1}|\mathbf{x}_t)$.
17
+ The models are built on the base class ['ModelMixin'] that is a `torch.nn.module` with basic functionality for saving and loading models both locally and from the HuggingFace hub.
18
+
19
+ ## ModelMixin
20
+ [[autodoc]] ModelMixin
21
+
22
+ ## UNet2DOutput
23
+ [[autodoc]] models.unet_2d.UNet2DOutput
24
+
25
+ ## UNet2DModel
26
+ [[autodoc]] UNet2DModel
27
+
28
+ ## UNet1DOutput
29
+ [[autodoc]] models.unet_1d.UNet1DOutput
30
+
31
+ ## UNet1DModel
32
+ [[autodoc]] UNet1DModel
33
+
34
+ ## UNet2DConditionOutput
35
+ [[autodoc]] models.unet_2d_condition.UNet2DConditionOutput
36
+
37
+ ## UNet2DConditionModel
38
+ [[autodoc]] UNet2DConditionModel
39
+
40
+ ## DecoderOutput
41
+ [[autodoc]] models.vae.DecoderOutput
42
+
43
+ ## VQEncoderOutput
44
+ [[autodoc]] models.vae.VQEncoderOutput
45
+
46
+ ## VQModel
47
+ [[autodoc]] VQModel
48
+
49
+ ## AutoencoderKLOutput
50
+ [[autodoc]] models.vae.AutoencoderKLOutput
51
+
52
+ ## AutoencoderKL
53
+ [[autodoc]] AutoencoderKL
54
+
55
+ ## Transformer2DModel
56
+ [[autodoc]] Transformer2DModel
57
+
58
+ ## Transformer2DModelOutput
59
+ [[autodoc]] models.attention.Transformer2DModelOutput
60
+
61
+ ## FlaxModelMixin
62
+ [[autodoc]] FlaxModelMixin
63
+
64
+ ## FlaxUNet2DConditionOutput
65
+ [[autodoc]] models.unet_2d_condition_flax.FlaxUNet2DConditionOutput
66
+
67
+ ## FlaxUNet2DConditionModel
68
+ [[autodoc]] FlaxUNet2DConditionModel
69
+
70
+ ## FlaxDecoderOutput
71
+ [[autodoc]] models.vae_flax.FlaxDecoderOutput
72
+
73
+ ## FlaxAutoencoderKLOutput
74
+ [[autodoc]] models.vae_flax.FlaxAutoencoderKLOutput
75
+
76
+ ## FlaxAutoencoderKL
77
+ [[autodoc]] FlaxAutoencoderKL
docs/source/api/outputs.mdx ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # BaseOutputs
14
+
15
+ All models have outputs that are instances of subclasses of [`~utils.BaseOutput`]. Those are
16
+ data structures containing all the information returned by the model, but that can also be used as tuples or
17
+ dictionaries.
18
+
19
+ Let's see how this looks in an example:
20
+
21
+ ```python
22
+ from diffusers import DDIMPipeline
23
+
24
+ pipeline = DDIMPipeline.from_pretrained("google/ddpm-cifar10-32")
25
+ outputs = pipeline()
26
+ ```
27
+
28
+ The `outputs` object is a [`~pipeline_utils.ImagePipelineOutput`], as we can see in the
29
+ documentation of that class below, it means it has an image attribute.
30
+
31
+ You can access each attribute as you would usually do, and if that attribute has not been returned by the model, you will get `None`:
32
+
33
+ ```python
34
+ outputs.images
35
+ ```
36
+
37
+ or via keyword lookup
38
+
39
+ ```python
40
+ outputs["images"]
41
+ ```
42
+
43
+ When considering our `outputs` object as tuple, it only considers the attributes that don't have `None` values.
44
+ Here for instance, we could retrieve images via indexing:
45
+
46
+ ```python
47
+ outputs[:1]
48
+ ```
49
+
50
+ which will return the tuple `(outputs.images)` for instance.
51
+
52
+ ## BaseOutput
53
+
54
+ [[autodoc]] utils.BaseOutput
55
+ - to_tuple
docs/source/api/pipelines/alt_diffusion.mdx ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # AltDiffusion
14
+
15
+ AltDiffusion was proposed in [AltCLIP: Altering the Language Encoder in CLIP for Extended Language Capabilities](https://arxiv.org/abs/2211.06679) by Zhongzhi Chen, Guang Liu, Bo-Wen Zhang, Fulong Ye, Qinghong Yang, Ledell Wu
16
+
17
+ The abstract of the paper is the following:
18
+
19
+ *In this work, we present a conceptually simple and effective method to train a strong bilingual multimodal representation model. Starting from the pretrained multimodal representation model CLIP released by OpenAI, we switched its text encoder with a pretrained multilingual text encoder XLM-R, and aligned both languages and image representations by a two-stage training schema consisting of teacher learning and contrastive learning. We validate our method through evaluations of a wide range of tasks. We set new state-of-the-art performances on a bunch of tasks including ImageNet-CN, Flicker30k- CN, and COCO-CN. Further, we obtain very close performances with CLIP on almost all tasks, suggesting that one can simply alter the text encoder in CLIP for extended capabilities such as multilingual understanding.*
20
+
21
+
22
+ *Overview*:
23
+
24
+ | Pipeline | Tasks | Colab | Demo
25
+ |---|---|:---:|:---:|
26
+ | [pipeline_alt_diffusion.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion.py) | *Text-to-Image Generation* | - | -
27
+ | [pipeline_alt_diffusion_img2img.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/alt_diffusion/pipeline_alt_diffusion_img2img.py) | *Image-to-Image Text-Guided Generation* | - |-
28
+
29
+ ## Tips
30
+
31
+ - AltDiffusion is conceptually exaclty the same as [Stable Diffusion](./api/pipelines/stable_diffusion).
32
+
33
+ - *Run AltDiffusion*
34
+
35
+ AltDiffusion can be tested very easily with the [`AltDiffusionPipeline`], [`AltDiffusionImg2ImgPipeline`] and the `"BAAI/AltDiffusion"` checkpoint exactly in the same way it is shown in the [Conditional Image Generation Guide](./using-diffusers/conditional_image_generation) and the [Image-to-Image Generation Guide](./using-diffusers/img2img).
36
+
37
+ - *How to load and use different schedulers.*
38
+
39
+ The alt diffusion pipeline uses [`DDIMScheduler`] scheduler by default. But `diffusers` provides many other schedulers that can be used with the alt diffusion pipeline such as [`PNDMScheduler`], [`LMSDiscreteScheduler`], [`EulerDiscreteScheduler`], [`EulerAncestralDiscreteScheduler`] etc.
40
+ To use a different scheduler, you can either change it via the [`ConfigMixin.from_config`] method or pass the `scheduler` argument to the `from_pretrained` method of the pipeline. For example, to use the [`EulerDiscreteScheduler`], you can do the following:
41
+
42
+ ```python
43
+ >>> from diffusers import AltDiffusionPipeline, EulerDiscreteScheduler
44
+
45
+ >>> pipeline = AltDiffusionPipeline.from_pretrained("BAAI/AltDiffusion")
46
+ >>> pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
47
+
48
+ >>> # or
49
+ >>> euler_scheduler = EulerDiscreteScheduler.from_pretrained("BAAI/AltDiffusion", subfolder="scheduler")
50
+ >>> pipeline = AltDiffusionPipeline.from_pretrained("BAAI/AltDiffusion", scheduler=euler_scheduler)
51
+ ```
52
+
53
+
54
+ - *How to conver all use cases with multiple or single pipeline*
55
+
56
+ If you want to use all possible use cases in a single `DiffusionPipeline` we recommend using the `components` functionality to instantiate all components in the most memory-efficient way:
57
+
58
+ ```python
59
+ >>> from diffusers import (
60
+ ... AltDiffusionPipeline,
61
+ ... AltDiffusionImg2ImgPipeline,
62
+ ... )
63
+
64
+ >>> text2img = AltDiffusionPipeline.from_pretrained("BAAI/AltDiffusion")
65
+ >>> img2img = AltDiffusionImg2ImgPipeline(**text2img.components)
66
+
67
+ >>> # now you can use text2img(...) and img2img(...) just like the call methods of each respective pipeline
68
+ ```
69
+
70
+ ## AltDiffusionPipelineOutput
71
+ [[autodoc]] pipelines.alt_diffusion.AltDiffusionPipelineOutput
72
+
73
+ ## AltDiffusionPipeline
74
+ [[autodoc]] AltDiffusionPipeline
75
+ - __call__
76
+ - enable_attention_slicing
77
+ - disable_attention_slicing
78
+
79
+ ## AltDiffusionImg2ImgPipeline
80
+ [[autodoc]] AltDiffusionImg2ImgPipeline
81
+ - __call__
82
+ - enable_attention_slicing
83
+ - disable_attention_slicing
docs/source/api/pipelines/cycle_diffusion.mdx ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Cycle Diffusion
14
+
15
+ ## Overview
16
+
17
+ Cycle Diffusion is a Text-Guided Image-to-Image Generation model proposed in [Unifying Diffusion Models' Latent Space, with Applications to CycleDiffusion and Guidance](https://arxiv.org/abs/2210.05559) by Chen Henry Wu, Fernando De la Torre.
18
+
19
+ The abstract of the paper is the following:
20
+
21
+ *Diffusion models have achieved unprecedented performance in generative modeling. The commonly-adopted formulation of the latent code of diffusion models is a sequence of gradually denoised samples, as opposed to the simpler (e.g., Gaussian) latent space of GANs, VAEs, and normalizing flows. This paper provides an alternative, Gaussian formulation of the latent space of various diffusion models, as well as an invertible DPM-Encoder that maps images into the latent space. While our formulation is purely based on the definition of diffusion models, we demonstrate several intriguing consequences. (1) Empirically, we observe that a common latent space emerges from two diffusion models trained independently on related domains. In light of this finding, we propose CycleDiffusion, which uses DPM-Encoder for unpaired image-to-image translation. Furthermore, applying CycleDiffusion to text-to-image diffusion models, we show that large-scale text-to-image diffusion models can be used as zero-shot image-to-image editors. (2) One can guide pre-trained diffusion models and GANs by controlling the latent codes in a unified, plug-and-play formulation based on energy-based models. Using the CLIP model and a face recognition model as guidance, we demonstrate that diffusion models have better coverage of low-density sub-populations and individuals than GANs.*
22
+
23
+ *Tips*:
24
+ - The Cycle Diffusion pipeline is fully compatible with any [Stable Diffusion](./stable_diffusion) checkpoints
25
+ - Currently Cycle Diffusion only works with the [`DDIMScheduler`].
26
+
27
+ *Example*:
28
+
29
+ In the following we should how to best use the [`CycleDiffusionPipeline`]
30
+
31
+ ```python
32
+ import requests
33
+ import torch
34
+ from PIL import Image
35
+ from io import BytesIO
36
+
37
+ from diffusers import CycleDiffusionPipeline, DDIMScheduler
38
+
39
+ # load the pipeline
40
+ # make sure you're logged in with `huggingface-cli login`
41
+ model_id_or_path = "CompVis/stable-diffusion-v1-4"
42
+ scheduler = DDIMScheduler.from_pretrained(model_id_or_path, subfolder="scheduler")
43
+ pipe = CycleDiffusionPipeline.from_pretrained(model_id_or_path, scheduler=scheduler).to("cuda")
44
+
45
+ # let's download an initial image
46
+ url = "https://raw.githubusercontent.com/ChenWu98/cycle-diffusion/main/data/dalle2/An%20astronaut%20riding%20a%20horse.png"
47
+ response = requests.get(url)
48
+ init_image = Image.open(BytesIO(response.content)).convert("RGB")
49
+ init_image = init_image.resize((512, 512))
50
+ init_image.save("horse.png")
51
+
52
+ # let's specify a prompt
53
+ source_prompt = "An astronaut riding a horse"
54
+ prompt = "An astronaut riding an elephant"
55
+
56
+ # call the pipeline
57
+ image = pipe(
58
+ prompt=prompt,
59
+ source_prompt=source_prompt,
60
+ init_image=init_image,
61
+ num_inference_steps=100,
62
+ eta=0.1,
63
+ strength=0.8,
64
+ guidance_scale=2,
65
+ source_guidance_scale=1,
66
+ ).images[0]
67
+
68
+ image.save("horse_to_elephant.png")
69
+
70
+ # let's try another example
71
+ # See more samples at the original repo: https://github.com/ChenWu98/cycle-diffusion
72
+ url = "https://raw.githubusercontent.com/ChenWu98/cycle-diffusion/main/data/dalle2/A%20black%20colored%20car.png"
73
+ response = requests.get(url)
74
+ init_image = Image.open(BytesIO(response.content)).convert("RGB")
75
+ init_image = init_image.resize((512, 512))
76
+ init_image.save("black.png")
77
+
78
+ source_prompt = "A black colored car"
79
+ prompt = "A blue colored car"
80
+
81
+ # call the pipeline
82
+ torch.manual_seed(0)
83
+ image = pipe(
84
+ prompt=prompt,
85
+ source_prompt=source_prompt,
86
+ init_image=init_image,
87
+ num_inference_steps=100,
88
+ eta=0.1,
89
+ strength=0.85,
90
+ guidance_scale=3,
91
+ source_guidance_scale=1,
92
+ ).images[0]
93
+
94
+ image.save("black_to_blue.png")
95
+ ```
96
+
97
+ ## CycleDiffusionPipeline
98
+ [[autodoc]] CycleDiffusionPipeline
99
+ - __call__
docs/source/api/pipelines/dance_diffusion.mdx ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Dance Diffusion
14
+
15
+ ## Overview
16
+
17
+ [Dance Diffusion](https://github.com/Harmonai-org/sample-generator) by Zach Evans.
18
+
19
+ Dance Diffusion is the first in a suite of generative audio tools for producers and musicians to be released by Harmonai.
20
+ For more info or to get involved in the development of these tools, please visit https://harmonai.org and fill out the form on the front page.
21
+
22
+ The original codebase of this implementation can be found [here](https://github.com/Harmonai-org/sample-generator).
23
+
24
+ ## Available Pipelines:
25
+
26
+ | Pipeline | Tasks | Colab
27
+ |---|---|:---:|
28
+ | [pipeline_dance_diffusion.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/dance_diffusion/pipeline_dance_diffusion.py) | *Unconditional Audio Generation* | - |
29
+
30
+
31
+ ## DanceDiffusionPipeline
32
+ [[autodoc]] DanceDiffusionPipeline
33
+ - __call__
docs/source/api/pipelines/ddim.mdx ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # DDIM
14
+
15
+ ## Overview
16
+
17
+ [Denoising Diffusion Implicit Models](https://arxiv.org/abs/2010.02502) (DDIM) by Jiaming Song, Chenlin Meng and Stefano Ermon.
18
+
19
+ The abstract of the paper is the following:
20
+
21
+ Denoising diffusion probabilistic models (DDPMs) have achieved high quality image generation without adversarial training, yet they require simulating a Markov chain for many steps to produce a sample. To accelerate sampling, we present denoising diffusion implicit models (DDIMs), a more efficient class of iterative implicit probabilistic models with the same training procedure as DDPMs. In DDPMs, the generative process is defined as the reverse of a Markovian diffusion process. We construct a class of non-Markovian diffusion processes that lead to the same training objective, but whose reverse process can be much faster to sample from. We empirically demonstrate that DDIMs can produce high quality samples 10× to 50× faster in terms of wall-clock time compared to DDPMs, allow us to trade off computation for sample quality, and can perform semantically meaningful image interpolation directly in the latent space.
22
+
23
+ The original codebase of this paper can be found here: [ermongroup/ddim](https://github.com/ermongroup/ddim).
24
+ For questions, feel free to contact the author on [tsong.me](https://tsong.me/).
25
+
26
+ ## Available Pipelines:
27
+
28
+ | Pipeline | Tasks | Colab
29
+ |---|---|:---:|
30
+ | [pipeline_ddim.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/ddim/pipeline_ddim.py) | *Unconditional Image Generation* | - |
31
+
32
+
33
+ ## DDIMPipeline
34
+ [[autodoc]] DDIMPipeline
35
+ - __call__
docs/source/api/pipelines/ddpm.mdx ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # DDPM
14
+
15
+ ## Overview
16
+
17
+ [Denoising Diffusion Probabilistic Models](https://arxiv.org/abs/2006.11239)
18
+ (DDPM) by Jonathan Ho, Ajay Jain and Pieter Abbeel proposes the diffusion based model of the same name, but in the context of the 🤗 Diffusers library, DDPM refers to the discrete denoising scheduler from the paper as well as the pipeline.
19
+
20
+ The abstract of the paper is the following:
21
+
22
+ We present high quality image synthesis results using diffusion probabilistic models, a class of latent variable models inspired by considerations from nonequilibrium thermodynamics. Our best results are obtained by training on a weighted variational bound designed according to a novel connection between diffusion probabilistic models and denoising score matching with Langevin dynamics, and our models naturally admit a progressive lossy decompression scheme that can be interpreted as a generalization of autoregressive decoding. On the unconditional CIFAR10 dataset, we obtain an Inception score of 9.46 and a state-of-the-art FID score of 3.17. On 256x256 LSUN, we obtain sample quality similar to ProgressiveGAN.
23
+
24
+ The original codebase of this paper can be found [here](https://github.com/hojonathanho/diffusion).
25
+
26
+
27
+ ## Available Pipelines:
28
+
29
+ | Pipeline | Tasks | Colab
30
+ |---|---|:---:|
31
+ | [pipeline_ddpm.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/ddpm/pipeline_ddpm.py) | *Unconditional Image Generation* | - |
32
+
33
+
34
+ # DDPMPipeline
35
+ [[autodoc]] DDPMPipeline
36
+ - __call__
docs/source/api/pipelines/latent_diffusion.mdx ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Latent Diffusion
14
+
15
+ ## Overview
16
+
17
+ Latent Diffusion was proposed in [High-Resolution Image Synthesis with Latent Diffusion Models](https://arxiv.org/abs/2112.10752) by Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer.
18
+
19
+ The abstract of the paper is the following:
20
+
21
+ *By decomposing the image formation process into a sequential application of denoising autoencoders, diffusion models (DMs) achieve state-of-the-art synthesis results on image data and beyond. Additionally, their formulation allows for a guiding mechanism to control the image generation process without retraining. However, since these models typically operate directly in pixel space, optimization of powerful DMs often consumes hundreds of GPU days and inference is expensive due to sequential evaluations. To enable DM training on limited computational resources while retaining their quality and flexibility, we apply them in the latent space of powerful pretrained autoencoders. In contrast to previous work, training diffusion models on such a representation allows for the first time to reach a near-optimal point between complexity reduction and detail preservation, greatly boosting visual fidelity. By introducing cross-attention layers into the model architecture, we turn diffusion models into powerful and flexible generators for general conditioning inputs such as text or bounding boxes and high-resolution synthesis becomes possible in a convolutional manner. Our latent diffusion models (LDMs) achieve a new state of the art for image inpainting and highly competitive performance on various tasks, including unconditional image generation, semantic scene synthesis, and super-resolution, while significantly reducing computational requirements compared to pixel-based DMs.*
22
+
23
+ The original codebase can be found [here](https://github.com/CompVis/latent-diffusion).
24
+
25
+ ## Tips:
26
+
27
+ -
28
+ -
29
+ -
30
+
31
+ ## Available Pipelines:
32
+
33
+ | Pipeline | Tasks | Colab
34
+ |---|---|:---:|
35
+ | [pipeline_latent_diffusion.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion.py) | *Text-to-Image Generation* | - |
36
+ | [pipeline_latent_diffusion_superresolution.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/latent_diffusion/pipeline_latent_diffusion_superresolution.py) | *Super Resolution* | - |
37
+
38
+ ## Examples:
39
+
40
+
41
+ ## LDMTextToImagePipeline
42
+ [[autodoc]] LDMTextToImagePipeline
43
+ - __call__
44
+
45
+ ## LDMSuperResolutionPipeline
46
+ [[autodoc]] LDMSuperResolutionPipeline
47
+ - __call__
docs/source/api/pipelines/latent_diffusion_uncond.mdx ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Unconditional Latent Diffusion
14
+
15
+ ## Overview
16
+
17
+ Unconditional Latent Diffusion was proposed in [High-Resolution Image Synthesis with Latent Diffusion Models](https://arxiv.org/abs/2112.10752) by Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer.
18
+
19
+ The abstract of the paper is the following:
20
+
21
+ *By decomposing the image formation process into a sequential application of denoising autoencoders, diffusion models (DMs) achieve state-of-the-art synthesis results on image data and beyond. Additionally, their formulation allows for a guiding mechanism to control the image generation process without retraining. However, since these models typically operate directly in pixel space, optimization of powerful DMs often consumes hundreds of GPU days and inference is expensive due to sequential evaluations. To enable DM training on limited computational resources while retaining their quality and flexibility, we apply them in the latent space of powerful pretrained autoencoders. In contrast to previous work, training diffusion models on such a representation allows for the first time to reach a near-optimal point between complexity reduction and detail preservation, greatly boosting visual fidelity. By introducing cross-attention layers into the model architecture, we turn diffusion models into powerful and flexible generators for general conditioning inputs such as text or bounding boxes and high-resolution synthesis becomes possible in a convolutional manner. Our latent diffusion models (LDMs) achieve a new state of the art for image inpainting and highly competitive performance on various tasks, including unconditional image generation, semantic scene synthesis, and super-resolution, while significantly reducing computational requirements compared to pixel-based DMs.*
22
+
23
+ The original codebase can be found [here](https://github.com/CompVis/latent-diffusion).
24
+
25
+ ## Tips:
26
+
27
+ -
28
+ -
29
+ -
30
+
31
+ ## Available Pipelines:
32
+
33
+ | Pipeline | Tasks | Colab
34
+ |---|---|:---:|
35
+ | [pipeline_latent_diffusion_uncond.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/latent_diffusion_uncond/pipeline_latent_diffusion_uncond.py) | *Unconditional Image Generation* | - |
36
+
37
+ ## Examples:
38
+
39
+ ## LDMPipeline
40
+ [[autodoc]] LDMPipeline
41
+ - __call__
docs/source/api/pipelines/overview.mdx ADDED
@@ -0,0 +1,191 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Pipelines
14
+
15
+ Pipelines provide a simple way to run state-of-the-art diffusion models in inference.
16
+ Most diffusion systems consist of multiple independently-trained models and highly adaptable scheduler
17
+ components - all of which are needed to have a functioning end-to-end diffusion system.
18
+
19
+ As an example, [Stable Diffusion](https://huggingface.co/blog/stable_diffusion) has three independently trained models:
20
+ - [Autoencoder](./api/models#vae)
21
+ - [Conditional Unet](./api/models#UNet2DConditionModel)
22
+ - [CLIP text encoder](https://huggingface.co/docs/transformers/v4.21.2/en/model_doc/clip#transformers.CLIPTextModel)
23
+ - a scheduler component, [scheduler](./api/scheduler#pndm),
24
+ - a [CLIPFeatureExtractor](https://huggingface.co/docs/transformers/v4.21.2/en/model_doc/clip#transformers.CLIPFeatureExtractor),
25
+ - as well as a [safety checker](./stable_diffusion#safety_checker).
26
+ All of these components are necessary to run stable diffusion in inference even though they were trained
27
+ or created independently from each other.
28
+
29
+ To that end, we strive to offer all open-sourced, state-of-the-art diffusion system under a unified API.
30
+ More specifically, we strive to provide pipelines that
31
+ - 1. can load the officially published weights and yield 1-to-1 the same outputs as the original implementation according to the corresponding paper (*e.g.* [LDMTextToImagePipeline](https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines/latent_diffusion), uses the officially released weights of [High-Resolution Image Synthesis with Latent Diffusion Models](https://arxiv.org/abs/2112.10752)),
32
+ - 2. have a simple user interface to run the model in inference (see the [Pipelines API](#pipelines-api) section),
33
+ - 3. are easy to understand with code that is self-explanatory and can be read along-side the official paper (see [Pipelines summary](#pipelines-summary)),
34
+ - 4. can easily be contributed by the community (see the [Contribution](#contribution) section).
35
+
36
+ **Note** that pipelines do not (and should not) offer any training functionality.
37
+ If you are looking for *official* training examples, please have a look at [examples](https://github.com/huggingface/diffusers/tree/main/examples).
38
+
39
+ ## 🧨 Diffusers Summary
40
+
41
+ The following table summarizes all officially supported pipelines, their corresponding paper, and if
42
+ available a colab notebook to directly try them out.
43
+
44
+
45
+ | Pipeline | Paper | Tasks | Colab
46
+ |---|---|:---:|:---:|
47
+ | [alt_diffusion](./api/pipelines/alt_diffusion) | [**AltDiffusion**](https://arxiv.org/abs/2211.06679) | Image-to-Image Text-Guided Generation | -
48
+ | [cycle_diffusion](./api/pipelines/cycle_diffusion) | [**Cycle Diffusion**](https://arxiv.org/abs/2210.05559) | Image-to-Image Text-Guided Generation |
49
+ | [dance_diffusion](./api/pipelines/dance_diffusion) | [**Dance Diffusion**](https://github.com/williamberman/diffusers.git) | Unconditional Audio Generation |
50
+ | [ddpm](./api/pipelines/ddpm) | [**Denoising Diffusion Probabilistic Models**](https://arxiv.org/abs/2006.11239) | Unconditional Image Generation |
51
+ | [ddim](./api/pipelines/ddim) | [**Denoising Diffusion Implicit Models**](https://arxiv.org/abs/2010.02502) | Unconditional Image Generation |
52
+ | [latent_diffusion](./api/pipelines/latent_diffusion) | [**High-Resolution Image Synthesis with Latent Diffusion Models**](https://arxiv.org/abs/2112.10752)| Text-to-Image Generation |
53
+ | [latent_diffusion](./api/pipelines/latent_diffusion) | [**High-Resolution Image Synthesis with Latent Diffusion Models**](https://arxiv.org/abs/2112.10752)| Super Resolution Image-to-Image |
54
+ | [latent_diffusion_uncond](./api/pipelines/latent_diffusion_uncond) | [**High-Resolution Image Synthesis with Latent Diffusion Models**](https://arxiv.org/abs/2112.10752) | Unconditional Image Generation |
55
+ | [pndm](./api/pipelines/pndm) | [**Pseudo Numerical Methods for Diffusion Models on Manifolds**](https://arxiv.org/abs/2202.09778) | Unconditional Image Generation |
56
+ | [score_sde_ve](./api/pipelines/score_sde_ve) | [**Score-Based Generative Modeling through Stochastic Differential Equations**](https://openreview.net/forum?id=PxTIG12RRHS) | Unconditional Image Generation |
57
+ | [score_sde_vp](./api/pipelines/score_sde_vp) | [**Score-Based Generative Modeling through Stochastic Differential Equations**](https://openreview.net/forum?id=PxTIG12RRHS) | Unconditional Image Generation |
58
+ | [stable_diffusion](./api/pipelines/stable_diffusion) | [**Stable Diffusion**](https://stability.ai/blog/stable-diffusion-public-release) | Text-to-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)
59
+ | [stable_diffusion](./api/pipelines/stable_diffusion) | [**Stable Diffusion**](https://stability.ai/blog/stable-diffusion-public-release) | Image-to-Image Text-Guided Generation | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/image_2_image_using_diffusers.ipynb)
60
+ | [stable_diffusion](./api/pipelines/stable_diffusion) | [**Stable Diffusion**](https://stability.ai/blog/stable-diffusion-public-release) | Text-Guided Image Inpainting | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb)
61
+ | [stochastic_karras_ve](./api/pipelines/stochastic_karras_ve) | [**Elucidating the Design Space of Diffusion-Based Generative Models**](https://arxiv.org/abs/2206.00364) | Unconditional Image Generation |
62
+ | [vq_diffusion](./api/pipelines/vq_diffusion) | [Vector Quantized Diffusion Model for Text-to-Image Synthesis](https://arxiv.org/abs/2111.14822) | Text-to-Image Generation |
63
+
64
+
65
+ **Note**: Pipelines are simple examples of how to play around with the diffusion systems as described in the corresponding papers.
66
+
67
+ However, most of them can be adapted to use different scheduler components or even different model components. Some pipeline examples are shown in the [Examples](#examples) below.
68
+
69
+ ## Pipelines API
70
+
71
+ Diffusion models often consist of multiple independently-trained models or other previously existing components.
72
+
73
+
74
+ Each model has been trained independently on a different task and the scheduler can easily be swapped out and replaced with a different one.
75
+ During inference, we however want to be able to easily load all components and use them in inference - even if one component, *e.g.* CLIP's text encoder, originates from a different library, such as [Transformers](https://github.com/huggingface/transformers). To that end, all pipelines provide the following functionality:
76
+
77
+ - [`from_pretrained` method](../diffusion_pipeline) that accepts a Hugging Face Hub repository id, *e.g.* [runwayml/stable-diffusion-v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5) or a path to a local directory, *e.g.*
78
+ "./stable-diffusion". To correctly retrieve which models and components should be loaded, one has to provide a `model_index.json` file, *e.g.* [runwayml/stable-diffusion-v1-5/model_index.json](https://huggingface.co/runwayml/stable-diffusion-v1-5/blob/main/model_index.json), which defines all components that should be
79
+ loaded into the pipelines. More specifically, for each model/component one needs to define the format `<name>: ["<library>", "<class name>"]`. `<name>` is the attribute name given to the loaded instance of `<class name>` which can be found in the library or pipeline folder called `"<library>"`.
80
+ - [`save_pretrained`](../diffusion_pipeline) that accepts a local path, *e.g.* `./stable-diffusion` under which all models/components of the pipeline will be saved. For each component/model a folder is created inside the local path that is named after the given attribute name, *e.g.* `./stable_diffusion/unet`.
81
+ In addition, a `model_index.json` file is created at the root of the local path, *e.g.* `./stable_diffusion/model_index.json` so that the complete pipeline can again be instantiated
82
+ from the local path.
83
+ - [`to`](../diffusion_pipeline) which accepts a `string` or `torch.device` to move all models that are of type `torch.nn.Module` to the passed device. The behavior is fully analogous to [PyTorch's `to` method](https://pytorch.org/docs/stable/generated/torch.nn.Module.html#torch.nn.Module.to).
84
+ - [`__call__`] method to use the pipeline in inference. `__call__` defines inference logic of the pipeline and should ideally encompass all aspects of it, from pre-processing to forwarding tensors to the different models and schedulers, as well as post-processing. The API of the `__call__` method can strongly vary from pipeline to pipeline. *E.g.* a text-to-image pipeline, such as [`StableDiffusionPipeline`](./stable_diffusion) should accept among other things the text prompt to generate the image. A pure image generation pipeline, such as [DDPMPipeline](https://github.com/huggingface/diffusers/tree/main/src/diffusers/pipelines/ddpm) on the other hand can be run without providing any inputs. To better understand what inputs can be adapted for
85
+ each pipeline, one should look directly into the respective pipeline.
86
+
87
+ **Note**: All pipelines have PyTorch's autograd disabled by decorating the `__call__` method with a [`torch.no_grad`](https://pytorch.org/docs/stable/generated/torch.no_grad.html) decorator because pipelines should
88
+ not be used for training. If you want to store the gradients during the forward pass, we recommend writing your own pipeline, see also our [community-examples](https://github.com/huggingface/diffusers/tree/main/examples/community)
89
+
90
+ ## Contribution
91
+
92
+ We are more than happy about any contribution to the officially supported pipelines 🤗. We aspire
93
+ all of our pipelines to be **self-contained**, **easy-to-tweak**, **beginner-friendly** and for **one-purpose-only**.
94
+
95
+ - **Self-contained**: A pipeline shall be as self-contained as possible. More specifically, this means that all functionality should be either directly defined in the pipeline file itself, should be inherited from (and only from) the [`DiffusionPipeline` class](.../diffusion_pipeline) or be directly attached to the model and scheduler components of the pipeline.
96
+ - **Easy-to-use**: Pipelines should be extremely easy to use - one should be able to load the pipeline and
97
+ use it for its designated task, *e.g.* text-to-image generation, in just a couple of lines of code. Most
98
+ logic including pre-processing, an unrolled diffusion loop, and post-processing should all happen inside the `__call__` method.
99
+ - **Easy-to-tweak**: Certain pipelines will not be able to handle all use cases and tasks that you might like them to. If you want to use a certain pipeline for a specific use case that is not yet supported, you might have to copy the pipeline file and tweak the code to your needs. We try to make the pipeline code as readable as possible so that each part –from pre-processing to diffusing to post-processing– can easily be adapted. If you would like the community to benefit from your customized pipeline, we would love to see a contribution to our [community-examples](https://github.com/huggingface/diffusers/tree/main/examples/community). If you feel that an important pipeline should be part of the official pipelines but isn't, a contribution to the [official pipelines](./overview) would be even better.
100
+ - **One-purpose-only**: Pipelines should be used for one task and one task only. Even if two tasks are very similar from a modeling point of view, *e.g.* image2image translation and in-painting, pipelines shall be used for one task only to keep them *easy-to-tweak* and *readable*.
101
+
102
+ ## Examples
103
+
104
+ ### Text-to-Image generation with Stable Diffusion
105
+
106
+ ```python
107
+ # make sure you're logged in with `huggingface-cli login`
108
+ from diffusers import StableDiffusionPipeline, LMSDiscreteScheduler
109
+
110
+ pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
111
+ pipe = pipe.to("cuda")
112
+
113
+ prompt = "a photo of an astronaut riding a horse on mars"
114
+ image = pipe(prompt).images[0]
115
+
116
+ image.save("astronaut_rides_horse.png")
117
+ ```
118
+
119
+ ### Image-to-Image text-guided generation with Stable Diffusion
120
+
121
+ The `StableDiffusionImg2ImgPipeline` lets you pass a text prompt and an initial image to condition the generation of new images.
122
+
123
+ ```python
124
+ import requests
125
+ from PIL import Image
126
+ from io import BytesIO
127
+
128
+ from diffusers import StableDiffusionImg2ImgPipeline
129
+
130
+ # load the pipeline
131
+ device = "cuda"
132
+ pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
133
+ "runwayml/stable-diffusion-v1-5", revision="fp16", torch_dtype=torch.float16
134
+ ).to(device)
135
+
136
+ # let's download an initial image
137
+ url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
138
+
139
+ response = requests.get(url)
140
+ init_image = Image.open(BytesIO(response.content)).convert("RGB")
141
+ init_image = init_image.resize((768, 512))
142
+
143
+ prompt = "A fantasy landscape, trending on artstation"
144
+
145
+ images = pipe(prompt=prompt, init_image=init_image, strength=0.75, guidance_scale=7.5).images
146
+
147
+ images[0].save("fantasy_landscape.png")
148
+ ```
149
+ You can also run this example on colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/image_2_image_using_diffusers.ipynb)
150
+
151
+ ### Tweak prompts reusing seeds and latents
152
+
153
+ You can generate your own latents to reproduce results, or tweak your prompt on a specific result you liked. [This notebook](https://github.com/pcuenca/diffusers-examples/blob/main/notebooks/stable-diffusion-seeds.ipynb) shows how to do it step by step. You can also run it in Google Colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pcuenca/diffusers-examples/blob/main/notebooks/stable-diffusion-seeds.ipynb).
154
+
155
+
156
+ ### In-painting using Stable Diffusion
157
+
158
+ The `StableDiffusionInpaintPipeline` lets you edit specific parts of an image by providing a mask and text prompt.
159
+
160
+ ```python
161
+ import PIL
162
+ import requests
163
+ import torch
164
+ from io import BytesIO
165
+
166
+ from diffusers import StableDiffusionInpaintPipeline
167
+
168
+
169
+ def download_image(url):
170
+ response = requests.get(url)
171
+ return PIL.Image.open(BytesIO(response.content)).convert("RGB")
172
+
173
+
174
+ img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
175
+ mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"
176
+
177
+ init_image = download_image(img_url).resize((512, 512))
178
+ mask_image = download_image(mask_url).resize((512, 512))
179
+
180
+ pipe = StableDiffusionInpaintPipeline.from_pretrained(
181
+ "runwayml/stable-diffusion-inpainting",
182
+ revision="fp16",
183
+ torch_dtype=torch.float16,
184
+ )
185
+ pipe = pipe.to("cuda")
186
+
187
+ prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
188
+ image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]
189
+ ```
190
+
191
+ You can also run this example on colab [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb)
docs/source/api/pipelines/pndm.mdx ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # PNDM
14
+
15
+ ## Overview
16
+
17
+ [Pseudo Numerical methods for Diffusion Models on manifolds](https://arxiv.org/abs/2202.09778) (PNDM) by Luping Liu, Yi Ren, Zhijie Lin and Zhou Zhao.
18
+
19
+ The abstract of the paper is the following:
20
+
21
+ Denoising Diffusion Probabilistic Models (DDPMs) can generate high-quality samples such as image and audio samples. However, DDPMs require hundreds to thousands of iterations to produce final samples. Several prior works have successfully accelerated DDPMs through adjusting the variance schedule (e.g., Improved Denoising Diffusion Probabilistic Models) or the denoising equation (e.g., Denoising Diffusion Implicit Models (DDIMs)). However, these acceleration methods cannot maintain the quality of samples and even introduce new noise at a high speedup rate, which limit their practicability. To accelerate the inference process while keeping the sample quality, we provide a fresh perspective that DDPMs should be treated as solving differential equations on manifolds. Under such a perspective, we propose pseudo numerical methods for diffusion models (PNDMs). Specifically, we figure out how to solve differential equations on manifolds and show that DDIMs are simple cases of pseudo numerical methods. We change several classical numerical methods to corresponding pseudo numerical methods and find that the pseudo linear multi-step method is the best in most situations. According to our experiments, by directly using pre-trained models on Cifar10, CelebA and LSUN, PNDMs can generate higher quality synthetic images with only 50 steps compared with 1000-step DDIMs (20x speedup), significantly outperform DDIMs with 250 steps (by around 0.4 in FID) and have good generalization on different variance schedules.
22
+
23
+ The original codebase can be found [here](https://github.com/luping-liu/PNDM).
24
+
25
+ ## Available Pipelines:
26
+
27
+ | Pipeline | Tasks | Colab
28
+ |---|---|:---:|
29
+ | [pipeline_pndm.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pndm/pipeline_pndm.py) | *Unconditional Image Generation* | - |
30
+
31
+
32
+ ## PNDMPipeline
33
+ [[autodoc]] pipelines.pndm.pipeline_pndm.PNDMPipeline
34
+ - __call__
35
+
docs/source/api/pipelines/repaint.mdx ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # RePaint
14
+
15
+ ## Overview
16
+
17
+ [RePaint: Inpainting using Denoising Diffusion Probabilistic Models](https://arxiv.org/abs/2201.09865) (PNDM) by Andreas Lugmayr, Martin Danelljan, Andres Romero, Fisher Yu, Radu Timofte, Luc Van Gool.
18
+
19
+ The abstract of the paper is the following:
20
+
21
+ Free-form inpainting is the task of adding new content to an image in the regions specified by an arbitrary binary mask. Most existing approaches train for a certain distribution of masks, which limits their generalization capabilities to unseen mask types. Furthermore, training with pixel-wise and perceptual losses often leads to simple textural extensions towards the missing areas instead of semantically meaningful generation. In this work, we propose RePaint: A Denoising Diffusion Probabilistic Model (DDPM) based inpainting approach that is applicable to even extreme masks. We employ a pretrained unconditional DDPM as the generative prior. To condition the generation process, we only alter the reverse diffusion iterations by sampling the unmasked regions using the given image information. Since this technique does not modify or condition the original DDPM network itself, the model produces high-quality and diverse output images for any inpainting form. We validate our method for both faces and general-purpose image inpainting using standard and extreme masks.
22
+ RePaint outperforms state-of-the-art Autoregressive, and GAN approaches for at least five out of six mask distributions.
23
+
24
+ The original codebase can be found [here](https://github.com/andreas128/RePaint).
25
+
26
+ ## Available Pipelines:
27
+
28
+ | Pipeline | Tasks | Colab
29
+ |-------------------------------------------------------------------------------------------------------------------------------|--------------------|:---:|
30
+ | [pipeline_repaint.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/repaint/pipeline_repaint.py) | *Image Inpainting* | - |
31
+
32
+ ## Usage example
33
+
34
+ ```python
35
+ from io import BytesIO
36
+
37
+ import torch
38
+
39
+ import PIL
40
+ import requests
41
+ from diffusers import RePaintPipeline, RePaintScheduler
42
+
43
+
44
+ def download_image(url):
45
+ response = requests.get(url)
46
+ return PIL.Image.open(BytesIO(response.content)).convert("RGB")
47
+
48
+
49
+ img_url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/repaint/celeba_hq_256.png"
50
+ mask_url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/repaint/mask_256.png"
51
+
52
+ # Load the original image and the mask as PIL images
53
+ original_image = download_image(img_url).resize((256, 256))
54
+ mask_image = download_image(mask_url).resize((256, 256))
55
+
56
+ # Load the RePaint scheduler and pipeline based on a pretrained DDPM model
57
+ scheduler = RePaintScheduler.from_pretrained("google/ddpm-ema-celebahq-256")
58
+ pipe = RePaintPipeline.from_pretrained("google/ddpm-ema-celebahq-256", scheduler=scheduler)
59
+ pipe = pipe.to("cuda")
60
+
61
+ generator = torch.Generator(device="cuda").manual_seed(0)
62
+ output = pipe(
63
+ original_image=original_image,
64
+ mask_image=mask_image,
65
+ num_inference_steps=250,
66
+ eta=0.0,
67
+ jump_length=10,
68
+ jump_n_sample=10,
69
+ generator=generator,
70
+ )
71
+ inpainted_image = output.images[0]
72
+ ```
73
+
74
+ ## RePaintPipeline
75
+ [[autodoc]] pipelines.repaint.pipeline_repaint.RePaintPipeline
76
+ - __call__
77
+
docs/source/api/pipelines/score_sde_ve.mdx ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Score SDE VE
14
+
15
+ ## Overview
16
+
17
+ [Score-Based Generative Modeling through Stochastic Differential Equations](https://arxiv.org/abs/2011.13456) (Score SDE) by Yang Song, Jascha Sohl-Dickstein, Diederik P. Kingma, Abhishek Kumar, Stefano Ermon and Ben Poole.
18
+
19
+ The abstract of the paper is the following:
20
+
21
+ Creating noise from data is easy; creating data from noise is generative modeling. We present a stochastic differential equation (SDE) that smoothly transforms a complex data distribution to a known prior distribution by slowly injecting noise, and a corresponding reverse-time SDE that transforms the prior distribution back into the data distribution by slowly removing the noise. Crucially, the reverse-time SDE depends only on the time-dependent gradient field (\aka, score) of the perturbed data distribution. By leveraging advances in score-based generative modeling, we can accurately estimate these scores with neural networks, and use numerical SDE solvers to generate samples. We show that this framework encapsulates previous approaches in score-based generative modeling and diffusion probabilistic modeling, allowing for new sampling procedures and new modeling capabilities. In particular, we introduce a predictor-corrector framework to correct errors in the evolution of the discretized reverse-time SDE. We also derive an equivalent neural ODE that samples from the same distribution as the SDE, but additionally enables exact likelihood computation, and improved sampling efficiency. In addition, we provide a new way to solve inverse problems with score-based models, as demonstrated with experiments on class-conditional generation, image inpainting, and colorization. Combined with multiple architectural improvements, we achieve record-breaking performance for unconditional image generation on CIFAR-10 with an Inception score of 9.89 and FID of 2.20, a competitive likelihood of 2.99 bits/dim, and demonstrate high fidelity generation of 1024 x 1024 images for the first time from a score-based generative model.
22
+
23
+ The original codebase can be found [here](https://github.com/yang-song/score_sde_pytorch).
24
+
25
+ This pipeline implements the Variance Expanding (VE) variant of the method.
26
+
27
+ ## Available Pipelines:
28
+
29
+ | Pipeline | Tasks | Colab
30
+ |---|---|:---:|
31
+ | [pipeline_score_sde_ve.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/score_sde_ve/pipeline_score_sde_ve.py) | *Unconditional Image Generation* | - |
32
+
33
+ ## ScoreSdeVePipeline
34
+ [[autodoc]] ScoreSdeVePipeline
35
+ - __call__
36
+
docs/source/api/pipelines/stable_diffusion.mdx ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Stable diffusion pipelines
14
+
15
+ Stable Diffusion is a text-to-image _latent diffusion_ model created by the researchers and engineers from [CompVis](https://github.com/CompVis), [Stability AI](https://stability.ai/) and [LAION](https://laion.ai/). It's trained on 512x512 images from a subset of the [LAION-5B](https://laion.ai/blog/laion-5b/) dataset. This model uses a frozen CLIP ViT-L/14 text encoder to condition the model on text prompts. With its 860M UNet and 123M text encoder, the model is relatively lightweight and can run on consumer GPUs.
16
+
17
+ Latent diffusion is the research on top of which Stable Diffusion was built. It was proposed in [High-Resolution Image Synthesis with Latent Diffusion Models](https://arxiv.org/abs/2112.10752) by Robin Rombach, Andreas Blattmann, Dominik Lorenz, Patrick Esser, Björn Ommer. You can learn more details about it in the [specific pipeline for latent diffusion](pipelines/latent_diffusion) that is part of 🤗 Diffusers.
18
+
19
+ For more details about how Stable Diffusion works and how it differs from the base latent diffusion model, please refer to the official [launch announcement post](https://stability.ai/blog/stable-diffusion-announcement) and [this section of our own blog post](https://huggingface.co/blog/stable_diffusion#how-does-stable-diffusion-work).
20
+
21
+ *Tips*:
22
+ - To tweak your prompts on a specific result you liked, you can generate your own latents, as demonstrated in the following notebook: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pcuenca/diffusers-examples/blob/main/notebooks/stable-diffusion-seeds.ipynb)
23
+
24
+ *Overview*:
25
+
26
+ | Pipeline | Tasks | Colab | Demo
27
+ |---|---|:---:|:---:|
28
+ | [pipeline_stable_diffusion.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py) | *Text-to-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/stable_diffusion.ipynb) | [🤗 Stable Diffusion](https://huggingface.co/spaces/stabilityai/stable-diffusion)
29
+ | [pipeline_stable_diffusion_img2img.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py) | *Image-to-Image Text-Guided Generation* | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/image_2_image_using_diffusers.ipynb) | [🤗 Diffuse the Rest](https://huggingface.co/spaces/huggingface/diffuse-the-rest)
30
+ | [pipeline_stable_diffusion_inpaint.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py) | **Experimental** – *Text-Guided Image Inpainting* | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/in_painting_with_stable_diffusion_using_diffusers.ipynb) | Coming soon
31
+
32
+ ## Tips
33
+
34
+ ### How to load and use different schedulers.
35
+
36
+ The stable diffusion pipeline uses [`PNDMScheduler`] scheduler by default. But `diffusers` provides many other schedulers that can be used with the stable diffusion pipeline such as [`DDIMScheduler`], [`LMSDiscreteScheduler`], [`EulerDiscreteScheduler`], [`EulerAncestralDiscreteScheduler`] etc.
37
+ To use a different scheduler, you can either change it via the [`ConfigMixin.from_config`] method or pass the `scheduler` argument to the `from_pretrained` method of the pipeline. For example, to use the [`EulerDiscreteScheduler`], you can do the following:
38
+
39
+ ```python
40
+ >>> from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
41
+
42
+ >>> pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
43
+ >>> pipeline.scheduler = EulerDiscreteScheduler.from_config(pipeline.scheduler.config)
44
+
45
+ >>> # or
46
+ >>> euler_scheduler = EulerDiscreteScheduler.from_pretrained("CompVis/stable-diffusion-v1-4", subfolder="scheduler")
47
+ >>> pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", scheduler=euler_scheduler)
48
+ ```
49
+
50
+
51
+ ### How to conver all use cases with multiple or single pipeline
52
+
53
+ If you want to use all possible use cases in a single `DiffusionPipeline` you can either:
54
+ - Make use of the [Stable Diffusion Mega Pipeline](https://github.com/huggingface/diffusers/tree/main/examples/community#stable-diffusion-mega) or
55
+ - Make use of the `components` functionality to instantiate all components in the most memory-efficient way:
56
+
57
+ ```python
58
+ >>> from diffusers import (
59
+ ... StableDiffusionPipeline,
60
+ ... StableDiffusionImg2ImgPipeline,
61
+ ... StableDiffusionInpaintPipeline,
62
+ ... )
63
+
64
+ >>> text2img = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4")
65
+ >>> img2img = StableDiffusionImg2ImgPipeline(**text2img.components)
66
+ >>> inpaint = StableDiffusionInpaintPipeline(**text2img.components)
67
+
68
+ >>> # now you can use text2img(...), img2img(...), inpaint(...) just like the call methods of each respective pipeline
69
+ ```
70
+
71
+ ## StableDiffusionPipelineOutput
72
+ [[autodoc]] pipelines.stable_diffusion.StableDiffusionPipelineOutput
73
+
74
+ ## StableDiffusionPipeline
75
+ [[autodoc]] StableDiffusionPipeline
76
+ - __call__
77
+ - enable_attention_slicing
78
+ - disable_attention_slicing
79
+
80
+ ## StableDiffusionImg2ImgPipeline
81
+ [[autodoc]] StableDiffusionImg2ImgPipeline
82
+ - __call__
83
+ - enable_attention_slicing
84
+ - disable_attention_slicing
85
+
86
+ ## StableDiffusionInpaintPipeline
87
+ [[autodoc]] StableDiffusionInpaintPipeline
88
+ - __call__
89
+ - enable_attention_slicing
90
+ - disable_attention_slicing
docs/source/api/pipelines/stochastic_karras_ve.mdx ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # Stochastic Karras VE
14
+
15
+ ## Overview
16
+
17
+ [Elucidating the Design Space of Diffusion-Based Generative Models](https://arxiv.org/abs/2206.00364) by Tero Karras, Miika Aittala, Timo Aila and Samuli Laine.
18
+
19
+ The abstract of the paper is the following:
20
+
21
+ We argue that the theory and practice of diffusion-based generative models are currently unnecessarily convoluted and seek to remedy the situation by presenting a design space that clearly separates the concrete design choices. This lets us identify several changes to both the sampling and training processes, as well as preconditioning of the score networks. Together, our improvements yield new state-of-the-art FID of 1.79 for CIFAR-10 in a class-conditional setting and 1.97 in an unconditional setting, with much faster sampling (35 network evaluations per image) than prior designs. To further demonstrate their modular nature, we show that our design changes dramatically improve both the efficiency and quality obtainable with pre-trained score networks from previous work, including improving the FID of an existing ImageNet-64 model from 2.07 to near-SOTA 1.55.
22
+
23
+ This pipeline implements the Stochastic sampling tailored to the Variance-Expanding (VE) models.
24
+
25
+
26
+ ## Available Pipelines:
27
+
28
+ | Pipeline | Tasks | Colab
29
+ |---|---|:---:|
30
+ | [pipeline_stochastic_karras_ve.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stochastic_karras_ve/pipeline_stochastic_karras_ve.py) | *Unconditional Image Generation* | - |
31
+
32
+
33
+ ## KarrasVePipeline
34
+ [[autodoc]] KarrasVePipeline
35
+ - __call__
docs/source/api/pipelines/vq_diffusion.mdx ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--Copyright 2022 The HuggingFace Team. All rights reserved.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
4
+ the License. You may obtain a copy of the License at
5
+
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+
8
+ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9
+ an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10
+ specific language governing permissions and limitations under the License.
11
+ -->
12
+
13
+ # VQDiffusion
14
+
15
+ ## Overview
16
+
17
+ [Vector Quantized Diffusion Model for Text-to-Image Synthesis](https://arxiv.org/abs/2111.14822) by Shuyang Gu, Dong Chen, Jianmin Bao, Fang Wen, Bo Zhang, Dongdong Chen, Lu Yuan, Baining Guo
18
+
19
+ The abstract of the paper is the following:
20
+
21
+ We present the vector quantized diffusion (VQ-Diffusion) model for text-to-image generation. This method is based on a vector quantized variational autoencoder (VQ-VAE) whose latent space is modeled by a conditional variant of the recently developed Denoising Diffusion Probabilistic Model (DDPM). We find that this latent-space method is well-suited for text-to-image generation tasks because it not only eliminates the unidirectional bias with existing methods but also allows us to incorporate a mask-and-replace diffusion strategy to avoid the accumulation of errors, which is a serious problem with existing methods. Our experiments show that the VQ-Diffusion produces significantly better text-to-image generation results when compared with conventional autoregressive (AR) models with similar numbers of parameters. Compared with previous GAN-based text-to-image methods, our VQ-Diffusion can handle more complex scenes and improve the synthesized image quality by a large margin. Finally, we show that the image generation computation in our method can be made highly efficient by reparameterization. With traditional AR methods, the text-to-image generation time increases linearly with the output image resolution and hence is quite time consuming even for normal size images. The VQ-Diffusion allows us to achieve a better trade-off between quality and speed. Our experiments indicate that the VQ-Diffusion model with the reparameterization is fifteen times faster than traditional AR methods while achieving a better image quality.
22
+
23
+ The original codebase can be found [here](https://github.com/microsoft/VQ-Diffusion).
24
+
25
+ ## Available Pipelines:
26
+
27
+ | Pipeline | Tasks | Colab
28
+ |---|---|:---:|
29
+ | [pipeline_vq_diffusion.py](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/vq_diffusion/pipeline_vq_diffusion.py) | *Text-to-Image Generation* | - |
30
+
31
+
32
+ ## VQDiffusionPipeline
33
+ [[autodoc]] pipelines.vq_diffusion.pipeline_vq_diffusion.VQDiffusionPipeline
34
+ - __call__