Hi Ptrblck,
Sorry, for finding the best number of epoch, I use the list of validation loss from all  epochs. and then convert the list to the numpy array to find the minimum loss and index and get the optimum epoch there.
with the CPU it works good but when I run the code with GPU it give me error, the code is 
val_lossesArray=np.asarray(val_losses)
   vvv2=torch.from_numpy(val_lossesArray)
   result = np.where(val_lossesArray == np.amin(val_lossesArray))
   vv1=result[-1]
   EpochFinal=vv1[0]
   print("best epoch",Epoc) ```


and the error is ( result = np.where(val_lossesArray == np.amin(val_lossesArray))
TypeError: eq() received an invalid combination of arguments - got (numpy.ndarray), but expected one of:
* (Tensor other)
     didn't match because some of the arguments have invalid types: (!numpy.ndarray!)
* (Number other)
     didn't match because some of the arguments have invalid types: (!numpy.ndarray!)
)