@colesbury et al. shouldn’t it be this ?
pad = (kernel_size -1) dilation + 1

For example, consider kernel size 1 and dilation 1 or kernel size 2 and dilation 1. In these cases padding should be 1 and 2 but given the equation you provided they are 0 and 1.