Skip to content

TypeError: UVit2DModel.forward.<locals>.layer_() got an unexpected keyword argument 'encoder_hidden_states' #11214

Open

Description

@RongKaiWeskerMA

Describe the bug

When I run the amused example, I got this error: TypeError: UVit2DModel.forward..layer_() got an unexpected keyword argument 'encoder_hidden_states'.

Looks like the transformer layer does not have this encore_hidden_state attributes.

Reproduction

Run the amused example

Logs

System Info

newest diffuser GitHub repository

Who can help?

No response

Activity

  1. added
    bug
    on Apr 6, 2025
  2. bghira commented on Apr 6, 2025

    @bghira
    Contributor

    can you show the whole trace?

  3. bghira commented on Apr 6, 2025

    @bghira
    Contributor

    BasicTransformerBlock has encoder_hidden_states
    https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention.py#L473

    and transformer_layers is a list of BasicTransformerBlock
    https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/unets/uvit_2d.py#L108

    down_block and up_block are both UViTBlock, which also has
    https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/unets/uvit_2d.py#L383

    so i'm not clear where this layer arg error is coming in, a full trace will be helpful.

  4. RongKaiWeskerMA commented on Apr 7, 2025

    @RongKaiWeskerMA
    Author

    accelerate launch train_amused.py \ --output_dir <output path> \ --train_batch_size 16 \ --gradient_accumulation_steps 1 \ --learning_rate 8e-4 \ --use_lora \ --pretrained_model_name_or_path amused/amused-256 \ --instance_data_dataset 'm1guelpf/nouns' \ --image_key image \ --prompt_key text \ --resolution 256 \ --mixed_precision fp16 \ --lr_scheduler constant \ --validation_prompts \ 'a pixel art character with square red glasses, a baseball-shaped head and a orange-colored body on a dark background' \ 'a pixel art character with square orange glasses, a lips-shaped head and a red-colored body on a light background' \ 'a pixel art character with square blue glasses, a microwave-shaped head and a purple-colored body on a sunny background' \ 'a pixel art character with square red glasses, a baseball-shaped head and a blue-colored body on an orange background' \ 'a pixel art character with square red glasses' \ 'a pixel art character' \ 'square red glasses on a pixel art character' \ 'square red glasses on a pixel art character with a baseball-shaped head' \ --max_train_steps 10000 \ --checkpointing_steps 500 \ --validation_steps 250 \ --gradient_checkpointing

    Error log full trace:

    Exception has occurred: TypeError UVit2DModel.forward.<locals>.layer_() got an unexpected keyword argument 'encoder_hidden_states' File "/home/wesker/personal/diffusers/src/diffusers/models/unets/uvit_2d.py", line 189, in forward hidden_states = layer_( ^^^^^^^ File "/home/wesker/anaconda3/envs/diffusion/lib/python3.11/site-packages/torch/amp/autocast_mode.py", line 44, in decorate_autocast return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/home/wesker/anaconda3/envs/diffusion/lib/python3.11/site-packages/accelerate/utils/operations.py", line 807, in __call__ return convert_to_fp32(self.model_forward(*args, **kwargs)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/wesker/anaconda3/envs/diffusion/lib/python3.11/site-packages/accelerate/utils/operations.py", line 819, in forward return model_forward(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/wesker/anaconda3/envs/diffusion/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1750, in _call_impl return forward_call(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/wesker/anaconda3/envs/diffusion/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1739, in _wrapped_call_impl return self._call_impl(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/wesker/personal/diffusers/examples/amused/train_amused.py", line 826, in main model( File "/home/wesker/personal/diffusers/examples/amused/train_amused.py", line 975, in <module> main(parse_args()) TypeError: UVit2DModel.forward.<locals>.layer_() got an unexpected keyword argument 'encoder_hidden_states'

  5. RongKaiWeskerMA commented on Apr 7, 2025

    @RongKaiWeskerMA
    Author

    Interestingly, this error only occurs when building diffusers from source by:
    git clone https://github.com/huggingface/diffusers.git && cd diffusers && pip install -e ".[torch]"
    . When installing the diffusers package directly from pip and using the same train_amused.py script, the error does not appear

  6. github-actions commented on May 6, 2025

    @github-actions
    Contributor

    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.

  7. added
    stale
    on May 6, 2025
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

    bugstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions