Skip to content
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

[Feature] Fix like xtuner #119

Merged
merged 5 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Update diffusers and fix test
  • Loading branch information
okotaku committed Jan 5, 2024
commit 5b0a3440f1e81f5d2a18727f649d6b0150651af9
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ pip install git+https://github.com/okotaku/diffengine.git

DiffEngine makes training easy through its pre-defined configs. These configs provide a streamlined way to start your training process. Here's how you can get started using one of the pre-defined configs:

1. **Choose a config**: You can find various pre-defined configs in the [`configs`](configs/) directory of the DiffEngine repository. For example, if you wish to train a DreamBooth model using the Stable Diffusion algorithm, you can use the [`configs/stable_diffusion_dreambooth/stable_diffusion_v15_dreambooth_lora_dog.py`](configs/stable_diffusion_dreambooth/stable_diffusion_v15_dreambooth_lora_dog.py).
1. **Choose a config**: You can find various pre-defined configs in the [`configs`](diffengine/configs/) directory of the DiffEngine repository. For example, if you wish to train a DreamBooth model using the Stable Diffusion algorithm, you can use the [`configs/stable_diffusion_dreambooth/stable_diffusion_v15_dreambooth_lora_dog.py`](diffengine/configs/stable_diffusion_dreambooth/stable_diffusion_v15_dreambooth_lora_dog.py).

2. **Start Training**: Open a terminal and run the following command to start training with the selected config:

```bash
diffengine train stable_diffusion_v15_dreambooth_lora_dog.py
diffengine train stable_diffusion_v15_dreambooth_lora_dog
```

3. **Monitor Progress and get results**: The training process will begin, and you can track its progress. The outputs of the training will be located in the `work_dirs/stable_diffusion_v15_dreambooth_lora_dog` directory, specifically when using the `stable_diffusion_v15_dreambooth_lora_dog` config.
Expand Down
4 changes: 2 additions & 2 deletions diffengine/models/archs/ip_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
IPAdapterAttnProcessor,
IPAdapterAttnProcessor2_0,
)
from diffusers.models.embeddings import ImageProjection, Resampler
from diffusers.models.embeddings import ImageProjection, IPAdapterPlusImageProjection
from diffusers.utils import _get_model_file
from safetensors import safe_open
from torch import nn
Expand Down Expand Up @@ -181,7 +181,7 @@ def process_ip_adapter_state_dict( # noqa: PLR0915, C901, PLR0912
for k, v in image_projection.state_dict().items():
new_k = k.replace("image_embeds.", "proj.")
ip_image_projection_state_dict[new_k] = v
elif isinstance(image_projection, Resampler):
elif isinstance(image_projection, IPAdapterPlusImageProjection):
for k, v in image_projection.state_dict().items():
if "2.to" in k:
new_k = k.replace("2.to", "0.to")
Expand Down
4 changes: 2 additions & 2 deletions diffengine/models/editors/ip_adapter/ip_adapter_xl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import torch
from diffusers import DiffusionPipeline
from diffusers.models.embeddings import ImageProjection, Resampler
from diffusers.models.embeddings import ImageProjection, IPAdapterPlusImageProjection
from diffusers.utils import load_image
from PIL import Image
from torch import nn
Expand Down Expand Up @@ -321,7 +321,7 @@ def prepare_model(self) -> None:
"""
self.image_encoder = CLIPVisionModelWithProjection.from_pretrained(
self.image_encoder_name, subfolder=self.image_encoder_sub_folder)
self.image_projection = Resampler(
self.image_projection = IPAdapterPlusImageProjection(
embed_dims=self.image_encoder.config.hidden_size,
output_dims=self.unet.config.cross_attention_dim,
hidden_dims=1280,
Expand Down
167 changes: 0 additions & 167 deletions diffengine/models/editors/ip_adapter/resampler.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from .sdxl_controlnet_data_preprocessor import SDXLControlNetDataPreprocessor
from .stable_diffusion_xl_controlnet import StableDiffusionXLControlNet
from .stable_diffusion_xl_controlnetxs import StableDiffusionXLControlNetXS

__all__ = ["SDXLControlNetDataPreprocessor", "StableDiffusionXLControlNet",
"StableDiffusionXLControlNetXS"]
__all__ = ["SDXLControlNetDataPreprocessor", "StableDiffusionXLControlNet"]
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from mmengine import print_log
from PIL import Image

from diffengine.models.editors import StableDiffusionXLControlNet
from diffengine.registry import MODELS

from .stable_diffusion_xl_controlnet import StableDiffusionXLControlNet


@MODELS.register_module()
class StableDiffusionXLControlNetXS(StableDiffusionXLControlNet):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
"torch>=2.0.1",
"torchvision>=0.15.2",
"datasets>=2.14.6",
"diffusers>=0.24.0",
"diffusers>=0.25.0",
"mmengine>=0.10.1",
"sentencepiece>=0.1.99",
"tqdm",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/test_archs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from diffusers import UNet2DConditionModel
from diffusers.models.embeddings import ImageProjection, Resampler
from diffusers.models.embeddings import ImageProjection, IPAdapterPlusImageProjection
from peft import LoHaConfig, LoKrConfig, LoraConfig, OFTConfig

from diffengine.models.archs import (
Expand Down Expand Up @@ -79,7 +79,7 @@ def test_process_ip_adapter_state_dict():
assert "proj.weight" in proj_state_dict["image_proj"]
assert len(proj_state_dict["ip_adapter"]) == 24

resampler = Resampler(
resampler = IPAdapterPlusImageProjection(
embed_dims=32,
output_dims=32,
hidden_dims=128,
Expand Down
Loading