tensorflow/tensorflow
Compilers
TensorFlow has accumulated several compilers and lowering paths. They all turn TF graphs into something more efficient — XLA HLO, MLIR dialects, TFLite flatbuffers, or static C++ binaries.
| Page | What it covers | Code under |
|---|---|---|
| XLA / tf2xla / JIT / AOT | TF→HLO lowering, JIT auto-clustering, ahead-of-time tfcompile |
tensorflow/compiler/tf2xla/, jit/, aot/ |
| MLIR | The MLIR dialects TF defines and the passes between them | tensorflow/compiler/mlir/, tensorflow/core/ir/, tensorflow/core/transforms/ |
| TensorRT integration | NVIDIA TensorRT subgraph fusion | tensorflow/compiler/tf2tensorrt/ |
How they connect
graph LR
Graph[TF Graph or FuncGraph]
Grappler[Grappler]
JIT[JIT auto-clustering]
TF2XLA[tf2xla]
MLIR[MLIR pipeline tf -> mhlo -> stablehlo]
HLO[XLA HLO]
XLA[XLA compiler in openxla/xla]
Device[CPU/GPU/TPU exec]
AOT[tfcompile AOT]
Static[Static C++ binary]
TF2TRT[tf2tensorrt]
TRT[TensorRT engine]
TFLite[TFLite flatbuffer]
Graph --> Grappler
Grappler --> JIT
JIT -- chosen subgraphs --> TF2XLA
Graph --> MLIR
MLIR --> HLO
TF2XLA --> HLO
HLO --> XLA
XLA --> Device
Graph --> AOT
AOT --> XLA
AOT --> Static
Graph --> TF2TRT
TF2TRT --> TRT
MLIR -- tfl dialect --> TFLiteWhat lives where
- The XLA compiler core (HLO IR, optimization passes, codegen) was extracted to
openxla/xlain 2023. This repo only contains the bridge code (TF↔XLA) undertensorflow/compiler/. - MLIR is used by both the new TFLite converter and the new TF compiler stack. Dialects and passes live under
tensorflow/compiler/mlir/. - TensorRT (NVIDIA's inference compiler) integration is under
tensorflow/compiler/tf2tensorrt/and produces aTRTEngineOpthat runs the engine inline in a TF graph. - AOT (
tfcompile) generates static C++ libraries for an XLA-compiled function — the path used to ship inference models without bringing the whole TF runtime.
Compiler vs runtime
The boundary is fuzzy:
- Compilers transform graphs offline (or at first call) and emit some artifact (HLO, TF executable, TFLite flatbuffer, static lib).
- Runtimes then execute the artifact (core-runtime, TFRT, TFLite, or XLA's runtime in
openxla/xla).
A tf.function(jit_compile=True) call straddles both: the compiler runs at first call, the runtime runs the resulting executable on subsequent calls.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.