Created
November 7, 2018 01:18
-
-
Save jlebar/4702d287165ad30f6412d70a6c5370d0 to your computer and use it in GitHub Desktop.
Simple example of using xla.compile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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