Sorry, I didn’t get a ping for this. Could you check if any of the images are full of zeros? (after you apply the mean-centering?). And, check there are no infs or NaNs in your image before preconditioning.
images = torch.from_numpy(Norm_image.astype(np.double)).cuda() #shape [1000,255,255]

print(torch.isnan(images).any())
print(torch.isinf(images).any())

Also, could you try the following code and see if the NaN issue goes away?
#use torch.linalg.svd instead of torch.svd
#this returns V already transposed (so more efficient)
U, S, VT = torch.linalg.svd(images) 
images_from_svd = U @ S.diag_embed() @ VT 




 Ahmad_Khan:

X = images.reshape(nImage, h*w)


Is this reshape right, perhaps you could be introducing the NaN when mean-centering your images? If Images is shape [B,W,H] you could just do image_mean = images.mean(dim=(-1,-2)) then image_norm = image - image_mean (which is then passed to torch.linalg.svd(image_norm))
Also, remember to write code wrapped around 3 backticks ``` so it’s shown nicely!