liveBook · Manning

XLA

As explained in Deep Learning with Python, Third Edition

Accelerated Linear Algebra, TensorFlow's optional compiler used to further optimize and speed up function execution.

XLA, short for Accelerated Linear Algebra, is TensorFlow's high-performance compiler for optimizing function execution. It provides a faster compilation path than ordinary graph mode, with the trade-off of additional work during the first call. section 3.1 section 3.3.1

Compile a TensorFlow function with XLA

Add jit_compile=True to a TensorFlow function: @tf.function(jit_compile=True) def dense(inputs, W, b): return tf.nn.relu(tf.matmul(inputs, W) + b). TensorFlow compiles dense into an optimized program; the first call takes longer, while later calls can run faster. section 3.3.1

Use XLA with a simple workflow:

  • Debug the function in the ordinary Python runtime first. section 3.3.1
  • Apply @tf.function to enable TensorFlow graph mode. section 3.3.1
  • Set jit_compile=True when the extra compilation work is worthwhile. section 3.3.1
@tf.function(jit_compile=True)
def dense(inputs, W, b):
    return tf.nn.relu(tf.matmul(inputs, W) + b)

Inspect the compact TensorFlow example that enables XLA for a dense operation. section 3.3.1

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains activation, first-call overhead, and later speedups, but does not descend into compiler internals.
Examples
Demonstrates XLA by compiling a TensorFlow dense function containing matrix multiplication and ReLU.
What it assumes
Assumes familiarity with TensorFlow functions and tf.function while emphasizing runtime debugging before compilation.
What you can do after
Apply it via TensorFlow's jit_compile=True option after debugging the function in Python.
How it connects
Connects TensorFlow with graph mode, TPUs, GPUs, and JAX through compilation and hardware acceleration.

Also explained in

Compare how 3 books explain XLA →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.