horseee / DeepCache

[CVPR 2024] DeepCache: Accelerating Diffusion Models for Free
https://horseee.github.io/Diffusion_DeepCache/
Apache License 2.0
687 stars 32 forks source link

Diffusers 0.26.3 #25

Closed elismasilva closed 4 months ago

elismasilva commented 4 months ago

Hi you need update pipeline XL to work with last version of Diffusers...

horseee commented 4 months ago

Hi @elismasilva,

I tested DeepCache under diffusers==0.26.3 and it works well. Can you give me the code snippet that can reproduce the bug/error?

elismasilva commented 4 months ago

When i try import pipeline:

from DeepCache.sdxl.pipeline_stable_diffusion_xl import StableDiffusionXLPipeline as DeepCacheStableDiffusionXLPipeline

i got error:

Exception has occurred: ImportError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
cannot import name 'PositionNet' from 'diffusers.models.embeddings' (f:\Projetos\Fast\optimum\venv2\lib\site-packages\diffusers\models\embeddings.py)
  File "F:\Projetos\Fast\optimum\venv2\Lib\site-packages\DeepCache\sdxl\unet_2d_condition.py", line 32, in <module>
    from diffusers.models.embeddings import (
  File "F:\Projetos\Fast\optimum\venv2\Lib\site-packages\DeepCache\sdxl\pipeline_stable_diffusion_xl.py", line 48, in <module>
    from .unet_2d_condition import UNet2DConditionModel
  File "F:\Projetos\Fast\optimum\text-deep-cache.py", line 3, in <module>
    from DeepCache.sdxl.pipeline_stable_diffusion_xl import StableDiffusionXLPipeline as DeepCacheStableDiffusionXLPipeline
  File "C:\Users\pelol\.pyenv\pyenv-win\versions\3.10.11\Lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\pelol\.pyenv\pyenv-win\versions\3.10.11\Lib\runpy.py", line 196, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,
ImportError: cannot import name 'PositionNet' from 'diffusers.models.embeddings' (f:\Projetos\Fast\optimum\venv2\lib\site-packages\diffusers\models\embeddings.py)

I tried to fix this by looking at the original pipeline, I managed to fix the PositionNet one but then more and more errors started appearing so I found that your pipeline is very different from the original, for example it is not prepared for batch process if I don't use the textencoder it It's a problem too. I managed to make it work just with DeepCacheSDHelper using the pipeline. By the way, does this class have the same result as the implemented pipeline?:

This is my code, the line that causes the problem is commented out:

import torch
from diffusers import StableDiffusionXLPipeline
#from DeepCache.sdxl.pipeline_stable_diffusion_xl import StableDiffusionXLPipeline as DeepCacheStableDiffusionXLPipeline
queue = []

queue.extend([{
  'prompt': '3/4 shot, candid photograph of a beautiful 30 year old redhead woman with messy dark hair, peacefully sleeping in her bed, night, dark, light from window, dark shadows, masterpiece, uhd, moody',
  'seed': 877866765,
}])

pipe = StableDiffusionXLPipeline.from_pretrained(
  'stabilityai/stable-diffusion-xl-base-1.0',
  use_safetensors=True,
  torch_dtype=torch.float16,
  variant='fp16',
).to('cuda')

generator = torch.Generator(device='cuda')

for i, generation in enumerate(queue, start=1):
  generator.manual_seed(generation['seed'])

  image = pipe(
    prompt=generation['prompt'],
    generator=generator    
  ).images[0]

  image.save(f'image_{i}.png')
elismasilva commented 4 months ago

23 Looking now at the history I suppose this is related, this pipeline is for 0.24 diffusers right?

horseee commented 4 months ago

23 Looking now at the history I suppose this is related, this pipeline is for 0.24 diffusers right?

Yes. If you want to use the code in DeepCache.sdxl.pipeline_stable_diffusion_xl, than Diffusers needs to be downgraded to 0.24(test passed under 0.21.3<diffusers<0.25.0).

And another way is to install the package DeepCache and follow the instruction to run the pipeline (or use DeepCache.extension.deepcache, the same). This implementation can support the latest versions of diffusers so far.

elismasilva commented 4 months ago

Ok thank you! i hope you can fix cpu offload bug soon, but for while for 1 batch its ok.