TensorFlow
TensorFlow is Google's open-source machine learning platform for building, training and deploying models across servers, mobile and the web. Learn its ecosystem.
Overview
TensorFlow is an open-source machine learning platform created at Google. At its core it is a library for computing with tensors, which are multi-dimensional arrays, with automatic differentiation so that models can learn from data. Around that core sits a large family of tools: the Keras API for building models, tf.data for input pipelines, TensorFlow Serving for production servers, TensorFlow.js for browsers and TFX for end-to-end pipelines.
What sets TensorFlow apart is its focus on the whole life of a model, not only training. A model can be trained on GPUs or Cloud TPUs, saved in a standard format, served behind an API, and converted for phones and embedded devices. Many large organisations built production systems on it during the late 2010s, and those systems are still running.
An everyday picture is a factory with its own design office, assembly line and shipping department. Other workshops may be quicker for building a prototype, but this factory already has the loading bays, packaging and delivery routes needed to send the finished product to many different destinations.
What it is
TensorFlow is best understood as a core plus an ecosystem.
| Part | Purpose |
|---|---|
Core (tf) |
Tensors, operations, automatic differentiation with tf.GradientTape, devices |
tf.function |
Turns Python functions into optimised graphs |
| XLA | A compiler that fuses operations for faster execution on CPUs, GPUs and TPUs |
| Keras | The high-level API for layers, models and training loops |
tf.data |
Fast, parallel input pipelines for loading and transforming data |
tf.distribute |
Strategies for training across several GPUs, machines or TPUs |
| SavedModel | The standard on-disk format for trained models |
| TensorFlow Serving | A high-performance server for SavedModels over gRPC and REST |
| TensorFlow.js | Running and training models in JavaScript, in the browser or Node.js |
| TFX | Production pipeline components for validation, training, evaluation and deployment |
On-device inference was long handled by TensorFlow Lite. In September 2024 Google renamed it LiteRT, and it now accepts models from several frameworks, not only TensorFlow.
Where it came from
TensorFlow came out of Google Brain, which since 2011 had used an internal system called DistBelief for large neural networks. Google rebuilt that system's ideas into a more general and flexible library, and released TensorFlow as open source under the Apache 2.0 licence on 9 November 2015.
Key milestones:
- 2016: Google announced the Tensor Processing Unit, a chip designed for neural network workloads, closely tied to TensorFlow.
- February 2017: TensorFlow 1.0 was released. In the 1.x era, users first built a static graph and then ran it inside a session.
- 2017: TensorFlow Lite was announced for mobile and embedded devices.
- 2018: TensorFlow.js arrived for machine learning in JavaScript.
- September 2019: TensorFlow 2.0 made eager execution the default, adopted Keras as the central high-level API and removed many older, overlapping interfaces.
- 2.16 (2024): Keras 3, the multi-backend rewrite, became the default Keras for TensorFlow.
- September 2024: TensorFlow Lite was renamed LiteRT.
- 2.20 (August 2025): the
tf.litemodule was deprecated in favour of the separate LiteRT project.
Version 2.21 followed in March 2026. Releases continue, though much new research work has moved to PyTorch and JAX.
How it works
Tensors and eager execution
In TensorFlow 2, operations run immediately, as in NumPy. You can create tensors, add them and print results. Trainable values live in tf.Variable objects.
Gradients
To compute gradients, you run the forward pass inside a tf.GradientTape context. The tape records operations, and tape.gradient(loss, variables) replays them backwards using the chain rule. This is backpropagation. Keras's fit method does this for you.
Graphs with tf.function
Eager code is easy to debug but has Python overhead. Decorating a function with @tf.function traces it once into a graph. TensorFlow then optimises the graph, removes unused work and can run it without Python. Setting jit_compile=True asks XLA to compile the graph further, fusing many small operations into fewer kernels.
Input pipelines
tf.data builds pipelines from files or arrays, with steps such as map, shuffle, batch and prefetch. These run in parallel with training so the accelerator is not left waiting for data.
Distribution
tf.distribute.MirroredStrategy copies a model to several GPUs on one machine and averages gradients. Other strategies cover multiple machines and TPUs. Code inside the strategy's scope creates variables in the right places.
Saving and deploying
model.export() or tf.saved_model.save() writes a SavedModel: the graph, the weights and named signatures for inputs and outputs. TensorFlow Serving loads this directory and serves it. Converters produce LiteRT models for phones and TensorFlow.js models for the web.
Key concepts and terms
| Term | Meaning |
|---|---|
| Tensor | A typed multi-dimensional array |
| Variable | A tensor whose value can change, used for weights |
| Eager execution | Operations run immediately as Python executes |
tf.function |
Decorator that traces Python into an optimised graph |
| GradientTape | Records operations so gradients can be computed |
| XLA | Accelerated Linear Algebra, a compiler for tensor programs |
tf.data |
API for efficient input pipelines |
| Distribution strategy | A way to spread training across devices |
| SavedModel | Portable format holding graph, weights and signatures |
| Signature | A named entry point with defined inputs and outputs |
| LiteRT | Google's on-device runtime, formerly TensorFlow Lite |
| TFX | TensorFlow Extended, components for production ML pipelines |
A worked example
This scenario is illustrative. An online shop wants a model that predicts which product a visitor will click next, both on its website and inside its mobile app when the phone is offline.
- Clickstream logs are stored as TFRecord files. A
tf.datapipeline reads them, parses each record, shuffles with a buffer of 10,000 and batches 512 examples, withprefetchto overlap loading and training. - The team builds a Keras model with an embedding for product IDs and a few dense layers, and trains it with
fitfor five epochs on four GPUs usingMirroredStrategy. - The training step is wrapped in a graph automatically by Keras; they turn on XLA with
jit_compile=Trueand compare step times before keeping it. - They export a SavedModel with a signature that takes the last ten product IDs and returns scores.
- TensorFlow Serving loads the model behind the website's recommendation API.
- For the app, they convert a smaller version of the model for LiteRT, quantise it to reduce size and test that its top-ten suggestions match the server version on a sample of sessions.
The value here is a single training codebase feeding two very different deployment targets.
Strengths and limitations
Strengths:
- Mature, well-documented paths from training to serving, mobile and browser.
- Strong support for TPUs and XLA compilation.
tf.datahandles large, streaming datasets efficiently.- SavedModel gives a stable, language-neutral model format.
- Long production history and many existing systems.
Limitations:
- Most new research models are published in PyTorch first.
- The move from 1.x to 2.x changed APIs significantly, so older tutorials can mislead.
tf.functiontracing has subtle rules about Python side effects and retracing.- Parts of the ecosystem, such as on-device runtime and Keras, now live in separate projects, which adds version planning.
How it compares with alternatives
| Framework | Execution style | Strongest area | Note |
|---|---|---|---|
| TensorFlow | Eager plus traced graphs | Production pipelines, serving, on-device | Broad deployment family |
| PyTorch | Eager plus torch.compile |
Research and most new models | Largest model ecosystem |
| JAX | Functional transformations, XLA | Large-scale research on TPUs and GPUs | Pure-function style |
| Keras | High-level API on several back ends | Fast model building | Can run on TensorFlow, JAX or PyTorch |
| ONNX Runtime | Inference runtime | Cross-framework deployment | Not a training framework |
Practical guidance and best practices
- Write model code with Keras unless you need low-level control.
- Decide the deployment target, whether server, phone or browser, before choosing architecture, and test conversion early.
- Build input pipelines with
tf.dataand always addprefetch. - Keep Python side effects out of
tf.functioncode, and watch for repeated retracing caused by changing input shapes. - Try XLA with
jit_compile=Trueand measure; keep it only where it helps. - Export SavedModels with explicit signatures so serving code knows exact inputs.
- Pin TensorFlow, Keras and CUDA versions together; mismatches are a frequent cause of failures.
- For new on-device work, plan around LiteRT rather than the deprecated
tf.litemodule.
Common mistakes
- Following TensorFlow 1.x tutorials with sessions and placeholders in a 2.x project.
- Putting Python
printor list appends insidetf.functionand expecting them to run every step. - Feeding data from slow Python generators, which leaves GPUs idle.
- Mixing
tf.kerasfrom Keras 2 with Keras 3 code in the same program. - Skipping accuracy checks after converting a model for mobile, especially after quantisation.
Frequently asked questions
Is TensorFlow still used?
Yes. Many production systems, especially those built between 2016 and 2021, run on TensorFlow, and its serving and on-device tools are widely deployed. New research work, however, is more often written in PyTorch or JAX.
What is the relationship between TensorFlow and Keras?
Keras is the recommended high-level API for building models in TensorFlow. Since TensorFlow 2.16, the default is Keras 3, which is a separate multi-backend project that can also run on JAX and PyTorch.
What happened to TensorFlow Lite?
It was renamed LiteRT in September 2024. LiteRT can run models that started in TensorFlow, PyTorch, JAX or Keras. In TensorFlow 2.20 the tf.lite module was deprecated, and on-device work moved to the LiteRT project.
Do I need TPUs to use TensorFlow?
No. TensorFlow runs on CPUs and GPUs. TPUs are an option on Google Cloud for large workloads, and TensorFlow has long supported them well.
What is the difference between eager mode and tf.function?
Eager mode runs each operation straight away, which is easy to debug. tf.function traces your code into a graph that TensorFlow can optimise and run without Python, which is usually faster. Develop eagerly, then use graphs for speed.
How do I serve a TensorFlow model?
Export it as a SavedModel and load it with TensorFlow Serving, which offers gRPC and REST endpoints. Managed platforms such as Vertex AI and SageMaker can also host SavedModels.
Glossary
- DistBelief: Google's earlier internal system for training neural networks, the predecessor of TensorFlow.
- Graph: a representation of a computation as connected operations.
- Kernel fusion: combining several operations into one to reduce memory traffic.
- Quantisation: storing weights in fewer bits to shrink and speed up a model.
- Retracing: TensorFlow building a new graph because inputs changed shape or type.
- TFRecord: a binary file format for storing training examples.
- TPU: Google's accelerator chip designed for neural network workloads.
- TensorFlow.js: the JavaScript version of TensorFlow for browsers and Node.js.
Summary
TensorFlow is Google's open-source machine learning platform, released in 2015 and reshaped by version 2.0 in 2019 around eager execution and Keras. Its main strength is the path from training to deployment: tf.data pipelines, SavedModel, TensorFlow Serving, TensorFlow.js and, for devices, LiteRT. Research energy has largely moved to PyTorch and JAX, but TensorFlow remains a sound, well-supported choice where existing systems, TPU use or broad deployment targets matter.
Related
It belongs to Frameworks in my stack, under Deep learning. Others in the same group: