In [1]:
from utils import *


/home/ubuntu/anaconda2/lib/python2.7/site-packages/matplotlib/font_manager.py:273: UserWarning: Matplotlib is building the font cache using fc-list. This may take a moment.
  warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.')
Using gpu device 0: Tesla K80 (CNMeM is disabled, cuDNN 5103)
/home/ubuntu/anaconda2/lib/python2.7/site-packages/theano/sandbox/cuda/__init__.py:600: UserWarning: Your cuDNN version is more recent than the one Theano officially supports. If you see any problems, try updating Theano or downgrading cuDNN to version 5.
  warnings.warn(warn)
Using Theano backend.

In [32]:
lr = K.variable(0.1)

In [33]:
ones = K.variable(np.ones(3))

In [34]:
lr, ones


Out[34]:
(<CudaNdarrayType(float32, scalar)>, <CudaNdarrayType(float32, vector)>)

In [35]:
lr * ones


Out[35]:
Elemwise{mul,no_inplace}.0

In [36]:
fn1 = K.function([], [], updates=[(ones, lr * ones)])

In [37]:
lr.get_value(), ones.get_value()


Out[37]:
(array(0.10000000149011612, dtype=float32),
 array([ 1.,  1.,  1.], dtype=float32))

In [38]:
fn1([])
ones.get_value()


Out[38]:
array([ 0.1,  0.1,  0.1], dtype=float32)

In [39]:
lr.set_value(10.0)
fn1([])
ones.get_value()


Out[39]:
array([ 1.,  1.,  1.], dtype=float32)

In [40]:
lr = 0.001

In [41]:
lr * ones


Out[41]:
Elemwise{mul,no_inplace}.0

In [43]:
fn2 = K.function([], [], updates=[(ones, lr * ones)])
fn2([])
ones.get_value()


Out[43]:
array([ 0.001,  0.001,  0.001], dtype=float32)

In [44]:
lr = 1000.0
fn2([])
ones.get_value()


Out[44]:
array([  1.0000e-06,   1.0000e-06,   1.0000e-06], dtype=float32)

In [52]:
model = Sequential([Dense(1, input_shape=(1,))])
model.compile(optimizer=Adam(), loss='mse')
model.fit(np.array([1.0]), np.array([3.0]), nb_epoch=1, verbose=0)
model.optimizer.updates


Out[52]:
[(<CudaNdarrayType(float32, scalar)>, Elemwise{add,no_inplace}.0),
 (<CudaNdarrayType(float32, matrix)>, Elemwise{add,no_inplace}.0),
 (<CudaNdarrayType(float32, matrix)>, Elemwise{add,no_inplace}.0),
 (dense_2_W, Elemwise{sub,no_inplace}.0),
 (<CudaNdarrayType(float32, vector)>, Elemwise{add,no_inplace}.0),
 (<CudaNdarrayType(float32, vector)>, Elemwise{add,no_inplace}.0),
 (dense_2_b, Elemwise{sub,no_inplace}.0)]