microsoft / unilm

Large-scale Self-supervised Pre-training Across Tasks, Languages, and Modalities
https://aka.ms/GeneralAI
MIT License
19.25k stars 2.45k forks source link

Textdiffusers : TypeError: get_down_block() got an unexpected keyword argument 'attn_num_head_channels' #1153

Open Wonder1905 opened 1 year ago

Wonder1905 commented 1 year ago

Hi, Im trying to run textdiffusers, followed all instructions.

The problem arises when using:

accelerate launch train.py \
    --train_batch_size=24 \
    --gradient_accumulation_steps=4 \
    --gradient_checkpointing \
    --mixed_precision="fp16" \
    --num_train_epochs=2 \
    --learning_rate=1e-5 \
    --max_grad_norm=1 \
    --lr_scheduler="constant" \
    --lr_warmup_steps=0 \
    --output_dir="experiment_name" \
    --enable_xformers_memory_efficient_attention \
    --dataloader_num_workers=4 \
    --character_aware_loss_lambda=0.01 \
    --resume_from_checkpoint="latest" \
    --drop_caption \
    --mask_all_ratio=0.5 \
    --segmentation_mask_aug \
    --vis_num=8

I get this bug: TypeError: get_down_block() got an unexpected keyword argument 'attn_num_head_channels' (full bug at the end)

I understand what is the problem, the repo ask to install from diffusers from source. file: "./textdiffuser/diffusers/src/diffusers/models/unet_2d_condition.py" at line 291 call "get_down_block" with an argument "attn_num_head_channels", which not exist in the current version of diffusers. Hence it will be great if the authors can share the version of diffusers they used.

Env: Ubuntu18.04 torch==1.13.1 torchvision==0.14.1 transformers==4.27.4 diffusers : -e git+https://github.com/huggingface/diffusers@fc6acb6b97e93d58cb22b5fee52d884d77ce84d8#egg=diffusers

full bug report: File "train.py", line 506, in main unet = UNet2DConditionModel.from_pretrained( File "/workspace/unilm/textdiffuser/diffusers/src/diffusers/models/modeling_utils.py", line 563, in from_pretrained model = cls.from_config(config, **unused_kwargs) File "/workspace/unilm/textdiffuser/diffusers/src/diffusers/configuration_utils.py", line 232, in from_config model = cls(**init_dict) File "/workspace/unilm/textdiffuser/diffusers/src/diffusers/configuration_utils.py", line 604, in inner_init init(self, *args, **init_kwargs) File "/workspace/unilm/textdiffuser/diffusers/src/diffusers/models/unet_2d_condition.py", line 291, in __init__ down_block = get_down_block( TypeError: get_down_block() got an unexpected keyword argument 'attn_num_head_channels'

Thanks for your help!

JingyeChen commented 1 year ago

Thanks for your attention to our work! In fact there are several operations about replacing files. Did you finsh these operations? Besides, the version diffuser package is 0.17.0.dev0 in my environment. For your information!

git clone https://github.com/huggingface/diffusers
cp ./assets/files/scheduling_ddpm.py ./diffusers/src/diffusers/schedulers/scheduling_ddpm.py
cp ./assets/files/unet_2d_condition.py ./diffusers/src/diffusers/models/unet_2d_condition.py
cp ./assets/files/modeling_utils.py ./diffusers/src/diffusers/models/modeling_utils.py
cd diffusers && pip install -e .
Wonder1905 commented 1 year ago

Yes, I did. Lets pass on the flow, one uses your specific : unet_2d_condition.py, in line 291: down_block = get_down_block( down_block_type, num_layers=layers_per_block, in_channels=input_channel, out_channels=output_channel, temb_channels=blocks_time_embed_dim, add_downsample=not is_final_block, resnet_eps=norm_eps, resnet_act_fn=act_fn, resnet_groups=norm_num_groups, cross_attention_dim=cross_attention_dim[i], **attn_num_head_channels=attention_head_dim[i],** downsample_padding=downsample_padding, dual_cross_attention=dual_cross_attention, use_linear_projection=use_linear_projection, only_cross_attention=only_cross_attention[i], upcast_attention=upcast_attention, resnet_time_scale_shift=resnet_time_scale_shift,

This function call calls get_down_block with attn_num_head_channels from unet_2d_blocks.py files. The current version of diffusers , unet_2d_blocks.py line 32, def get_down_block function does not have any attn_num_head_channels argument. https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/unet_2d_blocks.py.

JingyeChen commented 1 year ago

I go through the repo https://github.com/huggingface/diffusers and found that "attn_num_head_channels" was removed recently. Alternatively, you can install diffusers with the following commands:

git clone https://github.com/JingyeChen/diffusers
cd diffusers
pip install -e .

Hope it will help you!