The first line of the error suggests that there is a device mismatch. Are you moving the loss to the cpu midway?
And make sure the loss is a result of differentiable functions on the input, else the training won’t work. I don’t know if the indicator_functions are.