I think the error you’re getting might be related to this issue

  
      github.com/pytorch/pytorch
  
  
    



Issue: Problematic handling of NaN and inf in grid_sample, causing segfaults, corrupted CUDA memory, and incorrect results 14


	
	opened by bnehoran
	on 2019-08-18
	
	
	


This issue is an expansion of the issue reported in #19826.
The discussion there diagnoses the segfault that occurs in the vectorized...




  
  
    
    
  
  


If so, the problem probably occurs whenever your predicted grid happens to contain an infinite or NaN value. Perhaps your model’s predictions blow up during training, or else you are dividing somewhere by a value that can sometimes be 0?
We will hopefully be able to fix this issue in grid_sample to handle these values without crashing, but in the mean time, my best recommendation for a workaround is to check for any NaN or infinite values in your grid (perhaps using torch.isfinite 8) and replacing them with some stand-in value before passing to grid_sample.