You do the similar thing of rewrapping your result into a Tensor after doing computations on non differentiable elements (python numbers in your case, integer tensors in the other post).
You will have to keep everything into Tensors for the autograd to work.