Assertion Error running Dustin's Coin Flipping Toy Example

Hello, I am new to Edward. I tried running Dustin’s sample coin flipping example, and keep running into an Assertion Error with ed.complete_conditional§. I also run into the same error in completely separate code. What am I doing wrong? Thanks for any guidance. Ikib

from future import absolute_import
from future import division
from future import print_function

import edward as ed
import numpy as np
import six
import tensorflow as tf

from edward.models import Bernoulli, Beta

def main(_):


x_data = np.array([0, 1, 0, 0, 0, 0, 0, 0, 0, 1])


p = Beta(1.0, 1.0)
x = Bernoulli(probs=p, sample_shape=10)


p_cond = ed.complete_conditional§

sess = ed.get_session()

print(‘p(probs | x) type:’, p_cond.parameters[‘name’])
param_vals ={key: val for
key, val in six.iteritems(p_cond.parameters)
if isinstance(val, tf.Tensor)}, {x: x_data})
for key, val in six.iteritems(param_vals):
print(’%s:\t%.3f’ % (key, val))

if name == “main”:

AssertionError Traceback (most recent call last)
in ()
24 if name == “main”:
—> 25

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\platform\ in run(main, argv)
124 # Call the main function, passing through any arguments
125 # to the final program.
–> 126 _sys.exit(main(argv))

in main(_)
—> 12 p_cond = ed.complete_conditional§
14 sess = ed.get_session()

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\edward\inferences\conjugacy\ in complete_conditional(rv, cond_set)
157 scope_name = scope + str(time.time()) # ensure unique scope when copying
–> 158 log_joint_copy = copy(log_joint, swap_dict, scope=scope_name + ‘swap’)
159 nat_params = tf.gradients(log_joint_copy, s_stat_placeholders)

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\edward\util\ in copy(org_instance, dict_swap, scope, replace_itself, copy_q, copy_parent_rvs)
268 # op. Therefore copy the op itself.
269 op = tensor.op
–> 270 new_op = copy(op, dict_swap, scope, True, copy_q, False)
272 output_index = op.outputs.index(tensor)

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\edward\util\ in copy(org_instance, dict_swap, scope, replace_itself, copy_q, copy_parent_rvs)
314 [], # input types; will add them afterwards
315 original_op,
–> 316 op_def)
318 # advertise op early to break recursions

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ in init(self, node_def, g, inputs, output_types, control_inputs, input_types, original_op, op_def)
1730 # Refactor so we don’t have to do this here.
1731 grouped_inputs = self._reconstruct_sequence_inputs(
-> 1732 op_def, inputs, node_def.attr)
1733 self._c_op = _create_c_op(self._graph, node_def, grouped_inputs,
1734 control_input_ops)

c:\users\bikim\appdata\local\conda\conda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ in _reconstruct_sequence_inputs(self, op_def, inputs, attrs)
1804 i += input_len
-> 1806 assert i == len(inputs)
1807 return grouped_inputs


Hi, I encountered this bug today aswell and was able to bypass it in tensorflow 1.8.
The error is actually not specific to the Coin Flipping example, indeed you get this error when you try to use edward’s copy function in tensorflow>=1.8.

There are currently at least 2 tensorflow-1.8 related bugs in edward, which are related to tensorflow switching to the C-API for graphs by default since tf 1.8.
e.g. tf.Session().graph._c_graph is None in tf 1.7 but not in 1.8.
The first bug and a fix is described here.

The second bug, which you are seeing, is because edwards’ copy function creates a tf.Operation with the argument inputs=[] with the comment that the inputs are added later.
However, using the C-API in the backend for the graph, tf.Operation apparently requires non-empty inputs.
In tensorflow 1.8, you may bypass this bug by setting the environment variable TF_C_API_GRAPH_CONSTRUCTION=0. I don’t think it works for current tf 1.9 though, as the constructor of the Operation class changed and does not check for self.graph._c_graph anymore.