Question: I am trying to migrate my previous tf1 code to tf2. Unfortunately my code was not on eager mode so I am having more difficulties. I did the following code (not yet training) and I got into the error message: 

```
Traceback (most recent call last):
    training_op = tf.assign(W, W - learning_rate * gradients)
AttributeError: module 'tensorflow' has no attribute 'assign'

```

This is my minimum code example PS: it has to work with complex numbers!

```
# Data pre-processing
    m = 50
    n = 20
    x_train, y_train, x_test, y_test = get_my_data(x, y, m, n) # data x of size mxn

    # Network Declaration
    input_size = n
    output_size = 1
    learning_rate = 0.001  # The optimization learning rate
    # Create weight matrix initialized randomely from N~(0, 0.01)
    W = tf.Variable(tf.complex(np.random.rand(input_size, output_size),
                               np.random.rand(input_size, output_size)), name="weights")

    with tf.GradientTape() as gtape:
        y_out = tf.matmul(x_train, W, name="out")
        error = y - y_out
        loss = tf.reduce_mean(tf.square(tf.abs(error)), name="mse")
        gradients = gtape.gradient(loss, [W])[0]
        training_op = tf.assign(W, W - learning_rate * gradients)

```

I do this manually because unless they changed that, optimizers are not supported for complex numbers so I do it "by hand".

Answer: 
`tf.assign*` functions are available as methods on [`tf.Variable`](https://www.tensorflow.org/api_docs/python/tf/Variable) in TF 2.0. So, your example could be rewritten as

```
with tf.GradientTape() as gtape:
    ...
    W.assign_sub(learning_rate * gradients)

```

Note that unlike `tf.assign` in TF 1.X, [`tf.Variable.assing_sub`](https://www.tensorflow.org/api_docs/python/tf/Variable#assign_sub) will execute the assignment eagerly.
Try `tf.compat.v1.assign` instead. 
It worked for me.