diffusers icon indicating copy to clipboard operation
diffusers copied to clipboard

single_file_utils.py#load_single_file_model_checkpoint bugs

Open knoopx opened this issue 1 year ago • 4 comments

Describe the bug

Loading a checkpoint from file crashes as it tries to print a warning with unexpected keys because is accessing __name__ on incorrect target (instance instead of class)

https://github.com/huggingface/diffusers/blob/d50baf0c632342b9576a24352244c4235ce8b875/src/diffusers/loaders/single_file_utils.py

f"Some weights of the model checkpoint were not used when initializing {vae.__name__} f"Some weights of the model checkpoint were not used when initializing {unet.__name__} f"Some weights of the model checkpoint were not used when initializing {controlnet.__name__}

should be:

[...].__class__.__name__

Reproduction

load a single file checkpoint with extra keys

Logs

No response

System Info

  • diffusers version: 0.27.2
  • Platform: Linux-6.8.8-1-clear-x86_64-with-glibc2.39
  • Python version: 3.11.0
  • PyTorch version (GPU?): 2.2.0+cu121 (True)
  • Huggingface_hub version: 0.23.0
  • Transformers version: 4.40.1
  • Accelerate version: 0.30.0

Who can help?

@sayakpaul

knoopx avatar May 08 '24 08:05 knoopx

Please provide a reproducible snippet.

Cc: @DN6

sayakpaul avatar May 08 '24 08:05 sayakpaul

@sayakpaul

Ran:

StableDiffusionPipeline.from_single_file("checkpoint-with-extra-keys.safetensor").

Got:

  File ".venv/lib/python3.11/site-packages/huggingface_hub/utils/_validators.py", line 114, in _inner_fn
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/diffusers/loaders/single_file.py", line 289, in from_single_file
    components = build_sub_model_components(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/diffusers/loaders/single_file.py", line 75, in build_sub_model_components
    vae_components = create_diffusers_vae_model_from_ldm(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/diffusers/loaders/single_file_utils.py", line 1391, in create_diffusers_vae_model_from_ldm
    f"Some weights of the model checkpoint were not used when initializing {vae.__name__}: \n {[', '.join(unexpected_keys)]}"
                                                                            ^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/diffusers/models/modeling_utils.py", line 218, in __getattr__
    return super().__getattr__(name)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1688, in __getattr__
    raise AttributeError(f"'{type(self).__name__}' object has no attribute '{name}'")
AttributeError: 'AutoencoderKL' object has no attribute '__name__'

Expected:

Some weights of the model checkpoint were not used when initializing AutoencoderKL: [...]

knoopx avatar May 09 '24 09:05 knoopx

This is still not fully reproducible.

sayakpaul avatar May 09 '24 10:05 sayakpaul

@knoopx we just merged this PR https://github.com/huggingface/diffusers/pull/7496 can you update the diffusers and try again?

if still not working, please provide a reproducible code example with inputs and checkpoints that accessible to us

yiyixuxu avatar May 09 '24 16:05 yiyixuxu

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

github-actions[bot] avatar Sep 14 '24 15:09 github-actions[bot]