Can you try to reproduce the error on your machine with docker? As I cannot to reproduce with this command on my local setup:
docker run tensorflow/tensorflow:2.5.0 python -c "
import tensorflow as tf 

@tf.function()
def f(x):
    return tf.reduce_sum(x, axis=-1)


def test_autograd():
    values = tf.random.uniform((8,), seed=213)
    sizes = tf.constant([4, 2, 2])
    x = tf.RaggedTensor.from_row_lengths(values, sizes)

    with tf.GradientTape() as tape:
        tape.watch(x.flat_values)
        y = f(x)

    grad = tape.gradient(y, x.flat_values)
test_autograd()
print('Ok')
"