You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue Description:
When using the Encoder from the diffusers.models.autoencoders.vae module, calling its forward method returns a value type mismatch, resulting in an AttributeError during subsequent processing. Specifically, when calling the Encoder's forward method, the returned result is a tuple, while the subsequent code expects to receive a tensor.
Reproduction
Please use the following code to reproduce the issue
Expected Behavior:
The Encoder's forward method in diffusers.models.autoencoders.vae should return a tensor for further processing.
Actual Behavior:
Running the above code results in the following error:
AttributeError: 'tuple' object has no attribute 'dim'
Additional Information:
Error log:
Traceback (most recent call last):
File "main.py", line 9, in <module>
encoder(torch.randn(1, 3, 256, 256)).shape
...
File "python3.11/site-packages/diffusers/models/autoencoders/vae.py", line 172, in forward
sample = down_block(sample)
...
File "python3.11/site-packages/diffusers/models/autoencoders/vae.py", line 172, in forward
hidden_states = resnet(hidden_states, temb)
...
File "python3.11/site-packages/diffusers/models/autoencoders/vae.py", line 172, in forward
hidden_states = self.norm1(hidden_states)
File "python3.11/site-packages/torch/nn/modules/normalization.py", line 313, in forward
return F.group_norm(input, self.num_groups, self.weight, self.bias, self.eps)
File "python3.11/site-packages/torch/nn/functional.py", line 2947, in group_norm
if input.dim() < 2:
AttributeError: 'tuple' object has no attribute 'dim'
Relevant code snippet:
In diffusers/models/autoencoders/vae.py, lines 171-173:
The issue arises because the down_blocks in diffusers.models.unets.unet_2d_blocks return different outputs: sometimes a single tensor (hidden_states), and other times tuples like (hidden_states, output_states) or (hidden_states, output_states, skip_sample). However, in the Encoder implementation, the loop that processes down_blocks assumes only a single tensor output:
This behavior causes errors when the down_block returns a tuple instead of a single tensor. Specifically, the tuple is passed to the next layer, which expects only a tensor, leading to runtime errors.
Describe the bug
Issue Description:
When using the Encoder from the
diffusers.models.autoencoders.vae module
, calling its forward method returns a value type mismatch, resulting in an AttributeError during subsequent processing. Specifically, when calling the Encoder's forward method, the returned result is a tuple, while the subsequent code expects to receive a tensor.Reproduction
Please use the following code to reproduce the issue
Expected Behavior:
The Encoder's forward method in
diffusers.models.autoencoders.vae
should return a tensor for further processing.Actual Behavior:
Running the above code results in the following error:
Additional Information:
Relevant code snippet:
diffusers/models/autoencoders/vae.py
, lines 171-173:DownBlock2D
'sforward
method declaration:Logs
No response
System Info
Who can help?
@DN6 @sayakpaul
The text was updated successfully, but these errors were encountered: