HLO (High-level Optimizer) is the hardware-agnostic XLA compiler component that analyzes and optimizes the mathematical computation graph. On TPUs, the Low Level Optimizer (LLO) is the lowest-level compiler in the XLA stack. It is responsible for TPU-specific optimizations for execution on the "bare metal" silicon.
HLO and LLO dumps capture detailed information about your computation graph at various stages of the XLA compilation pipeline. Generating these dumps is the first step in many debugging workflows, and you often need to include them in bug reports.
An HLO dump is typically a human-readable text file that lists the HLO instructions and their properties across compilation stages. Sometimes, HLO modules are dumped as:
- HloProto: Protocol buffer files, which are a more structured, machine-readable format.
- HloSnapshot: An HLO module plus its inputs. For replaying HLOs, you sometimes require the actual inputs fed to a given computation rather than random data.
You can use XLA flags to configure and capture dumps. In most cases, you set them with environment variables, and JAX also provides programmatic APIs to print or dump HLOs.
Basic configuration: Enable HLO dumps
Enable HLO dumping by setting the XLA_FLAGS environment variable:
export XLA_FLAGS="--xla_dump_to=<output_directory> --xla_dump_hlo_as_text"
Or set TPU init args as environment variables:
export LIBTPU_INIT_ARGS="--xla_dump_to=<output_directory>"
For example, you can use /tmp/xladump as <output_directory>.
By default, this dumps HLO modules as text, at the very beginning and end of the optimization pipeline.
Enable LLO dumps (TPU)
On TPU, generate LLO dumps by passing --xla_jf_dump_to via
LIBTPU_INIT_ARGS (and not XLA_FLAGS):
export LIBTPU_INIT_ARGS="--xla_jf_dump_to=<output_directory>"
Include LLO fingerprints
Fingerprints are generated by hashing all the relevant components of instructions, and is useful for comparing LLOs.
# Enable fingerprints
--xla_jf_dump_category_filter=fingerprint
# Enable "show your work"
--xla_jf_dump_extended_fingerprint=true
# Limit fingerprint calculation to 1-2 passes
# at start and end of LLO compilation
--xla_jf_dump_limit_fingerprints=true
More configuration
Dump HLO in specific formats
You can explicitly specify one or more dump formats:
- Text dumps
export XLA_FLAGS="--xla_dump_hlo_as_text --xla_dump_to=<output_directory>"
- HLO protos
export XLA_FLAGS="--xla_dump_hlo_as_proto --xla_dump_to=<output_directory>"
- HLO snapshots
export XLA_FLAGS="--xla_dump_hlo_snapshots --xla_dump_to=<output_directory>"
- Graph render with Graphviz server (only works well for small graphs)
export XLA_FLAGS="--xla_dump_hlo_as_url --xla_dump_to=<output_directory>"
- Graph render to HTML file (only works well for small graphs)
export XLA_FLAGS="--xla_dump_hlo_as_html --xla_dump_to=<output_directory>"
For larger graphs, you can use interactive_graphviz to visualize parts of the
graph.
You can also configure HLO dumps to use syntactic sugar wrappers as op names by
setting --xla_syntax_sugar_async_ops=true. This can reduce the dump size by
about 20%. By default, this flag is false, and actual op names are used:
export XLA_FLAGS="--xla_dump_to=<output_directory> --xla_syntax_sugar_async_ops=true"
Dump specific intermediate passes
In addition to the standard pre-optimized / final-optimized HLOs, you can also dump the state of HLOs after a particular compiler pass.
export XLA_FLAGS="--xla_dump_hlo_pass_re=<regex> --xla_dump_to=<output_directory>"
HLO modules are dumped for passes whose names match the regular expression. For example, to observe the HLOs resulting from passes related to SPMD partitioning:
export XLA_FLAGS="--xla_dump_to=<output_directory> --xla_dump_hlo_pass_re=spmd|propagation"
To dump the result after every XLA pass (which produces many files), set
--xla_dump_hlo_pass_re=.*:
export XLA_FLAGS="--xla_dump_to=<output_directory> --xla_dump_hlo_pass_re=.*"
Set LLO bundle formats: single or multi-line
For LLO dump files containing packed bundles, each instruction in a bundle is
printed on the same line by default, delimited by ;;. This keeps the bundle
count roughly equal to the line count and gives a visual sense of bundle
packing density from line lengths.
Example:
0x13 : > { %s43 = sshrl.u32 %s12724, 10 ;; %s12725 = smul.u32 3072, %s33 }
0x14 : > { %p40 = scmp.ge.s32.totalorder %s39, 5 ;; %s45 = sshrl.u32 %s12725, 10 }
To print each instruction on its own line instead, pass
--xla_tpu_instructions_on_separate_lines via LIBTPU_INIT_ARGS:
export LIBTPU_INIT_ARGS="--xla_jf_dump_to=<output_directory> \
--xla_tpu_instructions_on_separate_lines"
Example:
0x13 : > { %s43 = sshrl.u32 %s12724, 10
%s12725 = smul.u32 3072, %s33 }
0x14 : > { %p40 = scmp.ge.s32.totalorder %s39, 5
%s45 = sshrl.u32 %s12725, 10 }
This makes it easier to find individual instructions and opcodes with less line-wrapping.
Set LLO category filter
You can restrict LLO dump categories using --xla_jf_dump_category_filter with
a comma-separated list of categories. Common categories include:
original: Limits dumps to the initial, unoptimized LLO IR generated by the emitters, before optimization passes.codegen: Limits dumps to final code generation and utilization artifacts, such as packed bundles and post*RA LLO.fingerprint: Triggers LLO fingerprint generation.program: Outputs specific to the final executable.msa: Generates Memory Space Assignment (MSA) outputs.Example usage:
export LIBTPU_INIT_ARGS="--xla_jf_dump_to=<output_directory> \
--xla_jf_dump_category_filter=original,codegen"
Some dump utilities render the entire string in memory rather than streaming it out, which can lead to Out of Memory (OOM) errors at compile time. Restricting dumps to specific categories can help mitigate this.
Understand the core HLO & LLO dump files
These files contain the computation graph (HLO instructions) and represent the state of the module or LLO stages at various points of the compilation pipeline.
module_####.<module_name>.before_optimizations- The unoptimized HLO graph. This is the raw graph translated directly from the higher-level framework (like JAX or TensorFlow) before XLA applies any optimizations.
- Use case: Ideal for checking if the framework expressed your logic/math correctly.
module_####.<module_name>.after_optimizations- The fully optimized HLO graph. This is the graph immediately before it is lowered into backend-specific lower-level IRs (like LLO for TPUs or LLVM IR for GPUs/CPUs).
- Use case: Ideal for inspecting optimization decisions like operator fusion, layout assignment, or memory buffer allocations.
Example output files
Dumping HLO and LLO generates several text files in the output directory:
- HLO dumps use filenames prefixed with
module_####.<module_name>(optionally preceded by a timestamp), plus metadata and optimization stage suffixes. - LLO dumps use filenames formatted as
<timestamp>-<hlo_name>-<NN>-<stage>.txt, where<NN>is a two-digit pass sequence number so alphabetical sorting matches the chronological LLO stage order.
An example HLO file listing looks like:
module_0007.jit_matmul.cl_963683785.target_arguments.txt
module_0003.jit_broadcast_in_dim.cl_963683785.flagfile
module_0000.jit_convert_element_type.cl_963683785.debug_options
module_0000.jit_convert_element_type.cl_963683785.target_arguments.txt
module_0003.jit_broadcast_in_dim.cl_963683785.transfer_stats.txt
module_0003.jit_broadcast_in_dim.cl_963683785.hlo_module_config.txt
module_0003.jit_broadcast_in_dim.cl_963683785.basic_compiler_metadata.txt
module_0003.jit_broadcast_in_dim.cl_963683785.after_optimizations-buffer-assignment.txt
module_0000.jit_convert_element_type.cl_963683785.after_optimizations-live-range.txt
module_0000.jit_convert_element_type.cl_963683785.after_optimizations-buffer-assignment.txt
module_0007.jit_matmul.cl_963683785.after_optimizations.txt
module_0000.jit_convert_element_type.cl_963683785.execution_options.txt
module_0000.jit_convert_element_type.cl_963683785.after_optimizations-buffer-assignment-values.txt
module_0000.jit_convert_element_type.cl_963683785.transfer_stats.txt
module_0003.jit_broadcast_in_dim.cl_963683785.after_optimizations-memory-usage-report.txt
module_0007.jit_matmul.cl_963683785.tpu_comp_env.txt
module_0000.jit_convert_element_type.cl_963683785.basic_compiler_metadata.txt
module_0000.jit_convert_element_type.cl_963683785.flagfile
module_0000.jit_convert_element_type.cl_963683785.hlo_module_config.txt
module_0003.jit_broadcast_in_dim.cl_963683785.before_optimizations.txt
module_0007.jit_matmul.cl_963683785.before_optimizations.txt
module_0000.jit_convert_element_type.cl_963683785.after_optimizations.txt
module_0003.jit_broadcast_in_dim.cl_963683785.after_codegen.txt
...
An example LLO file listing looks like:
1677035272597175285-fusion.51157-00-pre-auto-mxu-assigner.txt
1677035272597175285-fusion.51157-01-original.txt
1677035272597175285-fusion.51157-02-post-invert-loops.txt
1677035272597175285-fusion.51157-03-post-CP.txt
1677035272597175285-fusion.51157-04-post-simplifier-1.txt
1677035272597175285-fusion.51157-05-post-bf16-coalescing.txt
1677035272597175285-fusion.51157-06-post-GVN.txt
1677035272597175285-fusion.51157-07-post-DCE.txt
1677035272597175285-fusion.51157-08-post-simplifier-2.txt
1677035272597175285-fusion.51157-09-post-MXU-assigner.txt
1677035272597175285-fusion.51157-10-post-GVN-2.txt
1677035272597175285-fusion.51157-11-post-DCE-2.txt
1677035272597175285-fusion.51157-12-post-bounds-check.txt
1677035272597175285-fusion.51157-13-pre-cssa.txt
1677035272597175285-fusion.51157-14-post-cssa.txt
1677035272597175285-fusion.51157-15-post-decomposer.txt
1677035272597175285-fusion.51157-16-post-constant-materializer.txt
1677035272597175285-fusion.51157-17-post-llo-dependency-graph-optimizations.txt
1677035272597175285-fusion.51157-18-post-GVN-3.txt
1677035272597175285-fusion.51157-19-post-DCE-3.txt
1677035272597175285-fusion.51157-20-post-constant-materializer.txt
1677035272597175285-fusion.51157-21-register-pressure.txt
1677035272597175285-fusion.51157-22-schedule-analysis_packed-bundles-pre-ra.txt
1677035272597175285-fusion.51157-23-packed-bundles-pre-ra.txt
1677035272597175285-fusion.51157-24-post-bundle-packing-pre-ra.txt
1677035272597175285-fusion.51157-25-post-grt.txt
1677035272597175285-fusion.51157-26-pre-finalize-registers-and-allocations.txt
1677035272597175285-fusion.51157-27-pre-availability-transform.txt
1677035272597175285-fusion.51157-28-post-availability-transform.txt
1677035272597175285-fusion.51157-29-post-ra.txt
1677035272597175285-fusion.51157-30-post-scalar-select-transform.txt
1677035272597175285-fusion.51157-31-schedule-analysis_packed-bundles-no-ra-deps.txt
1677035272597175285-fusion.51157-32-packed-bundles-no-ra-deps.txt
1677035272597175285-fusion.51157-33-post-bundle-packing-no-ra-deps.txt
1677035272597175285-fusion.51157-34-region-expansion-no-ra-deps.txt
1677035272597175285-fusion.51157-35-schedule-analysis_packed-bundles-post-ra.txt
1677035272597175285-fusion.51157-36-packed-bundles-post-ra.txt
1677035272597175285-fusion.51157-37-post-bundle-packing-post-ra.txt
1677035272597175285-fusion.51157-38-region-expansion.txt
1677035272597175285-fusion.51157-39-schedule-analysis_final_bundles.txt
1677035272597175285-fusion.51157-40-final_bundles.txt
Some dump files represent linearized LLO at that stage, some contain packed bundles, and some contain summaries or reports.
Platform-specific setup
Google Colab
In the first executed cell of your notebook (because environment variables and
command-line flags are usually only processed once, e.g., at module-import time
or XLA backend initialization time), set XLA_FLAGS with os.environ, for
example:
import os
os.environ['XLA_FLAGS'] = "--xla_dump_to=<output_directory>"
On TPU runtimes, set LLO dump flags in os.environ['LIBTPU_INIT_ARGS'] as well
before initializing the backend:
import os
os.environ['LIBTPU_INIT_ARGS'] = "--xla_jf_dump_to=<output_directory>"
This writes the dumps to <output_directory>, for example /tmp/xladump. On
Colab, navigate to the "Files" browser in the left sidebar to view and access
this directory.
You can use all the flags covered in Enable HLO dumps, Enable LLO dumps (TPU), and More configuration.
JAX-specific options
Programmatically in JAX
Instead of passing flags or environment variables, you can programmatically
inspect or dump HLO using JAX's lower and compile APIs.
Print the unoptimized lowered HLO directly:
def f(x):
return jax.numpy.sin(jax.numpy.cos(x))
print(jax.jit(f).lower(3.).as_text('hlo'))
# Equivalent via compiler_ir():
c = jax.jit(f).lower(3.).compiler_ir('hlo')
print(c.as_hlo_text())
Directly print a computation's optimized HLO:
def optimized_hlo(f, *args, platform=None):
print(jax.jit(f).lower(*args).compile().as_text())
def f(x):
return jax.numpy.sin(jax.numpy.cos(x))
optimized_hlo(f, 1.0)
Dump HLO files during compilation by passing compiler options to compile():
compilation_args = {
'xla_dump_to': '<output_directory>',
'xla_dump_hlo_pass_re': 'spmd|propagation', # or another pass regex
}
jax.jit(f).lower(*args).compile(compilation_args)
Dump jaxprs
jaxprs are JAX's intermediate
representation for program traces. To dump them, set:
export JAX_DUMP_IR_TO="<output_directory>"
export JAX_DUMP_IR_MODES="jaxpr"
Learn more in the JAX documentation on Exporting and serializing staged-out computations: Debugging.
Dump all or small computations
If you want to include every compilation in a dump, including small ones, set the JAX environment variable:
export JAX_COMPILER_DETAILED_LOGGING_MIN_OPS=0
Dump Mosaic computations
Mosaic is a compiler for the Pallas TPU backend and the experimental Pallas GPU
backend. --xla_mosaic_dump_to is an ABSL_FLAG (not an XLA_FLAGS
DebugOptions flag). On TPU, pass it through LIBTPU_INIT_ARGS:
export LIBTPU_INIT_ARGS="--xla_mosaic_dump_to=/tmp/mosaic_dumps"
Or pass it directly as a command-line flag to binaries that register it:
--xla_mosaic_dump_to=/tmp/mosaic_dumps
Check out the JAX documentation on Pallas and Mosaic to learn more.
More with HLO & LLO dumps
Finding the right computation
Usually, many computations get dumped. The dumped files are explicitly named with the JAX, Tensorflow, or PyTorch/XLA "computation name" that are called out in the logs, making it easy to identify the relevant HLO files. For example:
1624325116260738.module_0065.pmap__unnamed_wrapped_function_.186875.before_optimizations.txt
Otherwise, you can use ripgrep to quickly identify which module holds
particular symbols or computations.
Tip: Include the 3 dumped before_optimizations, after_optimizations, and
buffer-assignment files of interest in your bug reports.
Visualize with XProf
The XProf Graph Viewer tool can help you visualize the unoptimized HLO graph and extract the relevant HLO text in various formats.
HLO conversion
The hlo-opt tool can translate between HloProto and text formats, which is
useful when you have one format and need the other for debugging.
Learn how to use it in the XLA Tooling documentation: hlo-opt.
Replay
You can run (replay) the dumped computations on a specified XLA backend with fake data or input snapshots. This is a convenient way to reproduce, iterate, and debug issues in XLA.
The following commands use fake data. If you have saved HloSnapshots, you
can pass those instead, and the data from the snapshot is used. To still use
fake data while running a snapshot, pass --force_fake_data.
CPU backend:
bazel run -c opt //xla/hlo/tools:run_hlo_module -- --platform=cpu \
/tmp/xladump/module_4561.before_optimizations.txt
GPU backend:
bazel run -c opt //xla/hlo/tools:run_hlo_module -- --platform=CUDA \
/tmp/xladump/module_4561.before_optimizations.txt