-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Adjust demo scripts to be Keras 3 compatible #6761
Conversation
model.add(tf.keras.layers.Dropout(hparams[HP_DROPOUT], seed=rng.random())) | ||
model.add( | ||
tf.keras.layers.Dropout( | ||
hparams[HP_DROPOUT], seed=rng.randrange(1 << 32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresses this error:
File "/usr/local/google/home/bdubois/virtualenv/20240215-tensorboard-git-without-keras/lib/python3.11/site-packages/keras/src/layers/regularization/dropout.py", line 53, in __init__
self.seed_generator = backend.random.SeedGenerator(seed)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/google/home/bdubois/virtualenv/20240215-tensorboard-git-without-keras/lib/python3.11/site-packages/keras/src/random/seed_generator.py", line 61, in __init__
raise ValueError(
ValueError: Argument `seed` must be an integer. Received: seed=0.3616904771377427
@@ -125,11 +125,9 @@ def g(i): | |||
for step in range(3): | |||
# Suppress the profiler deprecation warnings from tf.summary.trace_*. | |||
with _silence_deprecation_warnings(): | |||
tf.summary.trace_on(profiler=True) | |||
tf.summary.trace_on(profiler=True, profiler_outdir=logdir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresses this error:
WARNING:tensorflow:No `profiler_outdir` passed to trace_on(). Profiler won't be enabled.
0
WARNING:tensorflow:Ignoring `profiler_outdir` passed to trace_export(). Please pass it to trace_on() instead.
<snip>
File "/usr/local/google/home/bdubois/virtualenv/20240215-tensorboard-git-without-keras/lib/python3.11/site-packages/tensorflow/python/profiler/profiler_v2.py", line 144, in stop
raise errors.UnavailableError(
tensorflow.python.framework.errors_impl.UnavailableError: Cannot export profiling results. No profiler is running.
@@ -90,7 +90,7 @@ def keras(): | |||
model = tf.keras.models.Sequential(layers) | |||
model.compile( | |||
loss=tf.keras.losses.mean_squared_error, | |||
optimizer=tf.keras.optimizers.SGD(lr=0.2), | |||
optimizer=tf.keras.optimizers.SGD(learning_rate=0.2), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addresses this error:
File "/usr/local/google/home/bdubois/virtualenv/20240215-tensorboard-git-without-keras/lib/python3.11/site-packages/keras/src/optimizers/base_optimizer.py", line 38, in __init__
raise ValueError(f"Argument(s) not recognized: {kwargs}")
ValueError: Argument(s) not recognized: {'lr': 0.2}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing!
## Motivation for features / changes This test behaves differently internally and externally. The changes made in #6761 succeed in getting the test to pass externally, but it will then fail when imported Googlers see (cl/608667862).
This adjusts *_demo.py files to work with Keras 3.
The hparams_demo is fully backward compatible with Keras 2 and forward compatible with Keras 3.
Unfortunately the graphs_demo is not backward compatible with Keras 2. Users attempting to run it with Keras 2 will get the following error:
Amazingly, though, the graph that the demo generates with Keras 3 can be successfully loaded in the Graph dashboard. This makes me optimistic to get the Graph plugin fully Keras 3 compatible after addressing the user-reported error in #6686.
Old Keras 2 Graph:
New Keras 3 Graph: