As described in Compatibility for Graphs and Checkpoints, TensorFlow marks each kind of data with version information in order to maintain backward compatibility. This document provides additional details about the versioning mechanism, and how to use it to safely change data formats.
The two core artifacts exported from and imported into TensorFlow are checkpoints (serialized variable states) and GraphDefs (serialized computation graphs). Any approach to versioning these artifacts must take into account the following requirements:
GraphDefs created with older versions of TensorFlow.GraphDef is upgraded to a newer version of TensorFlow before the consumer.For GraphDefs, backward compatibility is enforced within a major version. This means functionality can only be removed between major versions. Forward compatibility is enforced within Patch releases (1.x.1 -> 1.x.2, for example).
In order to achieve backward and forward compatibility as well as know when to enforce changes in formats, the serialized representations of graphs and variable state need to have metadata that describes when they were produced. The sections below detail the TensorFlow implementation and guidelines for evolving GraphDef versions.
There are data versions for GraphDefs and checkpoints. Both data formats evolve at different rates, and also at different speeds than the version of 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.
This section discusses version information for data, binaries that produce data (producers), and binaries that consume data (consumers):
producer) and a minimum consumer version that they are compatible with (min_consumer).consumer) and a minimum producer version that they are compatible with (min_producer).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
consumer >= data's min_consumer
producer >= consumer's min_producer
consumer not in data's bad_consumers
Since both producers and consumers come from the same TensorFlow code base, core/public/version.h contains a main binary 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,
GraphDef versions, we have TF_GRAPH_DEF_VERSION, TF_GRAPH_DEF_VERSION_MIN_CONSUMER, and TF_GRAPH_DEF_VERSION_MIN_PRODUCER.TF_CHECKPOINT_VERSION, TF_CHECKPOINT_VERSION_MIN_CONSUMER, and TF_CHECKPOINT_VERSION_MIN_PRODUCER.This section presents examples of using this versioning mechanism to make changes to the GraphDef format.
Adding a new Op:
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.Adding a new Op and switching existing Python wrappers to use it:
min_consumer, since models which do not use this Op should not break.Removing an Op or restricting the functionality of an Op:
GraphDefs with the banned functionality. This can be done with REGISTER_OP(...).Deprecated(deprecated_at_version, message).min_producer to the GraphDef version from (2) and remove the functionality entirely.Changing the functionality of an Op:
SomethingV2 or similar and go through the process of adding it and switching existing Python wrappers to use it (may take 3 weeks if forward compatibility is desired).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.SomethingV2.Banning a single consumer version that cannot run safely:
bad_consumers for all new GraphDefs. If possible, add to bad_consumers only for GraphDefs which contain a certain Op or similar.
© 2017 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/programmers_guide/data_versions