Skip to content

Commit

Permalink
Fix flaky JaxLayer test. (#20756)
Browse files Browse the repository at this point in the history
The `DTypePolicy` test produces lower precision results.
  • Loading branch information
hertschuh authored Jan 13, 2025
1 parent e010829 commit 7d4b7bb
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions keras/src/utils/jax_layer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,13 @@ def verify_identical_model(model):
model2.export(path, format="tf_saved_model")
model4 = tf.saved_model.load(path)
output4 = model4.serve(x_test)
# The output difference is greater when using the GPU or bfloat16
lower_precision = testing.jax_uses_gpu() or "dtype" in layer_init_kwargs
self.assertAllClose(
output1,
output4,
# The output difference might be significant when using the GPU
atol=1e-2 if testing.jax_uses_gpu() else 1e-6,
atol=1e-2 if lower_precision else 1e-6,
rtol=1e-3 if lower_precision else 1e-6,
)

# test subclass model building without a build method
Expand Down

0 comments on commit 7d4b7bb

Please sign in to comment.