The code actually mostly runs for me (except the call missing parameters).
There is, however, no reason to not just use python ints for the crop_d,h,w calculation (as in crop_h_floor = (x.size(3)-height)//2 and crop_h_ceil = crop_h_floor = (x.size(3)-height+1)//2 and then using those in the pad call.
Best regards
Thomas