Backward CNN with multiple output

username: zeakey
cooked: <p>I’m now reimplementing the “Holistically-nested Edge Detection”(<a href="https://arxiv.org/abs/1504.06375" rel="nofollow noopener">arXiv</a>) with pytorch, which has multiple “side-outputs”.</p>
<p>So how can I backward CNN with multiple outputs ? This <a href="https://discuss.pytorch.org/t/how-to-do-backward-for-a-net-with-multiple-outputs/87">thread</a> suggested to use <code>torch.autograd.backward([x1, x2], [grad_x1, grad_x2])</code>, but I run into error with this solution, following is my error message:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "main.py", line 68, in &lt;module&gt;
    train()
  File "main.py", line 63, in train
    torch.autograd.backward(outputs, grads)
  File "/usr/local/lib/python2.7/dist-packages/torch/autograd/__init__.py", line 98, in backward
    variables, grad_variables, retain_graph)
RuntimeError: CUDNN_STATUS_MAPPING_ERROR
</code></pre>
<p>My code can be summarized as follow:</p>
<pre><code class="lang-auto">outputs = model(data)
loss, grads = some_numpy_tricks(outputs)
torch.autograd.backward(outputs, grads)
print "now loss=%f"%loss
</code></pre>
<p>In which <code>outputs</code> is a list containing multiple outputs of the model, and  <code>grads</code> is the list containing gradients of loss w.r.t each model output.</p>
<p>So why did error occur and what’s the correct solution for my case?</p>

username: smth
cooked: <p>this seems like a cudnn bug.<br>
Can you give me a way to reproduce this on my side?</p>
<p>You can also try setting this flag (at the beginning of your script) and see if it goes away: <code>torch.backends.cudnn.benchmark=True</code></p>

username: zeakey
cooked: <p>Hi Smth, sorry to bothering you again.</p>
<p>I met the new error:</p>
<pre><code>RuntimeError: dependency not found for N5torch8autograd12ConvBackwardE
</code></pre>
<p>I have been working on this for long but cannot solve the problem.</p>
<p>I have committed the code to <a href="https://gitlab.com/zeakey/pytorch-hed" rel="nofollow noopener">Gitlab</a>, could you please help me to solve this problem?</p>

username: smth
cooked: <p>which version of pytorch are you on? <code>print(torch.__version__)</code>, how did you install pytorch (conda or pip)? and what OS are you on?</p>

username: zeakey
cooked: <p>Thanks for your reply, my environments are as follow:<br>
PyTorch:</p>
<pre><code>In [2]: print torch.__version__
0.1.12_2
</code></pre>
<p>Installed via pip following the official instructions.<br>
OS:</p>
<pre><code>uname -a
Linux server01 4.4.0-72-generic #93~14.04.1-Ubuntu SMP Fri Mar 31 15:05:15 UTC 2017 x86_64 x86_64 x86_64 
GNU/Linux
</code></pre>
<p>CUDA:</p>
<pre><code>nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2016 NVIDIA Corporation
Built on Sun_Sep__4_22:14:01_CDT_2016
Cuda compilation tools, release 8.0, V8.0.44
</code></pre>
<p>The error mentioned before occurs both on CPU and GPU mode, so it seems not to be a CUDA problem.</p>

username: smth
cooked: <p>I’m really hoping that after you upgraded to v0.2.0, this issue has gone.</p>

username: zeakey
cooked: <p>OK, I will update to v0.2 and retry.</p>
<p>Thank you.</p>

username: XuKai
cooked: <p><a class="mention" href="/u/zeakey">@zeakey</a>   Hi, have you finished the reimplementing? Will you public your code?</p>

username: Matthew_Wong
cooked: <p>Though don’t know why, it did work. Thanks so much.</p>