Exceptional behavior when parameter groups is not equal to 1

George-Jiao: <p>I’ m runing the code:</p>
<pre><code class="lang-auto">import torch
te_y = torch.ones([1,4,10])    # torch.Size([1, 4, 10])
operator = torch.tensor([[[1.0, -2.0, 1.0]]]) # torch.Size([1, 1, 3])
torch.nn.functional.conv1d(te_y, operator, padding=1, groups=4)
</code></pre>
<p>get the error reporting with:</p>
<pre><code class="lang-auto">Given groups=4, expected weight to be at least 4 at dimension 0, but got weight of size [1, 1, 3] instead
</code></pre>
<p>But as the docs say:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/4/c4e8398b0a33fd6de737f8ab2bd873104804cf12.png" data-download-href="https://discuss.pytorch.org/uploads/default/c4e8398b0a33fd6de737f8ab2bd873104804cf12" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c4e8398b0a33fd6de737f8ab2bd873104804cf12_2_690x244.png" alt="image" data-base62-sha1="s5V7EJtQjuwug6kEqQLnQbQd9ce" width="690" height="244" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/c/4/c4e8398b0a33fd6de737f8ab2bd873104804cf12_2_690x244.png, https://discuss.pytorch.org/uploads/default/original/3X/c/4/c4e8398b0a33fd6de737f8ab2bd873104804cf12.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/c/4/c4e8398b0a33fd6de737f8ab2bd873104804cf12.png 2x" data-dominant-color="E4ECF0"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1013×359 32.9 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>It should be no error. I want to preform the 1d conv in the each 4 in_channels with the same weight by set the groups as the 4.</p>

Andrei_Cristea: <p>In the code you actually pass <code>groups=1</code> to nn.functional.conv1d, did you mean to write <code>groups=2</code>?</p>
<p>Just to clarify, what part of the docs suggest there should be no error? If <code>groups=2</code> and <code>in_channels=4</code>, then the 2nd dimension of weight needs to be 2 (=in_channels/groups), in your case it is 1.</p>
<p>For instance, this works:</p>
<pre><code class="lang-auto">import torch
B  = 1  # minibatch
IC = 4  # in-channels
G  = 2  # groups
OC = 2  # out-channels, multiple of groups
N  = 10 # spatial dimension of orig tensor
W  = 3  # spatial dimension of convolution

te_y = torch.ones([B, IC, N])
operator = torch.rand(OC, IC//G, W)
torch.nn.functional.conv1d(te_y, operator, padding=1, groups=G)

Output:
tensor([[[2.7952, 4.2234, 4.2234, 4.2234, 4.2234, 4.2234, 4.2234, 4.2234,
          4.2234, 2.6473],
         [1.9053, 3.6016, 3.6016, 3.6016, 3.6016, 3.6016, 3.6016, 3.6016,
          3.6016, 3.0767]]])
</code></pre>

George-Jiao: <p>Thanks for your answer! I know how to revised my code. I should to set the out_channel to the 4.<br>
It’s my fault to explain my question wrongly and I have revised the question. I want to perform the 1d conv in the each 4 in_channels with the groups = 4.<br>
Thank you again.</p>