@krishna511  I dont see much change in the difference you are training your model by the earlier approach for the expected gpu error there r several ways u can avoid it for example by calling

torch.cuda.empty_cache()

after each epoch will help you probably.