# What does doing .backward twice do?

**URL:** <https://discuss.pytorch.org/t/what-does-doing-backward-twice-do/58057>\
**Category:** Uncategorized\
**Created:** [October 12, 2019, 11:04pm UTC](https://discuss.pytorch.org/t/what-does-doing-backward-twice-do/58057 "2019-10-12T23:04:11Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![pinocchio](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/pinocchio/32/22093_2.png) [@pinocchio](https://discuss.pytorch.org/u/pinocchio)\
**Post date:** [October 13, 2019, 4:30pm UTC](https://discuss.pytorch.org/t/what-does-doing-backward-twice-do/58057/3 "2019-10-13T16:30:24Z")

</div>

need to read:

> [@How does one obtain gradients as data efficiently?](https://discuss.pytorch.org/t/how-does-one-obtain-gradients-as-data-efficiently/58059/4):
>
> the whole code just for reference: ''' This script is written to test: 1)what happens if we differentiate through pytorch's backward pass and to see if its consistent with the doing a second derivative ''' import torch import torch.nn as nn from grad\_test\_sympy import symbolic\_test import sys from pdb import set\_trace as st def test\_does\_backward\_backward\_match\_second\_derivative(experiment\_type,grad\_computation\_type='dl\_dw\_zero\_grad'): ''' 1)what happens if we differentiate th…

and

> [@Clone and detach in v0.4.0](https://discuss.pytorch.org/t/clone-and-detach-in-v0-4-0/16861/2):
>
> We’ll provide a migration guide when 0.4.0 is officially released. Here are the answers to your questions: tensor.detach() creates a tensor that shares storage with tensor that does not require grad. tensor.clone()creates a copy of tensor that imitates the original tensor's requires\_grad field. You should use detach() when attempting to remove a tensor from a computation graph, and clone as a way to copy the tensor while still keeping the copy as a part of the computation graph it came from. …

---

_[View the full topic](https://discuss.pytorch.org/t/what-does-doing-backward-twice-do/58057)._
