'Tensorflow assign_sub not updating values

I have two TF variables that are both the same shape. When I call the assign_sub method on one of them, it does not seem to perform the operation. I have had the same results using tf sub. Does anyone know why this occurs and how I can fix it? Bellow is taken from my jupyter notebook.

Many thanks for any help!

w1
<tf.Variable 'Variable:0' shape=(784, 200) dtype=float32, numpy=
array([[-0.00517749,  0.00802523, -0.0166106 , ...,  0.07224225,
         0.00734451, -0.04644822],
       [-0.00716587,  0.02453488, -0.02327951, ..., -0.04119773,
         0.03330942, -0.06695535],
       [ 0.0342979 ,  0.01537804,  0.00616781, ..., -0.02635622,
         0.02543317, -0.10961799],
       ...,
       [-0.06884291,  0.03944634,  0.00704791, ...,  0.09215239,
        -0.0011345 , -0.0416344 ],
       [ 0.00044725,  0.04232293,  0.06169483, ..., -0.01707994,
        -0.07201626, -0.03409686],
       [-0.00368566, -0.01963305, -0.05840254, ...,  0.01990965,
        -0.00817258,  0.00537805]], dtype=float32)>

w2
<tf.Tensor: shape=(784, 200), dtype=float32, numpy=
array([[ 2.11303495e-13,  8.10649508e-13, -2.57005734e-13, ...,
         5.05237399e-13, -1.01372578e-13,  1.07068786e-13],
       [ 1.18608231e-11, -9.10568062e-12, -6.91622454e-12, ...,
         8.96156760e-12, -6.27301726e-12, -9.66544986e-13],
       [ 1.00307686e-10, -1.66703994e-11, -1.10054750e-10, ...,
         1.12350018e-10, -1.54337272e-11,  2.23625597e-11],
       ...,
       [-1.18554699e-09, -1.32580569e-09,  1.17279297e-09, ...,
        -4.93490693e-10,  5.27944355e-09,  4.86970464e-10],
       [-1.39517775e-09, -1.04426978e-09,  2.03556771e-09, ...,
        -1.12062248e-09,  2.76391743e-10,  1.14915535e-10],
       [-6.50262344e-11, -1.25571095e-10,  1.51342119e-10, ...,
        -4.65945928e-11, -4.77228326e-11,  4.47814286e-11]], dtype=float32)>

w1.assign_sub(w2)
<tf.Variable 'UnreadVariable' shape=(784, 200) dtype=float32, numpy=
array([[-0.00517749,  0.00802523, -0.0166106 , ...,  0.07224225,
         0.00734451, -0.04644822],
       [-0.00716587,  0.02453488, -0.02327951, ..., -0.04119773,
         0.03330942, -0.06695535],
       [ 0.0342979 ,  0.01537804,  0.00616781, ..., -0.02635622,
         0.02543317, -0.10961799],
       ...,
       [-0.06884291,  0.03944634,  0.00704791, ...,  0.09215239,
        -0.0011345 , -0.0416344 ],
       [ 0.00044725,  0.04232293,  0.06169482, ..., -0.01707994,
        -0.07201626, -0.03409686],
       [-0.00368566, -0.01963305, -0.05840254, ...,  0.01990965,
        -0.00817258,  0.00537805]], dtype=float32)>

w1
<tf.Variable 'Variable:0' shape=(784, 200) dtype=float32, numpy=
array([[-0.00517749,  0.00802523, -0.0166106 , ...,  0.07224225,
         0.00734451, -0.04644822],
       [-0.00716587,  0.02453488, -0.02327951, ..., -0.04119773,
         0.03330942, -0.06695535],
       [ 0.0342979 ,  0.01537804,  0.00616781, ..., -0.02635622,
         0.02543317, -0.10961799],
       ...,
       [-0.06884291,  0.03944634,  0.00704791, ...,  0.09215239,
        -0.0011345 , -0.0416344 ],
       [ 0.00044725,  0.04232293,  0.06169482, ..., -0.01707994,
        -0.07201626, -0.03409686],
       [-0.00368566, -0.01963305, -0.05840254, ...,  0.01990965,
        -0.00817258,  0.00537805]], dtype=float32)>


Solution 1:[1]

I don't think there is a problem in the op assign_sub, but The values of w2 are too small: -0.00517749 - 2.11303495e-13 = -0.00517749

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tou You