Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update/optimization_and_modeling->[update] optimzation.py and modeling.py for tensorflow 2x. #1414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

p0lyMth
Copy link

@p0lyMth p0lyMth commented Jul 20, 2024

MOTIVATION

PR to resolve AttributeError: module 'tensorflow._api.v2.train' has no attribute 'Optimizer'

optimization.py:

  • change tf.train.Optimizer -> tf.compat.v1.train.Optimizer due to tensorflow 2x. src: [ https://www.tensorflow.org/api_docs/python/tf/compat/v1 ]

modeling.py: (due to changes made in optimization.py)

  • add @tf.function decorator above get_shape_list(...) due to eager execution enabled by default in tensorflow 2x. src: [ https://www.tensorflow.org/guide/function ]

  • change tf.get_variable -> tf.compat.v1.get_variable.

  • change tf.variable_score -> tf.compat.v1.variable_score.

  • change tf.truncated_normal_initializer -> tf.compat.v1.truncated_normal_initializer.

  • change tf.assert_less_equal -> tf.compat.v1.assert_less_equal.

  • change tf.get_variable_scope -> tf.compat.v1.get_variable_scope. src: [ https://www.tensorflow.org/api_docs/python/tf/compat/v1 ]

  • change tf.layers.dense -> tf.keras.layers.Dense due to Keras 3.

  • change tf.contrib.layers.layer_norm -> tf.keras.layers.LayerNormalization. src: [ https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense ] src: [ https://stackoverflow.com/a/62357941/11492382 ]


CONFIGURATION

  • software : Windows 11 Home [21H2]. WSL version 2.2.4.0; openSUSE tumbleweed 20240629
  • hardware : 64-bit operating system, x64-based processor
  • conda_env:
    • cudnn 8.9.7.29 conda-forge
    • python 3.12.2 conda-forge
    • tensorflow 2.16.1 conda-forge

Reported-by : Майкл Шодеке
Signed-off-by: Майкл Шодеке

MOTIVATION
PR to resolve `AttributeError: module 'tensorflow._api.v2.train' has no attribute 'Optimizer'`

`optimization.py`:
  - change `tf.train.Optimizer` -> `tf.compat.v1.train.Optimizer` due to tensorflow 2x.
  src: [ https://www.tensorflow.org/api_docs/python/tf/compat/v1 ]

`modeling.py`: (due to changes made in `optimization.py`)
  - add `@tf.function` decorator above `get_shape_list(...)` due to eager execution enabled by default in tensorflow 2x.
  src: [ https://www.tensorflow.org/guide/function ]

  - change `tf.get_variable` -> `tf.compat.v1.get_variable`.
  - change `tf.variable_score` -> `tf.compat.v1.variable_score`.
  - change `tf.truncated_normal_initializer` -> `tf.compat.v1.truncated_normal_initializer`.
  - change `tf.assert_less_equal` -> `tf.compat.v1.assert_less_equal`.
  - change `tf.get_variable_scope` -> `tf.compat.v1.get_variable_scope`.
  src: [ https://www.tensorflow.org/api_docs/python/tf/compat/v1 ]

  - change `tf.layers.dense` -> `tf.keras.layers.Dense` due to Keras 3.
  - change `tf.contrib.layers.layer_norm` -> `tf.keras.layers.LayerNormalization`.
  src: [ https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense ]
  src: [ https://stackoverflow.com/a/62357941/11492382 ]

CONFIGURATION
software  : Windows 11 Home [21H2]. WSL version 2.2.4.0; openSUSE tumbleweed 20240629
hardware  : 64-bit operating system, x64-based processor
conda_env :
  cudnn      8.9.7.29  conda-forge
  python     3.12.2    conda-forge
  tensorflow 2.16.1    conda-forge

Reported-by  : Майкл Шодеке
Signed-off-by: Майкл Шодеке
@p0lyMth p0lyMth force-pushed the update/optimization_and_modeling branch from 65a9d49 to 938a485 Compare July 20, 2024 05:52
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