Skip to content

use 🧨diffusers model #1384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
860adf6
lint(ldm.invoke.generator): 🚮 remove unused imports
keturn Nov 5, 2022
e6176df
Merge branch 'development' into dev/diffusers
keturn Nov 9, 2022
e7794c0
initial commit of DiffusionPipeline class
keturn Nov 9, 2022
d009a09
spike: proof of concept using diffusers for txt2img
keturn Nov 9, 2022
1740187
Merge remote-tracking branch 'keturn/dev/diffusers' into dev/diffusers
keturn Nov 9, 2022
d4ccd08
Merge branch 'development' into dev/diffusers
keturn Nov 9, 2022
a267b45
doc: type hints for Generator
keturn Nov 9, 2022
9f5e496
refactor(model_cache): factor out load_ckpt
keturn Nov 9, 2022
b39d04d
model_cache: add ability to load a diffusers model pipeline
keturn Nov 10, 2022
f49317c
model_cache: fix model default image dimensions
keturn Nov 10, 2022
8a19891
Merge branch 'development' into dev/diffusers
keturn Nov 10, 2022
8db7054
txt2img: support switching diffusers schedulers
keturn Nov 10, 2022
08c62d7
Merge branch 'development' into dev/diffusers
keturn Nov 10, 2022
1f83920
diffusers: let the scheduler do its scaling of the initial latents
keturn Nov 10, 2022
6b586b7
web server: update image_progress callback for diffusers data
keturn Nov 10, 2022
d121406
Merge branch 'development' into dev/diffusers
keturn Nov 11, 2022
7904d0c
diffusers: restore prompt weighting feature
keturn Nov 11, 2022
fdf2ed2
diffusers: fix set-sampler error following model switch
keturn Nov 11, 2022
3da4832
Merge branch 'development' into dev/diffusers
keturn Nov 11, 2022
1b326e7
diffusers: use InvokeAIDiffuserComponent for conditioning
keturn Nov 12, 2022
cbbe3a6
cross_attention_control: stub (no-op) implementations for diffusers
keturn Nov 12, 2022
0d52b85
model_cache: let offload_model work with DiffusionPipeline, sorta.
keturn Nov 12, 2022
50217c0
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 13, 2022
e7697d5
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 13, 2022
8d6189d
models.yaml.example: add diffusers-format model, set as default
keturn Nov 13, 2022
90ec3a7
test-invoke-conda: use diffusers-format model
keturn Nov 13, 2022
12efacc
test-invoke-conda: put huggingface-token where the library can use it
keturn Nov 14, 2022
e1c678c
test-invoke-conda: some diagnostic info from huggingface-cli
keturn Nov 14, 2022
d8dd1f9
test-invoke-conda: some diagnostic info from huggingface-cli
keturn Nov 14, 2022
a63a5f6
test-invoke-conda: it's a cache name, it doesn't need cache in the name
keturn Nov 14, 2022
be1e6f7
test-invoke-conda: run on pushes to forks
keturn Nov 14, 2022
bc5a7ba
test-invoke-conda: fix string comparison
keturn Nov 14, 2022
a71ec35
environment-mac: upgrade to diffusers 0.7 (from 0.6)
keturn Nov 14, 2022
8062758
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 15, 2022
638489d
lint(preload_models): pyflakes 🚮
keturn Nov 16, 2022
5b44a05
preload_models: explicitly load diffusers models
keturn Nov 16, 2022
624b202
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 19, 2022
d89385b
Merge branch 'development' into dev/diffusers
keturn Nov 20, 2022
8b9ff9b
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 22, 2022
7267d88
fix(model_cache): don't check `model.config` in diffusers format
keturn Nov 22, 2022
98dacba
fix typo in setup.py - `scripts/preload_models.py`
mauwii Nov 21, 2022
9568881
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 23, 2022
95848c9
dev: upgrade to diffusers 0.8 (from 0.7.1)
keturn Nov 23, 2022
375f3be
diffusers integration: support img2img
keturn Nov 24, 2022
458533a
Merge branch 'dev/diffusers-0.8' into dev/diffusers
keturn Nov 24, 2022
da5fee4
refactor: remove backported img2img.get_timesteps
keturn Nov 24, 2022
5a2f650
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 24, 2022
c849b51
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 25, 2022
9f49f54
CI: use huggingface cache for test-invoke-pip
keturn Nov 25, 2022
afae108
ci: use diffusers model
keturn Nov 25, 2022
1cbfa5e
fixup! ci: use diffusers model
keturn Nov 25, 2022
9ed8d24
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 25, 2022
5a6f236
dev: upgrade to diffusers 0.9 (from 0.8.1)
keturn Nov 25, 2022
15e99ae
lint: correct annotations for Python 3.9.
keturn Nov 25, 2022
66c5689
lint: correct AttributeError.name reference for Python 3.9.
keturn Nov 25, 2022
f72b0c8
CI: prefer diffusers-1.4 because it no longer requires a token
keturn Nov 25, 2022
95b914a
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 26, 2022
50ef6ef
build: there's yet another place to update requirements?
keturn Nov 26, 2022
03c057a
configure: try to download models even without token
keturn Nov 26, 2022
14d8f69
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 27, 2022
ce9384f
Merge remote-tracking branch 'origin/development' into dev/diffusers
keturn Nov 27, 2022
18cd56a
configure: add troubleshooting info for config-not-found
keturn Nov 27, 2022
a7dd76f
fix(configure): prepend root to config path
keturn Nov 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 33 additions & 35 deletions .github/workflows/test-invoke-conda.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
name: Test invoke.py
on:
push:
branches:
- 'main'
- 'development'
- 'fix-gh-actions-fork'
pull_request:
branches:
- 'main'
- 'development'
on: [push, pull_request]

jobs:
matrix:
# Run on:
# - pull requests
# - pushes to forks (will run in the forked project with that fork's secrets)
# - pushes to branches that are *not* pull requests
if: |
github.event_name == 'pull_request'
|| github.repository != 'invoke-ai/InvokeAI'
|| github.ref_protected
strategy:
matrix:
stable-diffusion-model:
- 'stable-diffusion-1.5'
- diffusers-1.4
environment-yaml:
- environment-lin-amd.yml
- environment-lin-cuda.yml
Expand All @@ -30,15 +29,13 @@ jobs:
- environment-yaml: environment-mac.yml
os: macos-12
default-shell: bash -l {0}
- stable-diffusion-model: stable-diffusion-1.5
stable-diffusion-model-url: https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt
stable-diffusion-model-dl-path: models/ldm/stable-diffusion-v1
stable-diffusion-model-dl-name: v1-5-pruned-emaonly.ckpt
name: ${{ matrix.environment-yaml }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
CONDA_ENV_NAME: invokeai
INVOKEAI_ROOT: '${{ github.workspace }}/invokeai'
PYTHONUNBUFFERED: 1
HAVE_SECRETS: ${{ secrets.HUGGINGFACE_TOKEN != '' }}
defaults:
run:
shell: ${{ matrix.default-shell }}
Expand All @@ -55,6 +52,15 @@ jobs:
- name: create environment.yml
run: cp "environments-and-requirements/${{ matrix.environment-yaml }}" environment.yml

- name: Use Cached Stable Diffusion Model
id: cache-sd-model
uses: actions/cache@v3
env:
cache-name: huggingface-${{ matrix.stable-diffusion-model }}
with:
path: ~/.cache/huggingface
key: ${{ env.cache-name }}

- name: Use cached conda packages
id: use-cached-conda-packages
uses: actions/cache@v3
Expand Down Expand Up @@ -82,32 +88,24 @@ jobs:
if: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/development' }}
run: echo "TEST_PROMPTS=tests/validate_pr_prompt.txt" >> $GITHUB_ENV

- name: Use Cached Stable Diffusion Model
id: cache-sd-model
uses: actions/cache@v3
env:
cache-name: cache-${{ matrix.stable-diffusion-model }}
with:
path: ${{ env.INVOKEAI_ROOT }}/${{ matrix.stable-diffusion-model-dl-path }}
key: ${{ env.cache-name }}

- name: Download ${{ matrix.stable-diffusion-model }}
id: download-stable-diffusion-model
if: ${{ steps.cache-sd-model.outputs.cache-hit != 'true' }}
run: |
mkdir -p "${{ env.INVOKEAI_ROOT }}/${{ matrix.stable-diffusion-model-dl-path }}"
curl \
-H "Authorization: Bearer ${{ secrets.HUGGINGFACE_TOKEN }}" \
-o "${{ env.INVOKEAI_ROOT }}/${{ matrix.stable-diffusion-model-dl-path }}/${{ matrix.stable-diffusion-model-dl-name }}" \
-L ${{ matrix.stable-diffusion-model-url }}

- name: run configure_invokeai.py
id: run-preload-models
run: |
python scripts/configure_invokeai.py --no-interactive --yes
if [ "${HAVE_SECRETS}" == true ] ; then
mkdir -p ~/.huggingface
echo -n '${{ secrets.HUGGINGFACE_TOKEN }}' > ~/.huggingface/token
fi
python scripts/configure_invokeai.py \
--no-interactive --yes \
--full-precision # can't use fp16 weights without a GPU

- name: Run the tests
id: run-tests
env:
# Set offline mode to make sure configure preloaded successfully.
HF_HUB_OFFLINE: 1
HF_DATASETS_OFFLINE: 1
TRANSFORMERS_OFFLINE: 1
run: |
time python scripts/invoke.py \
--model ${{ matrix.stable-diffusion-model }} \
Expand Down
67 changes: 33 additions & 34 deletions .github/workflows/test-invoke-pip.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: Test invoke.py pip
on:
push:
branches:
- 'main'
- 'development'
pull_request:
branches:
- 'main'
- 'development'
on: [push, pull_request]

jobs:
matrix:
# Run on:
# - pull requests
# - pushes to forks (will run in the forked project with that fork's secrets)
# - pushes to branches that are *not* pull requests
if: |
github.event_name == 'pull_request'
|| github.repository != 'invoke-ai/InvokeAI'
|| github.ref_protected
strategy:
matrix:
stable-diffusion-model:
- stable-diffusion-1.5
- diffusers-1.4
requirements-file:
- requirements-lin-cuda.txt
- requirements-lin-amd.txt
Expand All @@ -32,17 +32,15 @@ jobs:
- requirements-file: requirements-mac-mps-cpu.txt
os: macOS-12
default-shell: bash -l {0}
- stable-diffusion-model: stable-diffusion-1.5
stable-diffusion-model-url: https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt
stable-diffusion-model-dl-path: models/ldm/stable-diffusion-v1
stable-diffusion-model-dl-name: v1-5-pruned-emaonly.ckpt
name: ${{ matrix.requirements-file }} on ${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
defaults:
run:
shell: ${{ matrix.default-shell }}
env:
INVOKEAI_ROOT: '${{ github.workspace }}/invokeai'
PYTHONUNBUFFERED: 1
HAVE_SECRETS: ${{ secrets.HUGGINGFACE_TOKEN != '' }}
steps:
- name: Checkout sources
id: checkout-sources
Expand All @@ -53,6 +51,15 @@ jobs:
mkdir -p ${{ env.INVOKEAI_ROOT }}/configs
cp configs/models.yaml.example ${{ env.INVOKEAI_ROOT }}/configs/models.yaml

- name: Use Cached Stable Diffusion Model
id: cache-sd-model
uses: actions/cache@v3
env:
cache-name: huggingface-${{ matrix.stable-diffusion-model }}
with:
path: ~/.cache/huggingface
key: ${{ env.cache-name }}

- name: set test prompt to main branch validation
if: ${{ github.ref == 'refs/heads/main' }}
run: echo "TEST_PROMPTS=tests/preflight_prompts.txt" >> $GITHUB_ENV
Expand Down Expand Up @@ -81,32 +88,24 @@ jobs:
- name: install requirements
run: ${{ env.pythonLocation }}/bin/pip install -r '${{ matrix.requirements-file }}'

- name: Use Cached Stable Diffusion Model
id: cache-sd-model
uses: actions/cache@v3
env:
cache-name: cache-${{ matrix.stable-diffusion-model }}
with:
path: ${{ env.INVOKEAI_ROOT }}/${{ matrix.stable-diffusion-model-dl-path }}
key: ${{ env.cache-name }}

- name: Download ${{ matrix.stable-diffusion-model }}
id: download-stable-diffusion-model
if: ${{ steps.cache-sd-model.outputs.cache-hit != 'true' }}
run: |
mkdir -p "${{ env.INVOKEAI_ROOT }}/${{ matrix.stable-diffusion-model-dl-path }}"
curl \
-H "Authorization: Bearer ${{ secrets.HUGGINGFACE_TOKEN }}" \
-o "${{ env.INVOKEAI_ROOT }}/${{ matrix.stable-diffusion-model-dl-path }}/${{ matrix.stable-diffusion-model-dl-name }}" \
-L ${{ matrix.stable-diffusion-model-url }}

- name: run configure_invokeai.py
id: run-preload-models
run: |
${{ env.pythonLocation }}/bin/python scripts/configure_invokeai.py --no-interactive --yes
if [ "${HAVE_SECRETS}" == true ] ; then
mkdir -p ~/.huggingface
echo -n '${{ secrets.HUGGINGFACE_TOKEN }}' > ~/.huggingface/token
fi
${{ env.pythonLocation }}/bin/python scripts/configure_invokeai.py \
--no-interactive --yes \
--full-precision # can't use fp16 weights without a GPU

- name: Run the tests
id: run-tests
env:
# Set offline mode to make sure configure preloaded successfully.
HF_HUB_OFFLINE: 1
HF_DATASETS_OFFLINE: 1
TRANSFORMERS_OFFLINE: 1
run: |
time ${{ env.pythonLocation }}/bin/python scripts/invoke.py \
--model ${{ matrix.stable-diffusion-model }} \
Expand Down
5 changes: 4 additions & 1 deletion backend/invoke_ai_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from threading import Event

from ldm.invoke.args import Args, APP_ID, APP_VERSION, calculate_init_img_hash
from ldm.invoke.generator.diffusers_pipeline import PipelineIntermediateState
from ldm.invoke.pngwriter import PngWriter, retrieve_metadata
from ldm.invoke.prompt_parser import split_weighted_subprompts
from ldm.invoke.generator.inpaint import infill_methods
Expand Down Expand Up @@ -847,7 +848,9 @@ def generate_images(
init_img_path = self.get_image_path_from_url(init_img_url)
generation_parameters["init_img"] = Image.open(init_img_path).convert('RGB')

def image_progress(sample, step):
def image_progress(progress_state: PipelineIntermediateState):
step = progress_state.step
sample = progress_state.latents
if self.canceled.is_set():
raise CanceledException

Expand Down
2 changes: 2 additions & 0 deletions backend/modules/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"k_heun",
"k_lms",
"plms",
# diffusers:
"pndm",
]


Expand Down
9 changes: 9 additions & 0 deletions configs/models.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
# model requires a model config file, a weights file,
# and the width and height of the images it
# was trained on.
diffusers-1.4:
description: Diffusers version of Stable Diffusion version 1.4
format: diffusers
repo_name: CompVis/stable-diffusion-v1-4
default: true
diffusers-1.5:
description: Diffusers version of Stable Diffusion version 1.5
format: diffusers
repo_name: runwayml/stable-diffusion-v1-5
stable-diffusion-1.5:
description: The newest Stable Diffusion version 1.5 weight file (4.27 GB)
weights: models/ldm/stable-diffusion-v1/v1-5-pruned-emaonly.ckpt
Expand Down
2 changes: 1 addition & 1 deletion environments-and-requirements/environment-lin-amd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies:
- --extra-index-url https://download.pytorch.org/whl/rocm5.2/
- albumentations==0.4.3
- dependency_injector==4.40.0
- diffusers==0.6.0
- diffusers~=0.9
- einops==0.3.0
- eventlet
- flask==2.1.3
Expand Down
3 changes: 2 additions & 1 deletion environments-and-requirements/environment-lin-cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ dependencies:
- pytorch=1.12.1
- cudatoolkit=11.6
- pip:
- accelerate~=0.13
- albumentations==0.4.3
- dependency_injector==4.40.0
- diffusers==0.6.0
- diffusers~=0.9
- einops==0.3.0
- eventlet
- flask==2.1.3
Expand Down
2 changes: 1 addition & 1 deletion environments-and-requirements/environment-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:

- albumentations=1.2
- coloredlogs=15.0
- diffusers=0.6
- diffusers~=0.9
- einops=0.3
- eventlet
- grpcio=1.46
Expand Down
2 changes: 1 addition & 1 deletion environments-and-requirements/environment-win-cuda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
- albumentations==0.4.3
- basicsr==1.4.1
- dependency_injector==4.40.0
- diffusers==0.6.0
- diffusers~=0.9
- einops==0.3.0
- eventlet
- flask==2.1.3
Expand Down
5 changes: 3 additions & 2 deletions environments-and-requirements/requirements-base.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pip will resolve the version which matches torch
albumentations
dependency_injector==4.40.0
diffusers
diffusers[torch]~=0.9
einops
eventlet
facexlib
Expand Down Expand Up @@ -30,9 +30,10 @@ taming-transformers-rom1504
test-tube>=0.7.5
torch-fidelity
torchmetrics
transformers==4.21.*
transformers~=4.24
picklescan
git+https://github.com/openai/CLIP.git@main#egg=clip
git+https://github.com/Birch-san/k-diffusion.git@mps#egg=k-diffusion
git+https://github.com/invoke-ai/clipseg.git@relaxed-python-requirement#egg=clipseg
git+https://github.com/invoke-ai/[email protected]#egg=pypatchmatch

2 changes: 1 addition & 1 deletion installer/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
--trusted-host https://download.pytorch.org
accelerate~=0.14
albumentations
diffusers
diffusers[torch]~=0.9
einops
eventlet
facexlib
Expand Down
Loading