- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6.5k
Description
Describe the bug
TypeError in VAE with ResnetUpsampleBlock2D: NoneType used in addition
When I attempted to modify the encoder and decoder types within the VAE model to ResnetDownsampleBlock2D and ResnetUpsampleBlock2D respectively, I encountered an error:

Curious about this error, I cloned the diffusers source code to investigate.
I quickly identified the issue: when the up blocks are created, a None value is passed to the prev_output_channel variable. Subsequently, the code within ResnetUpsampleBlock2D attempts to use this None value in an addition operation with another variable (likely an integer type), which results in the TypeError shown in the image.
I believe this is a bug in this part of the code and hope it can be fixed promptly.
the source code:
diffusers/src/diffusers/models/autoencoders/vae.py
Lines 245 to 268 in b8093e6
| reversed_block_out_channels = list(reversed(block_out_channels)) | |
| output_channel = reversed_block_out_channels[0] | |
| for i, up_block_type in enumerate(up_block_types): | |
| prev_output_channel = output_channel | |
| output_channel = reversed_block_out_channels[i] | |
| is_final_block = i == len(block_out_channels) - 1 | |
| up_block = get_up_block( | |
| up_block_type, | |
| num_layers=self.layers_per_block + 1, | |
| in_channels=prev_output_channel, | |
| out_channels=output_channel, | |
| prev_output_channel=None, | |
| add_upsample=not is_final_block, | |
| resnet_eps=1e-6, | |
| resnet_act_fn=act_fn, | |
| resnet_groups=norm_num_groups, | |
| attention_head_dim=output_channel, | |
| temb_channels=temb_channels, | |
| resnet_time_scale_shift=norm_type, | |
| ) | |
| self.up_blocks.append(up_block) | |
| prev_output_channel = output_channel | 
Reproduction
It's easy to reproduct so I think there is no need to provide a code.
Logs
System Info
- π€ Diffusers version: 0.33.0
- Platform: Linux-6.8.0-52-generic-x86_64-with-glibc2.35
- Running on Google Colab?: No
- Python version: 3.12.0
- PyTorch version (GPU?): 2.6.0+cu124 (True)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Huggingface_hub version: 0.30.2
- Transformers version: not installed
- Accelerate version: 1.6.0
- PEFT version: not installed
- Bitsandbytes version: not installed
- Safetensors version: 0.5.3
- xFormers version: not installed
- Accelerator: NVIDIA GeForce RTX 4090, 24564 MiB
 NVIDIA GeForce RTX 4090, 24564 MiB
- Using GPU in script?:
- Using distributed or parallel set-up in script?:
Who can help?
No response
