liveBook · Manning

Just-in-time compilation

As explained in Deep Learning with R, Third Edition

Just-in-time compilation is the compilation of program code during execution into an optimized form for subsequent execution.

Just-in-time compilation converts program code during execution into an optimized form that can run faster afterward. In TensorFlow, wrap a function with tf_function() to compile its operations. section 3.3.1

Compiling a TensorFlow function

A dense layer can first be expressed as an ordinary R function, then wrapped with tf_function(). Setting jit_compile = TRUE requests just-in-time compilation for the wrapped computation. section 3.3.1

The technique appears alongside core numerical and automatic-differentiation operations:

  • TensorFlow connects compilation with tensors, variables, numerical operations, and GradientTape. section 3.3.1
  • JAX likewise treats just-in-time compilation as a way to make functions fast, alongside arrays, random operations, and gradients. section 3.5.1
library(tensorflow)
library(keras3)
use_backend("tensorflow")

Select the TensorFlow backend before experimenting with the compilation examples. section 3.3.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Demonstrates function wrapping and an explicit JIT option, but does not explain compiler internals or optimization details.
Examples
Uses a TensorFlow dense-layer function with tf_function() and jit_compile = TRUE, plus JAX setup for analogous compilation.
What it assumes
Assumes basic TensorFlow or JAX function, tensor, and numerical-operation usage while introducing compilation in that context.
What you can do after
Apply it via TensorFlow by wrapping a numerical function with tf_function() and enabling jit_compile when requested.
How it connects
Connects tensors, variables, numerical operations, automatic differentiation, TensorFlow, JAX, and functions.

Also explained in

Compare how 7 books explain just-in-time compilation →

Related concepts

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