# Transitioning to TensorFlow 1.0

The APIs in TensorFlow 1.0 have changed in ways that are not all backwards compatible. That is, TensorFlow programs that worked on TensorFlow 0.n won't necessarily work on TensorFlow 1.0. We have made this API changes to ensure an internally-consistent API, and do not plan to make backwards-breaking changes throughout the 1.N lifecycle.

This guide walks you through the major changes in the API and how to automatically upgrade your programs for TensorFlow 1.0. This guide not only steps you through the changes but also explains why we've made them.

If you would like to automatically port your code to 1.0, you can try our tf_upgrade.py script. While this script handles many cases, manual changes are sometimes necessary. Get this script from our GitHub tree.

To convert a single 0.n TensorFlow source file to 1.0, enter a command of the following format:

$python tf_upgrade.py --infile InputFile --outfile OutputFile  For example, the following command converts a 0.n TensorFlow program named test.py to a 1.0 TensorFlow program named test_1.0.py: $ python tf_upgrade.py --infile test.py --outfile test_1.0.py


The tf_upgrade.py script also generates a file named report.txt, which details all the changes it performed and makes additional suggestions about changes you might need to make manually.

To upgrade a whole directory of 0.n TensorFlow programs to 1.0, enter a command having the following format:

$python tf_upgrade.py --intree InputDir --outtree OutputDir  For example, the following command converts all the 0.n TensorFlow programs in the /home/user/cool directory, creating their 1.0 equivalents in the /home/user/cool_1.0 directory: $ python tf_upgrade.py --intree /home/user/cool --outtree /home/user/cool_1.0


### Limitations

There are a few things to watch out for. Specifically:

• You must manually fix any instances of tf.reverse(). The tf_upgrade.py script will warn you about tf.reverse() in stdout and in the report.txt file.
• On reordered arguments, tf_upgrade.py tries to minimally reformat your code, so it cannot automatically change the actual argument order. Instead, tf_upgrade.py makes your function invocations order-independent by introducing keyword arguments.
• Constructions like tf.get_variable_scope().reuse_variables() will likely not work. We recommend deleting those lines and replacing them with lines such as the following:

with tf.variable_scope(tf.get_variable_scope(), reuse=True):
...

• Analogously to tf.pack and tf.unpack, we're renamed TensorArray.pack and TensorArray.unpack to TensorArray.stack and TensorArray.unstack. However, TensorArray.pack and TensorArray.unpack cannot be detected lexically since they are indirectly related to the tf namespace e.g. foo = tf.TensorArray(); foo.unpack()

Instead of running tf_upgrade.py, you may manually upgrade your code. The remainder of this document provides a comprehensive list of all backward incompatible changes made in TensorFlow 1.0.

### Variables

Variable functions have been made more consistent and less confusing.

### Summary functions

Summary functions have been consolidated under the tf.summary namespace.

### Numeric differences

Integer division and tf.floordiv now uses flooring semantics. This is to make the results of np.divide and np.mod consistent with tf.divide and tf.mod, respectively. In addition we have changed the rounding algorithm used by tf.round to match NumPy.

The old and new behavior of division can be summarized with this table:

Expr TF 0.11 (py2) TF 0.11 (py3) TF 1.0 (py2) TF 1.0 (py3)
tf.div(3,4) 0 0 0 0
tf.div(-3,4) 0 0 -1 -1
tf.mod(-3,4) -3 -3 1 1
-3/4 0 -0.75 -1 -0.75
-3/4tf.divide(-3,4) N/A N/A -0.75 -1

The old and new behavior of rounding can be summarized with this table:

Input Python NumPy C++ round() TensorFlow 0.11(floor(x+.5)) TensorFlow 1.0
-3.5 -4 -4 -4 -3 -4
-2.5 -2 -2 -3 -2 -2
-1.5 -2 -2 -2 -1 -2
-0.5 0 0 -1 0 0
0.5 0 0 1 1 0
1.5 2 2 2 2 2
2.5 2 2 3 3 2
3.5 4 4 4 4 4

### NumPy matching names

Many functions have been renamed to match NumPy. This was done to make the transition between NumPy and TensorFlow as easy as possible. There are still numerous cases where functions do not match, so this is far from a hard and fast rule, but we have removed several commonly noticed inconsistencies.

### NumPy matching arguments

Arguments for certain TensorFlow 1.0 methods now match arguments in certain NumPy methods. To achieve this, TensorFlow 1.0 has changed keyword arguments and reordered some arguments. Notably, TensorFlow 1.0 now uses axis rather than dimension. TensorFlow 1.0 aims to keep the tensor argument first on operations that modify Tensors. (see the tf.concat change).

• tf.argmax
• keyword argument dimension should be renamed to axis
• tf.argmin
• keyword argument dimension should be renamed to axis
• tf.concat
• keyword argument concat_dim should be renamed to axis
• arguments have been reordered to tf.concat(values, axis, name='concat').
• tf.count_nonzero
• keyword argument reduction_indices should be renamed to axis
• tf.expand_dims
• keyword argument dim should be renamed to axis
• tf.reduce_all
• keyword argument reduction_indices should be renamed to axis
• tf.reduce_any
• keyword argument reduction_indices should be renamed to axis
• tf.reduce_join
• keyword argument reduction_indices should be renamed to axis
• tf.reduce_logsumexp
• keyword argument reduction_indices should be renamed to axis
• tf.reduce_max
• keyword argument reduction_indices should be renamed to axis
• tf.reduce_mean
• keyword argument reduction_indices should be renamed to axis
• tf.reduce_min
• keyword argument reduction_indices should be renamed to axis
• tf.reduce_prod
• keyword argument reduction_indices should be renamed to axis
• tf.reduce_sum
• keyword argument reduction_indices should be renamed to axis
• tf.reverse
• tf.reverse used to take a 1D bool tensor to control which dimensions were reversed. Now we use a Tensor of axis indices.
• For example tf.reverse(a, [True, False, True]) now must be tf.reverse(a, [0, 2])
• tf.reverse_sequence
• keyword argument batch_dim should be renamed to batch_axis
• keyword argument seq_dim should be renamed to seq_axis
• tf.sparse_concat
• keyword argument concat_dim should be renamed to axis
• tf.sparse_reduce_sum
• keyword argument reduction_axes should be renamed to axis
• tf.sparse_reduce_sum_sparse
• keyword argument reduction_axes should be renamed to axis
• tf.sparse_split
• keyword argument split_dim should be renamed to axis
• arguments have been reordered to tf.sparse_split(keyword_required=KeywordRequired(), sp_input=None, num_split=None, axis=None, name=None, split_dim=None).
• tf.split
• keyword argument split_dim should be renamed to axis
• keyword argument num_split should be renamed to num_or_size_splits
• arguments have been reordered to tf.split(value, num_or_size_splits, axis=0, num=None, name='split').
• tf.squeeze
• keyword argument squeeze_dims should be renamed to axis
• tf.svd
• arguments have been reordered to tf.svd(tensor, full_matrices=False, compute_uv=True, name=None).

### Simplified math variants

Batched versions of math operations have been removed. Now the functionality is contained in the non-batched versions. Similarly,tf.complex_abs has had its functionality moved to tf.abs

### Misc Changes

Several other changes have been made, including the following: