You are calculating gradients for different variables in case of Pytorch than in Tensorflow.
In Pytorch gradient calculation, please change the line to
grads = grad(kl_loss, [kl_loss, a_net.loc_w, a_net.scale_w, b_net.loc_w, b_net.scale_w, a_pred])