# Why do state stops gradients in tf.GradientTape？

**URL:** <https://discuss.ai.google.dev/t/why-do-state-stops-gradients-in-tf-gradienttape/30002>\
**Category:** General Discussion\
**Tags:** tfcore, help\_request\
**Created:** [May 30, 2022, 1:32am UTC](https://discuss.ai.google.dev/t/why-do-state-stops-gradients-in-tf-gradienttape/30002 "2022-05-30T01:32:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yangchenhao](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/yangchenhao/32/11560_2.png) [@yangchenhao](https://discuss.ai.google.dev/u/yangchenhao)\
**Post date:** [May 30, 2022, 1:32am UTC](https://discuss.ai.google.dev/t/why-do-state-stops-gradients-in-tf-gradienttape/30002/1 "2022-05-30T01:32:44Z")

</div>

```auto
x0 = tf.Variable(3.0)
x1 = tf.Variable(0.0)

with tf.GradientTape(persistent=True) as tape:
  # Update x1 = x1 + x0.
  x1.assign_add(x0)
  # The tape starts recording from x1.
  y = x1**2 # y = (x1 + x0)**2

# This doesn't work.
print(tape.gradient(y, x0)) #dy/dx0 = 2*(x1 + x0)

```

The result of the above code is None, and I want to know why it is designed this way?  
Thanks.

---

<div class="post-metadata">

**Author:** ![chunduriv](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@chunduriv](https://discuss.ai.google.dev/u/chunduriv)\
**Post date:** [August 4, 2023, 6:02am UTC](https://discuss.ai.google.dev/t/why-do-state-stops-gradients-in-tf-gradienttape/30002/3 "2023-08-04T06:02:14Z")

</div>

@yangchenhao,

Shouldn’t it be `print(tape.gradient(y, x1))` as you are adding `x0` to `x1` during the gradient tape?

Thank you!
