Using other 3rd party libraries such as numpy or scipy will detach these operations from the computation graph, which would be the case in:
D_til_inv = torch.from_numpy(scipy.linalg.fractional_matrix_power(D_til, (-1/2))).cuda()

If you don’t need or want to calculate the gradients for preceding operations, your code should work fine.
Otherwise you would need to either use PyTorch methods or write a custom autograd.Function as described here.