Skip to content

Port TF1 graph-mode code to tensorflow.compat.v1 for TF2 compatibility - #12

Merged
Arun Iyer (aruniyer) merged 1 commit into
mainfrom
aruniyer/modernize
Oct 7, 2026
Merged

Arun Iyer (aruniyer) merged 1 commit into
mainfrom
aruniyer/modernize

Conversation

@aruniyer

Copy link
Copy Markdown
Contributor

The code used TF1-only graph-mode APIs (tf.get_variable, tf.placeholder, tf.Session, tf.contrib...) which don't exist under plain import tensorflow as tf on TF2.

  • layers.py, model.py, train.py, utils.py: switched to import 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-gpu was removed from PyPI after TF 2.10; bumped to tensorflow==2.15.1 plus compatible numpy/pandas/scipy pins.

Verified: README's mr dataset example reproduces 77.5% test accuracy on a GPU instance, matching the paper.

…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.
@aruniyer
Arun Iyer (aruniyer) merged commit fcc0cac into main Oct 7, 2026
5 checks passed
@aruniyer
Arun Iyer (aruniyer) deleted the aruniyer/modernize branch October 7, 2026 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant