I have been implementing layers for my application. One of my layers has an explicit backward function. In that layer, the forward function takes a tensor input. However, it creates a numpy copy of it and uses it. This is because inside this layer there is a call to another library which computes the output of this layer. The forward function assigns that library’s output to a tensor and outputs that tensor. A loss function is computed based on this output. I can see that this is breaking the backpropagation path. I get the error: “element 0 of tensors does not require grad and does not have a grad_fn”. But how to fix it? How to make PyTorch bridge the path from this Layer’s output to the previous layers? I have tried setting requires_grad = True for the output tensor, inside the forward function, for which I get the error “leaf variable has been moved into the graph interior”. I have tried setting requires_grad = True, outside, i.e., in the main function after this layer is called and before the loss function. I get the error “unsupported operand type(s) for *: ‘float’ and ‘NoneType’”, when I update my parameters through gradient descent.