How to use gradient of neural network as the loss function?

Perhaps @ChrisRackauckas could help out here?