STT-tensorflow/tensorflow/tools/compatibility
A. Unique TensorFlower 985ad0276a PY2 removal cleanup
PiperOrigin-RevId: 352907145
Change-Id: I82de30d92dc9c2b53215d6d5732c67afe339c23d
2021-01-20 17:11:44 -08:00
..
testdata Remove test to un-red nightly builds as suggested in b/151378056 2020-03-19 09:26:43 -07:00
update PY2 removal cleanup 2021-01-20 17:11:44 -08:00
all_renames_v2_test.py
all_renames_v2.py minor spelling tweaks 2020-01-16 14:36:52 +09:00
ast_edits_test.py Move away from deprecated asserts 2020-06-30 16:10:22 -07:00
ast_edits.py Added an --upgrade_compat_v1_import flag to the upgrade script that allows it to upgrade import tensorflow.compat.v1 as tfimports to import tensorflow as tf imports. Note that this flag does not upgrade tf.compat.v1 when imported under other aliases, such as import tensorflow.compat.v1 as tfv1 2020-04-01 21:31:15 -07:00
BUILD PY2 removal cleanup 2021-01-20 17:11:44 -08:00
ipynb.py Small adjustments on import spacing. 2019-12-18 20:32:12 -08:00
module_deprecations_v2.py
README.md
renames_v2.py Deprecate enable_mixed_precision_graph_rewrite function. 2020-10-20 11:38:55 -07:00
reorders_v2.py Updating renames_v2.py and reorders_v2.py. 2020-01-30 16:02:36 -08:00
tf_upgrade_test.py Small adjustments on import spacing. 2019-12-18 20:32:12 -08:00
tf_upgrade_v2_main.py Merge pull request #44434 from Molkree:typos_in_misc_files 2020-10-29 23:38:22 -07:00
tf_upgrade_v2_safety_test.py Minor change in update script 2020-02-25 15:46:42 -08:00
tf_upgrade_v2_safety.py Minor change in update script 2020-02-25 15:46:42 -08:00
tf_upgrade_v2_test.py Change tf_upgrade_v2 to be compatible with tf1 and tf2 for tf.nn.dropout 2020-11-15 12:17:26 +09:00
tf_upgrade_v2.py Change tf_upgrade_v2 to be compatible with tf1 and tf2 for tf.nn.dropout 2020-11-15 12:17:26 +09:00
tf_upgrade.py

TensorFlow Python API Upgrade Utility

This tool allows you to upgrade your existing TensorFlow Python scripts, specifically:

  • tf_upgrade_v2.py: Upgrade code from TensorFlow 1.x to TensorFlow 2.0 preview.
  • tf_upgrade.py: Upgrade code to TensorFlow 1.0 from TensorFlow 0.11.

Running the script from pip package

First, install TensorFlow pip package*. See https://www.tensorflow.org/install/pip.

Upgrade script can be run on a single Python file:

tf_upgrade_v2 --infile foo.py --outfile foo-upgraded.py

It will print a list of errors it finds that it can't fix. You can also run it on a directory tree:

# upgrade the .py files and copy all the other files to the outtree
tf_upgrade_v2 --intree coolcode --outtree coolcode-upgraded

# just upgrade the .py files
tf_upgrade_v2 --intree coolcode --outtree coolcode-upgraded --copyotherfiles False

*Note: tf_upgrade_v2 is installed automatically as a script by the pip install after TensorFlow 1.12.

Report

The script will also dump out a report e.g. which will detail changes e.g.:

'tensorflow/tools/compatibility/testdata/test_file_v1_12.py' Line 65
--------------------------------------------------------------------------------

Added keyword 'input' to reordered function 'tf.argmax'
Renamed keyword argument from 'dimension' to 'axis'

    Old:         tf.argmax([[1, 3, 2]], dimension=0)
                                        ~~~~~~~~~~
    New:         tf.argmax(input=[[1, 3, 2]], axis=0)

Caveats

  • Don't update parts of your code manually before running this script. In particular, functions that have had reordered arguments like tf.argmax or tf.batch_to_space will cause the script to incorrectly add keyword arguments that mismap arguments.

  • This script wouldn't actually reorder arguments. Instead, the script will add keyword arguments to functions that had their arguments reordered.

  • The script assumes that tensorflow is imported using import tensorflow as tf.

  • Note for upgrading to 2.0: Check out tf2up.ml for a convenient tool to upgrade Jupyter notebooks and Python files in a GitHub repository.

  • Note for upgrading to 1.0: There are some syntaxes that are not handleable with this script as this script was designed to use only standard python packages. If the script fails with "A necessary keyword argument failed to be inserted." or "Failed to find keyword lexicographically. Fix manually.", you can try @machrisaa's fork of this script. @machrisaa has used the RedBaron Python refactoring engine which is able to localize syntactic elements more reliably than the built-in ast module this script is based upon. Note that the alternative script is not available for TensorFlow 2.0 upgrade.