torch.autograd.Function does not know anything about converting to CPU or GPU.
If you want to make your code run fine on both CPU and GPU, you need to make it generic.
A few tips:

calling torch.FloatTensor will always put your tensor in the CPU. You probably want to get the device in which the input tensor is by doing something like pred_out.new(), which will generate a new tensor in the same device as pred_out.
you are using np.ndarray in parts of your code. While it’s possible to do it, it will avoid parts of your code to run in the GPU
Performing for loops for the computations that you want will probably be slower in the GPU than in the CPU. You’d probably want to wrap some inner loops using only batched mathematical operations in tensors so that it can be efficiently computed in the GPU, so that instead of accepting one bounding box, you accept a bunch of them at the same time.