Conv2: .cuda() does not work as expected (Runtime Error for argument weight)

username: VasLem
cooked: <p>I have a problem that I cannot justify and I need an expert opinion as it might be architecture-related.<br>
So I define a fresh Xception-based model, which is the following (Xception block is also provided):</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/a/ac6d11db1ef1452e90f6fa05be1a7e442345b441.png" data-download-href="https://discuss.pytorch.org/uploads/default/ac6d11db1ef1452e90f6fa05be1a7e442345b441" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/a/ac6d11db1ef1452e90f6fa05be1a7e442345b441_2_477x500.png" alt="image" data-base62-sha1="oBlNXpyh1aq48Ys8cYcVtUGCCXL" width="477" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/a/ac6d11db1ef1452e90f6fa05be1a7e442345b441_2_477x500.png, https://discuss.pytorch.org/uploads/default/optimized/2X/a/ac6d11db1ef1452e90f6fa05be1a7e442345b441_2_715x750.png 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/a/ac6d11db1ef1452e90f6fa05be1a7e442345b441.png 2x" data-dominant-color="F0F0F0"><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">775×811 75.8 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><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/9/9c479cfaab26721f82546a38105d9dacf19fae0a.png" data-download-href="https://discuss.pytorch.org/uploads/default/9c479cfaab26721f82546a38105d9dacf19fae0a" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/9/9c479cfaab26721f82546a38105d9dacf19fae0a_2_656x500.png" alt="image" data-base62-sha1="mivUMXGjumfa9gWW3AjMOlsff6O" width="656" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/9/9c479cfaab26721f82546a38105d9dacf19fae0a_2_656x500.png, https://discuss.pytorch.org/uploads/default/original/2X/9/9c479cfaab26721f82546a38105d9dacf19fae0a.png 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/9/9c479cfaab26721f82546a38105d9dacf19fae0a.png 2x" data-dominant-color="EDEDED"><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">850×647 98.3 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>I then run:</p>
<pre><code class="lang-auto">model = SamplingSegmentation(3, 1, 6).cuda()
out = model(torch.ones((5, 3, 64, 64)).cuda())
</code></pre>
<p>And the error is:<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/a/acdc7dd09177f0109cfc7b6b130aefefdbfe5c55.png" data-download-href="https://discuss.pytorch.org/uploads/default/acdc7dd09177f0109cfc7b6b130aefefdbfe5c55" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/a/acdc7dd09177f0109cfc7b6b130aefefdbfe5c55_2_352x500.png" alt="image" data-base62-sha1="oFcwAMWmxG1mXg81Jg4vTNZ0wg5" width="352" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/a/acdc7dd09177f0109cfc7b6b130aefefdbfe5c55_2_352x500.png, https://discuss.pytorch.org/uploads/default/original/2X/a/acdc7dd09177f0109cfc7b6b130aefefdbfe5c55.png 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/a/acdc7dd09177f0109cfc7b6b130aefefdbfe5c55.png 2x" data-dominant-color="F5F8F7"><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">519×736 96.7 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>Does anyone know why this is happening? Printing the the input to the SeparableConvolution tells me it is already in cuda.</p>

username: ptrblck
cooked: <p>It seems you are using plain Python lists to store submodules in your model.<br>
While this might work logically in your forward method, the submodules won’t be properly registered, so that e.g. <code>model.parameters()</code> won’t show these parameters.<br>
Also, <code>.to()</code> or <code>.cuda()</code> calls won’t have any effect on the submodules, as is here the case.</p>
<p>Instead you should use <code>nn.ModuleList</code> to add your modules, which will properly register them.</p>
<p>PS: It’s always better to post code snippets and wrap them in three backticks ```, so that this code will be searchable in the discussion board and we could copy it in case we would like to debug it <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

username: VasLem
cooked: <p>Thank you, your advice saved my day, I just enclosed the modules list inside a nn.ModuleList and the problem was fixed. I will keep your other note in mind the next time I post something.</p>