# A little code problem

**URL:** <https://discuss.pytorch.org/t/a-little-code-problem/85854>\
**Category:** Uncategorized\
**Created:** [June 18, 2020, 12:49am UTC](https://discuss.pytorch.org/t/a-little-code-problem/85854 "2020-06-18T00:49:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![caokx](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/c/3d9bf3/32.png) [@caokx](https://discuss.pytorch.org/u/caokx)\
**Post date:** [June 18, 2020, 12:49am UTC](https://discuss.pytorch.org/t/a-little-code-problem/85854/1 "2020-06-18T00:49:52Z")

</div>

a = torch.tensor([4.], requires\_grad=True)  
print(a)  
b = a.pow(3)  
print(b)  
b.backward()  
print(a.grad)

tensor([4.], requires\_grad=True)  
tensor([64.], grad\_fn=)  
tensor([48.])

is the a.grad=3?

---

<div class="post-metadata">

**Author:** ![harsha\_g](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@harsha\_g](https://discuss.pytorch.org/u/harsha_g)\
**Post date:** [June 18, 2020, 2:20am UTC](https://discuss.pytorch.org/t/a-little-code-problem/85854/2 "2020-06-18T02:20:11Z")

</div>

Not sure what exactly the question is. But, read `a.grad` as the derivative of `b` with respect to `a` which in this case is `3*(4^2) = 48`.

---

<div class="post-metadata">

**Author:** ![ziqipang](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/z/6bbea6/32.png) [@ziqipang](https://discuss.pytorch.org/u/ziqipang)\
**Post date:** [June 18, 2020, 2:22am UTC](https://discuss.pytorch.org/t/a-little-code-problem/85854/4 "2020-06-18T02:22:00Z")

</div>

I was just wanting to reply the same. Agree with you!
