KLqp for RNN giving AttributeError: 'NoneType' object has no attribute 'outer_context'

Hi, I am facing an issue while running variational inference using KLqp on an RNN model. Here are the details of my code
def rnn_cell(hprev, x):
return tf.tanh(ed.dot(hprev, Wh) + ed.dot(x, Wx) + bh)

Wx = Normal(loc=tf.zeros([n_i, n_h]), scale=tf.ones([n_i,n_h]))
Wh = Normal(loc=tf.zeros([n_h, n_h]), scale=tf.ones([n_h, n_h]))
Wy = Normal(loc=tf.zeros([n_h, n_o]), scale=tf.ones([n_h, n_o]))
bh = Normal(loc=tf.zeros(n_h), scale=tf.ones(n_h))
by = Normal(loc=tf.zeros(n_o), scale=tf.ones(n_o))

x = tf.placeholder(tf.float32, [None, n_i], name=‘x’)
h = tf.scan(rnn_cell, x, initializer=tf.zeros(n_h))
y = Normal(loc=tf.matmul(h, Wy) + by, scale = 1.0*tf.ones(N))

qWx = Normal(loc=tf.get_variable(“qWx/loc”, [n_i, n_h]),scale=tf.nn.softplus(tf.get_variable(“qWx/scale”, [n_i, n_h])))
qWh = Normal(loc=tf.get_variable(“qWh/loc”, [n_h, n_h]),scale=tf.nn.softplus(tf.get_variable(“qWh/scale”, [n_h, n_h])))
qWy = Normal(loc=tf.get_variable(“qWy/loc”, [n_h, n_o]),scale=tf.nn.softplus(tf.get_variable(“qWy/scale”, [n_h, n_o])))
qbh = Normal(loc=tf.get_variable(“qbh/loc”, [n_h]),scale=tf.nn.softplus(tf.get_variable(“qbh/scale”, [n_h])))
qby = Normal(loc=tf.get_variable(“qby/loc”, [n_o]),scale=tf.nn.softplus(tf.get_variable(“qby/scale”, [n_o])))

inference = ed.KLqp({Wx:qWx, Wh:qWh, Wy:qWy, bh:qbh, by:qby}, data={x: x_train, y: y_train})
inference.run(n_iter=1000, n_samples=5)

Getting the following ERROR
/Applications/anaconda/lib/python2.7/site-packages/tensorflow/python/ops/control_flow_ops.pyc in AddWhileContext(self, op, between_op_list, between_ops)
1257 if grad_state is None:
1258 # This is a new while loop so create a grad state for it.
-> 1259 outer_forward_ctxt = forward_ctxt.outer_context
1260 if outer_forward_ctxt:
1261 outer_forward_ctxt = outer_forward_ctxt.GetWhileContext()

AttributeError: ‘NoneType’ object has no attribute ‘outer_context’

I am using Tensorflow 1.7.0 since I faced other issues with using Edward on higher versions. I have seen the same AttributeError reported on stack overflow for other use cases of TensorFlow, but not found a practical solution reported anywhere. Thanks in advance for the help.