Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient

username: promach
cooked: <p>For <a href="https://gist.github.com/buttercutter/b6f526c56e20f029d68e6f9041c3f5c0/d367642c1f2b69d3bf6c2a95860b4f113d0d59bb#file-gdas-py" rel="noopener nofollow ugc">this pytorch coding</a> , why do I have this runtime issue : <a href="https://gist.github.com/buttercutter/b6f526c56e20f029d68e6f9041c3f5c0/d367642c1f2b69d3bf6c2a95860b4f113d0d59bb#file-runtime-log" rel="noopener nofollow ugc">Cannot insert a Tensor that requires grad as a constant. Consider making it a parameter or input, or detaching the gradient</a></p>

username: promach
cooked: <p>After some debugging, it seems that the runtime error revolves around the variable <code>self.edges_results</code> which had in some way modified how tensorflow sees it.</p>
<p>So, setting variables <code>VISUALIZER</code> and <code>DEBUG</code> to zero (which will remove any tensorflow dependencies) will just <em>temporarily</em> eliminate the runtime error.</p>
<p>Any suggestions/advice ?</p>

username: promach
cooked: <p>One possible solution:</p>
<p>It seems that tensorflow does not like the use of <code>self.variable</code> inside <code>def forward()</code> unlike in Pytorch.  Tensorflow prefers the use of a new intermediate variable instead of <code>self.variable</code></p>
<p>So, the <a href="https://gist.github.com/buttercutter/b6f526c56e20f029d68e6f9041c3f5c0/revisions#diff-7f9700d4b68b7fd4fdda21847d9d4b86255cb18ef01e1ef87bbf8beaf3e5254e" rel="noopener nofollow ugc">following major change</a> is what seems to have resolved the issue.</p>
<p>Any comments ?</p>
<p>Note: <a href="https://github.com/D-X-Y/AutoDL-Projects/issues/99#issuecomment-835802887" rel="noopener nofollow ugc">Some more coding effort is needed to further modify the code</a> since the <a href="https://i.imgur.com/eC7Hwhx.png" rel="noopener nofollow ugc">output tensorboard graph</a> seems so much smaller and rather unconnected as a result.</p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/9/b/9b961556af5670f569e86c2991e3d4c0e6173aa6.png" data-download-href="https://discuss.pytorch.org/uploads/default/9b961556af5670f569e86c2991e3d4c0e6173aa6" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/9/b/9b961556af5670f569e86c2991e3d4c0e6173aa6_2_690x371.png" alt="image" data-base62-sha1="mcnyIJ2eoXtvRsFnuvHGlxwT0y2" width="690" height="371" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/9/b/9b961556af5670f569e86c2991e3d4c0e6173aa6_2_690x371.png, https://discuss.pytorch.org/uploads/default/optimized/3X/9/b/9b961556af5670f569e86c2991e3d4c0e6173aa6_2_1035x556.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/9/b/9b961556af5670f569e86c2991e3d4c0e6173aa6_2_1380x742.png 2x" data-dominant-color="1A191B"><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">1922×1034 84.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>