Skip to content

Instantly share code, notes, and snippets.

@jlebar
Created November 7, 2018 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlebar/4702d287165ad30f6412d70a6c5370d0 to your computer and use it in GitHub Desktop.
Save jlebar/4702d287165ad30f6412d70a6c5370d0 to your computer and use it in GitHub Desktop.
Simple example of using xla.compile
from tensorflow.contrib.compiler import xla
def model_fn(x, y, z):
return tf.reduce_sum(x + y * z)
def create_and_run_graph():
with tf.Session() as sess:
x = tf.placeholder(tf.float32, name='x')
y = tf.placeholder(tf.float32, name='y')
z = tf.placeholder(tf.float32, name='z')
result = xla.compile(computation=model_fn, inputs=(x, y, z))[0]
# `result` is a normal Tensor (albeit one that is computed by an XLA
# compiled executable) and can be used like any other Tensor.
result = tf.add(result, result)
return sess.run(result, feed_dict={ ... })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment