How to achieve off-network gradient propagation

Deep neural network output is a,convert output to numpy further call external PyPardiso library for matrix solving to get U. Loss function is a function of U. Please ask how to implement gradient update of loss function to network parameters.