# Unet1dmodel fails

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funet1dmodel-fails%2F36349%3E%5C
**Category:** 🧨 Diffusers\
**Created:** [April 12, 2023, 2:27pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funet1dmodel-fails%2F36349 "2023-04-12T14:27:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![StableDiffuser317](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@StableDiffuser317](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FStableDiffuser317)%5C
**Post date:** [April 12, 2023, 2:27pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funet1dmodel-fails%2F36349%2F1 "2023-04-12T14:27:55Z")

</div>

Specifying the architecture of a Unet1dmodel leads to weird behaviour.  
CODE :

default\_model = UNet1DModel(in\_channels = 17, out\_channels=1,sample\_size = 256)  
custom\_model = UNet1DModel(in\_channels = 17, out\_channels=1,sample\_size = 256,down\_block\_types =  
(“DownBlock1D”, “DownBlock1D”, “DownBlock1D”,“DownBlock1D”,“DownBlock1D”),  
up\_block\_types = (“UpBlock1D”, “UpBlock1D”,“UpBlock1D”,“UpBlock1D”, “UpBlock1D”),  
block\_out\_channels = (32, 32, 32, 32, 32))  
x = torch.randn((16,1,256))  
timesteps = torch.randint(0,10,(16,))  
y\_default = default\_model(x,timesteps)  
y\_custom = custom\_model(x,timesteps)

ERROR :  
Regarding y\_custom  
RuntimeError: Given groups=1, weight of size [32, 17, 1], expected input[16, 1, 128] to have 17 channels, but got 1 channels instead

The in\_channel argument is simply due to the following thread

> <https://github.com/huggingface/diffusers/issues/2967>
>
> This is using the latest huggingface diffusers:
> 
> \`\`\`
> from diffusers.models.un…et\_1d import UNet1DModel
> import torch
> 
> net = UNet1DModel().cuda()
> input\_data = torch.rand(1, 2, 16000).cuda()
> net(input\_data, 1)
> \`\`\`
> 
> gives the following:
> 
> \`\`\`
> ╭─────────────────────────────── Traceback (most recent call last) ───────────────────────────────╮
> │ \<ipython-input-4-fe6e05ad0774\>:1 in \<module\> │
> │ │
> │ /opt/miniconda3/lib/python3.9/site-packages/torch/nn/modules/module.py:1194 in \_call\_impl │
> │ │
> │ 1191 │ │ # this function, and just call forward. │
> │ 1192 │ │ if not (self.\_backward\_hooks or self.\_forward\_hooks or self.\_forward\_pre\_hooks o │
> │ 1193 │ │ │ │ or \_global\_forward\_hooks or \_global\_forward\_pre\_hooks): │
> │ ❱ 1194 │ │ │ return forward\_call(\*input, \*\*kwargs) │
> │ 1195 │ │ # Do not call functions when jit is used │
> │ 1196 │ │ full\_backward\_hooks, non\_full\_backward\_hooks = \[\], \[\] │
> │ 1197 │ │ if self.\_backward\_hooks or \_global\_backward\_hooks: │
> │ │
> │ /opt/miniconda3/lib/python3.9/site-packages/diffusers/models/unet\_1d.py:226 in forward │
> │ │
> │ 223 │ │ # 2. down │
> │ 224 │ │ down\_block\_res\_samples = () │
> │ 225 │ │ for downsample\_block in self.down\_blocks: │
> │ ❱ 226 │ │ │ sample, res\_samples = downsample\_block(hidden\_states=sample, temb=timestep\_e │
> │ 227 │ │ │ down\_block\_res\_samples += res\_samples │
> │ 228 │ │ │
> │ 229 │ │ # 3. mid │
> │ │
> │ /opt/miniconda3/lib/python3.9/site-packages/torch/nn/modules/module.py:1194 in \_call\_impl │
> │ │
> │ 1191 │ │ # this function, and just call forward. │
> │ 1192 │ │ if not (self.\_backward\_hooks or self.\_forward\_hooks or self.\_forward\_pre\_hooks o │
> │ 1193 │ │ │ │ or \_global\_forward\_hooks or \_global\_forward\_pre\_hooks): │
> │ ❱ 1194 │ │ │ return forward\_call(\*input, \*\*kwargs) │
> │ 1195 │ │ # Do not call functions when jit is used │
> │ 1196 │ │ full\_backward\_hooks, non\_full\_backward\_hooks = \[\], \[\] │
> │ 1197 │ │ if self.\_backward\_hooks or \_global\_backward\_hooks: │
> │ │
> │ /opt/miniconda3/lib/python3.9/site-packages/diffusers/models/unet\_1d\_blocks.py:524 in forward │
> │ │
> │ 521 │ def forward(self, hidden\_states, temb=None): │
> │ 522 │ │ hidden\_states = torch.cat(\[hidden\_states, temb\], dim=1) │
> │ 523 │ │ for resnet in self.resnets: │
> │ ❱ 524 │ │ │ hidden\_states = resnet(hidden\_states) │
> │ 525 │ │ │
> │ 526 │ │ return hidden\_states, (hidden\_states,) │
> │ 527 │
> │ │
> │ /opt/miniconda3/lib/python3.9/site-packages/torch/nn/modules/module.py:1194 in \_call\_impl │
> │ │
> │ 1191 │ │ # this function, and just call forward. │
> │ 1192 │ │ if not (self.\_backward\_hooks or self.\_forward\_hooks or self.\_forward\_pre\_hooks o │
> │ 1193 │ │ │ │ or \_global\_forward\_hooks or \_global\_forward\_pre\_hooks): │
> │ ❱ 1194 │ │ │ return forward\_call(\*input, \*\*kwargs) │
> │ 1195 │ │ # Do not call functions when jit is used │
> │ 1196 │ │ full\_backward\_hooks, non\_full\_backward\_hooks = \[\], \[\] │
> │ 1197 │ │ if self.\_backward\_hooks or \_global\_backward\_hooks: │
> │ │
> │ /opt/miniconda3/lib/python3.9/site-packages/diffusers/models/unet\_1d\_blocks.py:400 in forward │
> │ │
> │ 397 │ │ │ self.gelu\_2 = nn.GELU() │
> │ 398 │ │
> │ 399 │ def forward(self, hidden\_states): │
> │ ❱ 400 │ │ residual = self.conv\_skip(hidden\_states) if self.has\_conv\_skip else hidden\_state │
> │ 401 │ │ │
> │ 402 │ │ hidden\_states = self.conv\_1(hidden\_states) │
> │ 403 │ │ hidden\_states = self.group\_norm\_1(hidden\_states) │
> │ │
> │ /opt/miniconda3/lib/python3.9/site-packages/torch/nn/modules/module.py:1194 in \_call\_impl │
> │ │
> │ 1191 │ │ # this function, and just call forward. │
> │ 1192 │ │ if not (self.\_backward\_hooks or self.\_forward\_hooks or self.\_forward\_pre\_hooks o │
> │ 1193 │ │ │ │ or \_global\_forward\_hooks or \_global\_forward\_pre\_hooks): │
> │ ❱ 1194 │ │ │ return forward\_call(\*input, \*\*kwargs) │
> │ 1195 │ │ # Do not call functions when jit is used │
> │ 1196 │ │ full\_backward\_hooks, non\_full\_backward\_hooks = \[\], \[\] │
> │ 1197 │ │ if self.\_backward\_hooks or \_global\_backward\_hooks: │
> │ │
> │ /opt/miniconda3/lib/python3.9/site-packages/torch/nn/modules/conv.py:313 in forward │
> │ │
> │ 310 │ │ │ │ │ │ self.padding, self.dilation, self.groups) │
> │ 311 │ │
> │ 312 │ def forward(self, input: Tensor) -\> Tensor: │
> │ ❱ 313 │ │ return self.\_conv\_forward(input, self.weight, self.bias) │
> │ 314 │
> │ 315 │
> │ 316 class Conv2d(\_ConvNd): │
> │ │
> │ /opt/miniconda3/lib/python3.9/site-packages/torch/nn/modules/conv.py:309 in \_conv\_forward │
> │ │
> │ 306 │ │ │ return F.conv1d(F.pad(input, self.\_reversed\_padding\_repeated\_twice, mode=sel │
> │ 307 │ │ │ │ │ │ │ weight, bias, self.stride, │
> │ 308 │ │ │ │ │ │ │ \_single(0), self.dilation, self.groups) │
> │ ❱ 309 │ │ return F.conv1d(input, weight, bias, self.stride, │
> │ 310 │ │ │ │ │ │ self.padding, self.dilation, self.groups) │
> │ 311 │ │
> │ 312 │ def forward(self, input: Tensor) -\> Tensor: │
> ╰─────────────────────────────────────────────────────────────────────────────────────────────────╯
> RuntimeError: Given groups=1, weight of size \[32, 2, 1\], expected input\[1, 18, 16000\] to have 2
> channels, but got 18 channels instead
> \`\`\`
> 
> Why? Shouldn't the default parameters work out of the box?

---

<div class="post-metadata">

**Author:** ![williamberman](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/williamberman/32/14112_2.png) [@williamberman](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fwilliamberman)%5C
**Post date:** [April 14, 2023, 1:13am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Funet1dmodel-fails%2F36349%2F2 "2023-04-14T01:13:26Z")

</div>

hey @StableDiffuser317 I’m not sure how much time we have to prioritize debugging the 1 dimensional unet beyond the default configuration but please feel free to do some digging and open a PR updating the misconfiguration 🙂
