You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by gi...@git.apache.org on 2017/07/31 16:35:44 UTC

[GitHub] piiswrong commented on issue #7268: Autograd retain_graph=True bugs

piiswrong commented on issue #7268: Autograd retain_graph=True bugs
URL: https://github.com/apache/incubator-mxnet/issues/7268#issuecomment-319125769
 
 
   Your code works for me. Although the right way to do it is either
   ```
   with autograd.record():
       output, hidden = encoder(mx.nd.ones((8, 8, 300)), encoder_begin_state)
   
       hidden_detached = [i for i in hidden]
   
       prediction, _ = decoder(mx.nd.ones((8, 8, 300)), hidden_detached)
       l = loss(prediction, expected_label)
   
   l.backward()
   ```
   
   or
   
   ```
   with autograd.record():
       output, hidden = encoder(mx.nd.ones((8, 8, 300)), encoder_begin_state)
   
       hidden_detached = [i.detach() for i in hidden]
       for i in hidden_detached:
           i.attach_grad()
   
       prediction, _ = decoder(mx.nd.ones((8, 8, 300)), hidden_detached)
       l = loss(prediction, expected_label)
   
   l.backward()
   autograd.backward(hidden, [hidden_detached[0].grad, hidden_detached[1].grad])
   ```
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services