Repository navigation
Port TF1 graph-mode code to tensorflow.compat.v1 for TF2 compatibility - #12
Merged
Merged
Conversation
…ments
- layers.py, model.py, train.py, utils.py: the original code used
TF1-only graph-mode APIs (tf.get_variable, tf.variable_scope,
tf.placeholder, tf.Session, tf.contrib...) which no longer exist
under plain 'import tensorflow as tf' on TF2. Switched all four
files to 'import tensorflow.compat.v1 as tf' + tf.disable_v2_behavior()
so the unmodified graph-mode logic keeps working.
- tf.contrib.layers.xavier_initializer() -> tf.glorot_uniform_initializer()
(tf.contrib was removed entirely in TF2; this is the same Xavier/Glorot
uniform initializer under its compat.v1 name).
- tf.is_nan -> tf.math.is_nan (moved namespace in TF2).
- requirements.txt: tensorflow-gpu was removed from PyPI after TF 2.10
(GPU support is now bundled into the regular 'tensorflow' package on
Linux); bumped to tensorflow==2.15.1 and refreshed numpy/pandas/scipy
pins to versions compatible with it. Removed a duplicate scipy line.
- Added .gitignore entry for __pycache__/.
Verified end-to-end on a GPU instance: README's 'mr' dataset example
reproduces 77.5% test accuracy, matching the paper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The code used TF1-only graph-mode APIs (
tf.get_variable,tf.placeholder,tf.Session,tf.contrib...) which don't exist under plainimport tensorflow as tfon TF2.layers.py,model.py,train.py,utils.py: switched toimport tensorflow.compat.v1 as tf+tf.disable_v2_behavior().tf.contrib.layers.xavier_initializer()->tf.glorot_uniform_initializer()(contrib was removed in TF2; same initializer, compat.v1 name).tf.is_nan->tf.math.is_nan(moved namespace).requirements.txt:tensorflow-gpuwas removed from PyPI after TF 2.10; bumped totensorflow==2.15.1plus compatible numpy/pandas/scipy pins.Verified: README's
mrdataset example reproduces 77.5% test accuracy on a GPU instance, matching the paper.