Skip to content

AttributeError: 'StableDiffusionXLPipeline' object has no attribute 'final_offload_hook' #5054

Closed

Description

@alexisrolland

Describe the bug

After upgrading my code to 0.21.1 it triggers the error:

AttributeError: 'StableDiffusionXLPipeline' object has no attribute 'final_offload_hook'

Reproduction

import os
import torch
from diffusers import StableDiffusionXLPipeline

MODEL_PATH = os.getenv('MODEL_PATH')
pipeline = StableDiffusionXLPipeline.from_pretrained(MODEL_PATH, torch_dtype=torch.float16, variant='fp16', use_safetensors=True)
pipeline.enable_model_cpu_offload()
pipeline.final_offload_hook

Logs

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.10/site-packages/diffusers/configuration_utils.py", line 137, in __getattr__
    raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'StableDiffusionXLPipeline' object has no attribute 'final_offload_hook'

System Info

  • diffusers version: 0.21.1
  • Platform: Linux-5.4.72-microsoft-standard-WSL2-x86_64-with-glibc2.36
  • Python version: 3.10.13
  • PyTorch version (GPU?): 2.0.1+cu117 (True)
  • Huggingface_hub version: 0.17.1
  • Transformers version: 4.33.1
  • Accelerate version: 0.23.0
  • xFormers version: 0.0.21
  • Using GPU in script?: Yes
  • Using distributed or parallel set-up in script?: No

Who can help?

@patrickvonplaten , @sayakpaul , @williamberman

Activity

  1. sayakpaul commented on Sep 15, 2023

    @sayakpaul
    Member

    Why are you accessing pipeline.final_offload_hook?

  2. alexisrolland commented on Sep 15, 2023

    @alexisrolland
    Author

    To be honest I'm not sure whether it is necessary... It's a piece of code I have inherited from someone else. What the code does:

    1. Load ControlNet models
    2. Offload ControlNet models to CPU
    3. Instantiate SDXL ControlNet Pipeline
    # [...]
    controlnets = ControlNetModel.from_pretrained(os.getenv(model_path), torch_dtype=torch.float16)
    cpu_offload_with_hook(controlnets)
    
    # [...]
    pipeline = StableDiffusionXLControlNetPipeline(controlnet=controlnets, **default_pipeline.components)
    pipeline.final_offload_hook = default_pipeline.final_offload_hook  # default_pipeline is my StableDiffusionXLPipeline here

    What I know is that it used to work and now it does not anymore... but maybe I can just remove pipeline.final_offload_hook = default_pipeline.final_offload_hook ?

  3. sayakpaul commented on Sep 15, 2023

    @sayakpaul
    Member

    After using enable_model_cpu_offload() I don't think you will have the need to access any of these attributes actually. We recently refactored the enable_model_cpu_offload() API to make it generally available for all the pipeline inherited from DiffusionPipeline, so, that might have broken the behaviour you are referring to. Cc: @patrickvonplaten too.

  4. alexisrolland commented on Sep 17, 2023

    @alexisrolland
    Author

    Got it, thank you @sayakpaul. I'll just drop the final_offload_hook and close this issue.

  5. alexisrolland commented on Oct 5, 2023

    @alexisrolland
    Author

    I think dropping the final_offload_hook is what triggered these errors: #5281

    It seems the hooks of ControlNet pipeline are not properly synced with the main pipeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions