Hi , thanks for your advice it did remove that error but in turn this came up:
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-12-cd1866fff827> in <module>()
----> 1 train(data1[0:10],data2[0:10],128,1,128,128,10000)

<ipython-input-6-66e52529e52f> in train(data1, data2, embedding_size, n_layers, input_size, hidden_size, num_epochs)
     33             dec.zero_grad()
     34             print l
---> 35             l.backward()#retain_variables = True)
     36             optimizer.step()
     37 

/usr/local/lib/python2.7/dist-packages/torch/autograd/variable.pyc in backward(self, gradient, retain_variables)
    144                     'or with gradient w.r.t. the variable')
    145             gradient = self.data.new().resize_as_(self.data).fill_(1)
--> 146         self._execution_engine.run_backward((self,), (gradient,), retain_variables)
    147 
    148     def register_hook(self, hook):

RuntimeError: there are no graph nodes that require computing gradients

So , I have added the requires_grad attribute to every variable defined and do we add detach old graph after every backward pass or the old graph is preserved ? if we need to detach the old the graph then how do we need to do it?