Solved by Chirath_Pansilu in post #3 
              
              
                Try adding optimizer.zero_grad() in the batch loop 
In your code your’e accumulating gradients in the batch loop . So you need to clear gradients in the batch loop rather than in the epoch loop