Skip to content

Instantly share code, notes, and snippets.

@jlebar
Created November 7, 2018 01:20
Show Gist options
  • Save jlebar/76e73ca2626231bd588cb03ec5f74fa3 to your computer and use it in GitHub Desktop.
Save jlebar/76e73ca2626231bd588cb03ec5f74fa3 to your computer and use it in GitHub Desktop.
Example of TF functions with uninferrable shapes
def model_fn_random_shape():
random_dim_size = tf.random_uniform(
shape=[], minval=0, maxval=5, dtype=tf.int32)
# Return a vector with a random number of elements, all of them 42.0
return tf.fill([random_dim_size], 42.)
def run_random_shapes_model():
with tf.Session() as sess:
x = tf.placeholder(tf.float32, name='x')
result = xla.compile(model_fn_random_shape)[0]
print("result = " + str(sess.run(result)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment