TensorFlow Version Compatibility

This document is for users who need backwards compatibility across different versions of TensorFlow (either for code or data), and for developers who want to modify TensorFlow while preserving compatibility.

Semantic Versioning 2.0

TensorFlow follows Semantic Versioning 2.0 (semver) for its public API. Each release version of TensorFlow has the form MAJOR.MINOR.PATCH. For example, TensorFlow version 1.2.3 has MAJOR version 1, MINOR version 2, and PATCH version 3. Changes to each number have the following meaning:

For example, release 1.0.0 introduced backwards incompatible changes from release 0.12.1. However, release 1.1.1 was backwards compatible with release 1.0.0.

What is covered

Only the public APIs of TensorFlow are backwards compatible across minor and patch versions. The public APIs consist of

If a symbol is available through the tensorflow Python module or its submodules, but is not documented, then it is not considered part of the public API.

What is not covered

Some API functions are explicitly marked as "experimental" and can change in backward incompatible ways between minor releases. These include:

Compatibility of graphs and checkpoints

You'll sometimes need to preserve graphs and checkpoints. Graphs describe the data flow of ops to be run during training and inference, and checkpoints contain the saved tensor values of variables in a graph.

Many TensorFlow users save graphs and trained models to disk for later evaluation or additional training, but end up running their saved graphs or models on a later release. In compliance with semver, any graph or checkpoint written out with one version of TensorFlow can be loaded and evaluated with a later version of TensorFlow with the same major release. However, we will endeavor to preserve backwards compatibility even across major releases when possible, so that the serialized files are usable over long periods of time.

Graphs are serialized via the GraphDef protocol buffer. To facilitate (rare) backwards incompatible changes to graphs, each GraphDef has a version number separate from the TensorFlow version. For example, GraphDef version 17 deprecated the inv op in favor of reciprocal. The semantics are:

Finally, when support for a GraphDef version is dropped, we will attempt to provide tools for automatically converting graphs to a newer supported GraphDef version.

Graph and checkpoint compatibility when extending TensorFlow

This section is relevant only when making incompatible changes to the GraphDef format, such as when adding ops, removing ops, or changing the functionality of existing ops. The previous section should suffice for most users.

Backward and partial forward compatibility

Our versioning scheme has three requirements:

Note that while the GraphDef version mechanism is separate from the TensorFlow version, backwards incompatible changes to the GraphDef format are still restricted by Semantic Versioning. This means functionality can only be removed or changed between MAJOR versions of TensorFlow (such as 1.7 to 2.0). Additionally, forward compatibility is enforced within Patch releases (1.x.1 to 1.x.2 for example).

To achieve backward and forward compatibility and to know when to enforce changes in formats, graphs and checkpoints have metadata that describes when they were produced. The sections below detail the TensorFlow implementation and guidelines for evolving GraphDef versions.

Independent data version schemes

There are different data versions for graphs and checkpoints. The two data formats evolve at different rates from each other and also at different rates from TensorFlow. Both versioning systems are defined in core/public/version.h. Whenever a new version is added, a note is added to the header detailing what changed and the date.

Data, producers, and consumers

We distinguish between the following kinds of data version information: * producers: binaries that produce data. Producers have a version (producer) and a minimum consumer version that they are compatible with (min_consumer). * consumers: binaries that consume data. Consumers have a version (consumer) and a minimum producer version that they are compatible with (min_producer).

Each piece of versioned data has a VersionDef versions field which records the producer that made the data, the min_consumer that it is compatible with, and a list of bad_consumers versions that are disallowed.

By default, when a producer makes some data, the data inherits the producer's producer and min_consumer versions. bad_consumers can be set if specific consumer versions are known to contain bugs and must be avoided. A consumer can accept a piece of data if the following are all true:

Since both producers and consumers come from the same TensorFlow code base, core/public/version.h contains a main data version which is treated as either producer or consumer depending on context and both min_consumer and min_producer (needed by producers and consumers, respectively). Specifically,

Evolving GraphDef versions

This section explains how to use this versioning mechanism to make different types of changes to the GraphDef format.

Add an Op

Add the new Op to both consumers and producers at the same time, and do not change any GraphDef versions. This type of change is automatically backward compatible, and does not impact forward compatibility plan since existing producer scripts will not suddenly use the new functionality.

Add an Op and switch existing Python wrappers to use it

  1. Implement new consumer functionality and increment the GraphDef version.
  2. If it is possible to make the wrappers use the new functionality only in cases that did not work before, the wrappers can be updated now.
  3. Change Python wrappers to use the new functionality. Do not increment min_consumer, since models that do not use this Op should not break.

Remove or restrict an Op's functionality

  1. Fix all producer scripts (not TensorFlow itself) to not use the banned Op or functionality.
  2. Increment the GraphDef version and implement new consumer functionality that bans the removed Op or functionality for GraphDefs at the new version and above. If possible, make TensorFlow stop producing GraphDefs with the banned functionality. To do so, add the REGISTER_OP(...).Deprecated(deprecated_at_version, message).
  3. Wait for a major release for backward compatibility purposes.
  4. Increase min_producer to the GraphDef version from (2) and remove the functionality entirely.

Change an Op's functionality

  1. Add a new similar Op named SomethingV2 or similar and go through the process of adding it and switching existing Python wrappers to use it, which may take three weeks if forward compatibility is desired.
  2. Remove the old Op (Can only take place with a major version change due to backward compatibility).
  3. Increase min_consumer to rule out consumers with the old Op, add back the old Op as an alias for SomethingV2, and go through the process to switch existing Python wrappers to use it.
  4. Go through the process to remove SomethingV2.

Ban a single unsafe consumer version

  1. Bump the GraphDef version and add the bad version to bad_consumers for all new GraphDefs. If possible, add to bad_consumers only for GraphDefs which contain a certain Op or similar.
  2. If existing consumers have the bad version, push them out as soon as possible.