After few digging I have found a workaround that does not change the targets. The code snippet is given below.
## Iterations
for i in range(20):
    print("Iter No:",i)
    for xtr,ytr in dataloader:
        #print("Iter No:",i)
        #optimizer.zero_grad()
        y_tr = [{k:v for k,v in t.items()} for t in ytr]
        #print("In train before:")
        output = model(xtr,y_tr)
        #print("In train after")
        print(ytr)

Instead of  directly sending targets  ytr , I am creating another variable y_tr with same contents as that of ytr and sending that to the model. This does not change the value of targets.