Thanks. Yes i used if __name__ =='__main__': and also I tried running my script on command prompt too but same problem. However by changing num_worker of DataLoader to zero solves the problem. But I am still not sure why changing it any value other than 0 makes a difference? Is there anything wrong in my code?