I have this for a regression problem. I am not sure why the wrong epoch is chosen for best_epoch for saving the model.
Epoch 019: | Train Loss: 0.02398 | Val Loss: 0.01437
*********************************************
    epochs variable     value
0        0    train  7.781681
1        1    train  0.099485
2        2    train  0.042489
3        3    train  0.032492
4        4    train  0.027184
5        5    train  0.027754
6        6    train  0.028582
7        7    train  0.027290
8        8    train  0.025891
9        9    train  0.027295
10      10    train  0.024953
11      11    train  0.026291
12      12    train  0.024126
13      13    train  0.024956
14      14    train  0.027561
15      15    train  0.024773
16      16    train  0.027174
17      17    train  0.024941
18      18    train  0.028399
19      19    train  0.023982
20       0      val  0.052594
21       1      val  0.020137
22       2      val  0.017723
23       3      val  0.015413
24       4      val  0.018655
25       5      val  0.016836
26       6      val  0.015303
27       7      val  0.018473
28       8      val  0.015580
29       9      val  0.015238
30      10      val  0.016674
31      11      val  0.017407
32      12      val  0.019380
33      13      val  0.017760
34      14      val  0.015137
35      15      val  0.015405
36      16      val  0.021744
37      17      val  0.019030
38      18      val  0.015155
39      19      val  0.014370
best_epoch:  16
best_val_loss:  tensor(0.0041, device='cuda:0')


and this code in order to find the best model (not sure if the logic makes sense for regression):
if val_loss < best_val_loss: 
                best_val_loss = val_loss
                best_epoch = epoch
                print('best epoch is: ', best_epoch)
                best_preds = val_preds
                best_val_target = val_targets
            # if val_acc > best_pred: 
            #     best_pred = val_acc
            #     best_epoch = epoch
            #     best_preds = val_preds
            #     best_val_labels = val_labels

                
                if not test:
                    print("saving model...")
                    torch.save(model.state_dict(), model_path + task_name + ".pth")

also
best_val_loss = 100.0
best_epoch = 0


actually, I figured my mistake but still don’t know if my method makes sense to you for best_epoch for saving the best model in regression problem:
Epoch 019: | Train Loss: 0.02677 | Val Loss: 0.01631
*********************************************
    epochs variable     value
0        0    train  7.661003
1        1    train  0.086944
2        2    train  0.038162
3        3    train  0.030772
4        4    train  0.024799
5        5    train  0.026888
6        6    train  0.024464
7        7    train  0.025889
8        8    train  0.025391
9        9    train  0.026814
10      10    train  0.025069
11      11    train  0.023473
12      12    train  0.022358
13      13    train  0.022658
14      14    train  0.023542
15      15    train  0.023952
16      16    train  0.027181
17      17    train  0.024417
18      18    train  0.025738
19      19    train  0.026772
20       0      val  0.108998
21       1      val  0.019741
22       2      val  0.027762
23       3      val  0.015706
24       4      val  0.017672
25       5      val  0.028519
26       6      val  0.021219
27       7      val  0.015313
28       8      val  0.017817
29       9      val  0.015510
30      10      val  0.016199
31      11      val  0.014752
32      12      val  0.017109
33      13      val  0.015249
34      14      val  0.015251
35      15      val  0.027797
36      16      val  0.019257
37      17      val  0.021981
38      18      val  0.015022
39      19      val  0.016308
best_epoch:  11
best_val_loss:  0.014752049872186035


and
            val_loss = val_epoch_loss/len(dataloader_val)
            if val_loss < best_val_loss:
                best_val_loss = val_loss
                best_epoch = epoch
                print('best epoch is: ', best_epoch)
                best_preds = val_preds
                best_val_target = val_targets
            # if val_acc > best_pred: 
            #     best_pred = val_acc
            #     best_epoch = epoch
            #     best_preds = val_preds
            #     best_val_labels = val_labels

                
                if not test:
                    print("saving model...")
                    torch.save(model.state_dict(), model_path + task_name + ".pth")

I fixed the problem by adding this line:
val_loss = val_epoch_loss/len(dataloader_val)