0

I am writing a custom op, and I got stucked when writing the backward part.

When I call out_grad[0].asnumpy() or do any manipulation of the out_grad, the program crash without any error message.

I tried fill the in_grad with zeros, the program run smoothly, but I need the grad to flow backward. def backward(self, req, out_grad, in_data, out_data, in_grad, aux): self.assign(in_grad[0], req[0], 0) self.assign(in_grad[1], req[1], 0)

What's going wrong here?

Zehao Shi
  • 99
  • 8

2 Answers2

1

Custom Operator in MXNet show us how to define a loss function using custom op. The loss op is very special because it doesn't need grad to be flow into.

But in my situation, I need grad to flow into my op. So, the function below should return the dependency instead of empty as in loss op.

def declare_backward_dependency(self, out_grad, in_data, out_data):
    return [out_grad[0]]

In my opinion, the dependency is some variable which the gradient should be delievered to.

Zehao Shi
  • 99
  • 8
0

Have you tried to follow the tutorial here for developing a Custom Operator in MXNet.

If that does not help, provide your full code of the Custom operator along with some sample data and a simple model with which this issue can be easily reproduced.

Naveen Swamy
  • 109
  • 8
  • Yes. The tutorial show us how to define a loss function using custom op. The loss op is very special because it doesn't need grad to be flow into. I have found what is going wrong. I'm now posting my solution. – Zehao Shi Jun 21 '17 at 07:51