-
Notifications
You must be signed in to change notification settings - Fork 55
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
Keras 3.3.3 upgrade #165
Keras 3.3.3 upgrade #165
Conversation
Rolled over changes for Keras 3.3 for all tf.Model classes
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.
Very nice changes overall, thank you! See comments for some minor changes before merging.
bayesflow/coupling_networks.py
Outdated
@@ -436,7 +439,7 @@ def _semantic_spline_parameters(self, parameters): | |||
""" | |||
|
|||
shape = tf.shape(parameters) | |||
rank = len(shape) | |||
rank = parameters.shape.rank |
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.
tensorflow-specific, len(shape)
or parameters.ndim
should be fine. Safest would probably be keras.ops.ndim
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.
Changed parameters.shape.rank
to use keras.ops.ndim
in coupling_networks.py (see 47fbbbd)
# LearningRateSchedule instances need number of iterations | ||
current_lr = optimizer.lr(optimizer.iterations).numpy() | ||
elif hasattr(optimizer.lr, "numpy"): | ||
current_lr = optimizer.learning_rate(optimizer.iterations).numpy() |
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.
not sure if this works under jax/numpy backend - can you test this? As an alternative, we could use keras.ops.convert_to_numpy()
. We can then drop the hasattr
check
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.
Changed learning_rate().numpy()
to keras.ops.convert_to_numpy()
in helper_functions.py (see 47fbbbd)
bayesflow/inference_networks.py
Outdated
target_shape = tf.shape(targets) | ||
condition_shape = tf.shape(condition) | ||
target_shape = keras.backend.shape(targets) | ||
condition_shape = keras.backend.shape(condition) |
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.
as discussed, please use keras.ops
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.
Changed requested keras.backend
instances to keras.ops
in inference_networks.py
. (see 47fbbbd)
Will change remaining keras.backend
to keras.ops
calls with next update
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.
Remaining keras.backend
calls switched to respective keras.ops
functions (see b9d5f16)
Changed parameters.shape.rank to use keras.ops.ndim in coupling_networks.py, Changed learning_rate.numpy() to keras.ops.convert_to_numpy() in helper_functions.py, Changed requested keras.backend instances to keras.ops in inference_networks.py.
Changed all calls of keras.backend to the respective keras.ops function
We cannot merge this anymore due to the many changes on the branch, but we'll use this as a reference nonetheless. |
tf.model
,tf.layer
, andtf.optimizer
@tf.function
decorator tocoupling_networks._calculate_spline()
to allow execution in non-eager environmentstf.Tensor
in docstring toTensor
w.r.t. the experimental Tensor typeThe included changes have worked successfully in all of the example / tutorial notebooks, however I'm sure there are a few introduced bugs laying around when TensorFlow is not the chosen backend.
Current environment dependencies: