# Auto Differentiation

**URL:** <https://d2l.discourse.group/t/auto-differentiation/35>\
**Category:** pytorch\
**Created:** [May 22, 2020, 3:44am UTC](https://d2l.discourse.group/t/auto-differentiation/35 "2020-05-22T03:44:59Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![anirudh](https://yyz2.discourse-cdn.com/free1/user_avatar/d2l.discourse.group/anirudh/32/180_2.png) [@anirudh](https://d2l.discourse.group/u/anirudh)\
**Post date:** [June 12, 2020, 1:03pm UTC](https://d2l.discourse.group/t/auto-differentiation/35/8 "2020-06-12T13:03:44Z")

</div>

Answer to **first** question.  
`tensor.detach()` creates a tensor that shares the same storage with `tensor` that does not require grad.  
But `tensor.clone()` will also give you original tensor’s requires\_grad attributes. It is basically an exact copy including the computation graph.

Use `detach()` to remove a tensor from computation graph and use `clone` to copy the tensor while still keeping the copy as a part of the computation graph it came from.

The **second** answer about "the meaning of **d / a**" in 2.5.4.  
“a.grad == (d / a)” is true because if you see how d is calculate using f(a). It is basically scaling a by some constant factor k. And if you were to do differentiate such a function say function `d=k*a` with respect to a then you would get that k. Hence these are true and obviously it won’t hold for b because d is a function of which scales a and not b.

Answer to **third** question.  
As i suggested earlier and you probably did it, you can simply `pip install d2l` to import torch from d2l.  
If you want to import the specific rename imtorch.py just add this to the start of your code before making the import. →

```auto
import sys
sys.path.insert(0, "../")

```

Let me know if these answers solve your issue. 🙂

---

_[View the full topic](https://d2l.discourse.group/t/auto-differentiation/35)._
