Backward CNN with multiple output

I’m now reimplementing the “Holistically-nested Edge Detection”(arXiv) with pytorch, which has multiple “side-outputs”.

So how can I backward CNN with multiple outputs ? This thread suggested to use torch.autograd.backward([x1, x2], [grad_x1, grad_x2]), but I run into error with this solution, following is my error message:

Traceback (most recent call last):
  File "", line 68, in <module>
  File "", line 63, in train
    torch.autograd.backward(outputs, grads)
  File "/usr/local/lib/python2.7/dist-packages/torch/autograd/", line 98, in backward
    variables, grad_variables, retain_graph)

My code can be summarized as follow:

outputs = model(data)
loss, grads = some_numpy_tricks(outputs)
torch.autograd.backward(outputs, grads)
print "now loss=%f"%loss

In which outputs is a list containing multiple outputs of the model, and grads is the list containing gradients of loss w.r.t each model output.

So why did error occur and what’s the correct solution for my case?

this seems like a cudnn bug.
Can you give me a way to reproduce this on my side?

You can also try setting this flag (at the beginning of your script) and see if it goes away: torch.backends.cudnn.benchmark=True

1 Like

Hi Smth, sorry to bothering you again.

I met the new error:

RuntimeError: dependency not found for N5torch8autograd12ConvBackwardE

I have been working on this for long but cannot solve the problem.

I have committed the code to Gitlab, could you please help me to solve this problem?

which version of pytorch are you on? print(torch.__version__), how did you install pytorch (conda or pip)? and what OS are you on?

Thanks for your reply, my environments are as follow:

In [2]: print torch.__version__

Installed via pip following the official instructions.

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 


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

The error mentioned before occurs both on CPU and GPU mode, so it seems not to be a CUDA problem.

I’m really hoping that after you upgraded to v0.2.0, this issue has gone.

OK, I will update to v0.2 and retry.

Thank you.

@zeakey Hi, have you finished the reimplementing? Will you public your code?

Though don’t know why, it did work. Thanks so much.