RuntimeError: Function AddmmBackward returned an invalid gradient at index 1 - got [16, 2048] but expected shape compatible with [16, 32768]

username: Peter_Lee1
cooked: <p>Hello. I am trying to train a plain VAE on my custom dataset. I’m transforming the images into a (3,256,256) tensor and feeding it into the dataloader. The input and output tensors match, but when I run loss.backward(), it gives me the below error message:</p>
<p>“RuntimeError: Function AddmmBackward returned an invalid gradient at index 1 - got [16, 2048] but expected shape compatible with [16, 32768]”</p>
<p>Can you please clarify the issue and propose a solution? Thank you very much in advance.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/b/9/b9a9521c468d1b881a8cece178e53a772bc8394c.png" data-download-href="https://discuss.pytorch.org/uploads/default/b9a9521c468d1b881a8cece178e53a772bc8394c" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/b/9/b9a9521c468d1b881a8cece178e53a772bc8394c.png" alt="image" data-base62-sha1="qur6cBEn7s2itjxs6NWpwkMuNis" width="300" height="500" data-dominant-color="F1F1F1"><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">417×693 14.1 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>

username: Peter_Lee1
cooked: <p>Below are additional snips of the code…</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/6/a/6acc537e2c6a8bf31adba5b18c5357dab3963c78.png" data-download-href="https://discuss.pytorch.org/uploads/default/6acc537e2c6a8bf31adba5b18c5357dab3963c78" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/6/a/6acc537e2c6a8bf31adba5b18c5357dab3963c78.png" alt="image" data-base62-sha1="feMntnSEOuTkA3cHXiK9PJvLVHi" width="323" height="500" data-dominant-color="EEEFEF"><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">459×709 22.6 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>

username: Peter_Lee1
cooked: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/1/1/11cffade98e4ee5b13b5fc743a202a45b218062a.png" data-download-href="https://discuss.pytorch.org/uploads/default/11cffade98e4ee5b13b5fc743a202a45b218062a" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/1/1/11cffade98e4ee5b13b5fc743a202a45b218062a.png" alt="image" data-base62-sha1="2xzI8WH9oHX99laek3KkbHPvem6" width="393" height="500" data-dominant-color="EEEFEF"><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">581×738 29.6 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>

username: Peter_Lee1
cooked: <p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/e/9eff429e4a3c2a39cb105209dd582191f9aaf852.png" data-download-href="https://discuss.pytorch.org/uploads/default/9eff429e4a3c2a39cb105209dd582191f9aaf852" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/9/e/9eff429e4a3c2a39cb105209dd582191f9aaf852.png" alt="image" data-base62-sha1="mGykDsI8X9K6rOAI2HsJi9Ak8fg" width="690" height="425" data-dominant-color="F6F5F6"><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">943×582 27.5 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>

username: ptrblck
cooked: <p>Please don’t post images as we cannot copy/paste the code in order to debug and the forum search also won’t be able to index your post.<br>
You can post code snippets by wrapping them into three backticks ```, which would make debugging easier <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=10" title=":wink:" class="emoji" alt=":wink:"><br>
Make sure the code is executable (i.e. we can copy it and directly execute).</p>