From 6bf16bf4046c9c08bb4da01d24ca0e8b9f01cdd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20B=C4=B1=C3=A7akc=C4=B1?= <46622558+Frightera@users.noreply.github.com> Date: Wed, 2 Oct 2024 01:11:27 +0300 Subject: [PATCH 1/2] Update reproducibility_recipes.py --- examples/keras_recipes/reproducibility_recipes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/keras_recipes/reproducibility_recipes.py b/examples/keras_recipes/reproducibility_recipes.py index 00db09ff7d..5787bd9f5b 100644 --- a/examples/keras_recipes/reproducibility_recipes.py +++ b/examples/keras_recipes/reproducibility_recipes.py @@ -151,8 +151,10 @@ def train_model(train_data: tf.data.Dataset, test_data: tf.data.Dataset) -> dict ) model.compile( - optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"] + optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"], jit_compile = False ) + # jit_compile's default value is "auto" which will cause some problems in some + # ops, therefore it's set to False. # model.fit has a `shuffle` parameter which has a default value of `True`. # If you are using array-like objects, this will shuffle the data before From 0130fa2d64ef56df69cb2ada9c8c06c9478d21eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20B=C4=B1=C3=A7akc=C4=B1?= <46622558+Frightera@users.noreply.github.com> Date: Thu, 17 Oct 2024 01:04:31 +0100 Subject: [PATCH 2/2] Fix formatting and add the generated files --- .../ipynb/reproducibility_recipes.ipynb | 7 ++- .../md/reproducibility_recipes.md | 62 +++++++++++-------- .../keras_recipes/reproducibility_recipes.py | 7 ++- 3 files changed, 48 insertions(+), 28 deletions(-) diff --git a/examples/keras_recipes/ipynb/reproducibility_recipes.ipynb b/examples/keras_recipes/ipynb/reproducibility_recipes.ipynb index 89564b545a..2d0b59eeb4 100644 --- a/examples/keras_recipes/ipynb/reproducibility_recipes.ipynb +++ b/examples/keras_recipes/ipynb/reproducibility_recipes.ipynb @@ -252,8 +252,13 @@ " )\n", "\n", " model.compile(\n", - " optimizer=\"adam\", loss=\"sparse_categorical_crossentropy\", metrics=[\"accuracy\"]\n", + " optimizer=\"adam\",\n", + " loss=\"sparse_categorical_crossentropy\",\n", + " metrics=[\"accuracy\"],\n", + " jit_compile=False,\n", " )\n", + " # jit_compile's default value is \"auto\" which will cause some problems in some\n", + " # ops, therefore it's set to False.\n", "\n", " # model.fit has a `shuffle` parameter which has a default value of `True`.\n", " # If you are using array-like objects, this will shuffle the data before\n", diff --git a/examples/keras_recipes/md/reproducibility_recipes.md b/examples/keras_recipes/md/reproducibility_recipes.md index e18e36273e..2ceff76a3d 100644 --- a/examples/keras_recipes/md/reproducibility_recipes.md +++ b/examples/keras_recipes/md/reproducibility_recipes.md @@ -87,8 +87,8 @@ for initializer in initializers_list:
``` Running - Iteration --> 0 // Result --> 0.05609520897269249 - Iteration --> 1 // Result --> 0.05609520897269249 + Iteration --> 0 // Result --> 0.000790853810030967 + Iteration --> 1 // Result --> 0.000790853810030967 ```
@@ -96,8 +96,8 @@ Running
``` Running - Iteration --> 0 // Result --> 0.03690483793616295 - Iteration --> 1 // Result --> 0.03690483793616295 + Iteration --> 0 // Result --> -0.02175668440759182 + Iteration --> 1 // Result --> -0.02175668440759182 ```
@@ -105,8 +105,8 @@ Running
``` Running - Iteration --> 0 // Result --> 0.05230803042650223 - Iteration --> 1 // Result --> 0.05230803042650223 + Iteration --> 0 // Result --> 0.000790853810030967 + Iteration --> 1 // Result --> 0.000790853810030967 ```
@@ -114,8 +114,8 @@ Running
``` Running - Iteration --> 0 // Result --> 1.1893247365951538 - Iteration --> 1 // Result --> 1.1893247365951538 + Iteration --> 0 // Result --> 0.017981600016355515 + Iteration --> 1 // Result --> 0.017981600016355515 ```
@@ -123,8 +123,8 @@ Running
``` Running - Iteration --> 0 // Result --> 1.1893247365951538 - Iteration --> 1 // Result --> 1.1893247365951538 + Iteration --> 0 // Result --> 0.017981600016355515 + Iteration --> 1 // Result --> 0.017981600016355515 ```
@@ -132,8 +132,8 @@ Running
``` Running - Iteration --> 0 // Result --> 1.2784210443496704 - Iteration --> 1 // Result --> 1.2784210443496704 + Iteration --> 0 // Result --> -0.7536736726760864 + Iteration --> 1 // Result --> -0.7536736726760864 ```
@@ -141,8 +141,8 @@ Running
``` Running - Iteration --> 0 // Result --> 1.6819592714309692 - Iteration --> 1 // Result --> 1.6819592714309692 + Iteration --> 0 // Result --> 0.025429822504520416 + Iteration --> 1 // Result --> 0.025429822504520416 ```
@@ -150,8 +150,8 @@ Running
``` Running - Iteration --> 0 // Result --> 1.8079603910446167 - Iteration --> 1 // Result --> 1.8079603910446167 + Iteration --> 0 // Result --> -1.065855622291565 + Iteration --> 1 // Result --> -1.065855622291565 ```
@@ -159,8 +159,8 @@ Running
``` Running - Iteration --> 0 // Result --> 1.1893247365951538 - Iteration --> 1 // Result --> 1.1893247365951538 + Iteration --> 0 // Result --> 0.017981600016355515 + Iteration --> 1 // Result --> 0.017981600016355515 ```
@@ -168,8 +168,8 @@ Running
``` Running - Iteration --> 0 // Result --> 1.2784210443496704 - Iteration --> 1 // Result --> 1.2784210443496704 + Iteration --> 0 // Result --> -0.7536736726760864 + Iteration --> 1 // Result --> -0.7536736726760864 ```
@@ -273,8 +273,13 @@ def train_model(train_data: tf.data.Dataset, test_data: tf.data.Dataset) -> dict ) model.compile( - optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"] + optimizer="adam", + loss="sparse_categorical_crossentropy", + metrics=["accuracy"], + jit_compile=False, ) + # jit_compile's default value is "auto" which will cause some problems in some + # ops, therefore it's set to False. # model.fit has a `shuffle` parameter which has a default value of `True`. # If you are using array-like objects, this will shuffle the data before @@ -298,6 +303,13 @@ train_ds = tf.data.Dataset.from_tensor_slices((train_images, train_labels)) test_ds = tf.data.Dataset.from_tensor_slices((test_images, test_labels)) ``` +
+``` +Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz + 11490434/11490434 ━━━━━━━━━━━━━━━━━━━━ 0s 0us/step + +``` +
Remember we called `tf.config.experimental.enable_op_determinism()` at the beginning of the function. This makes the `tf.data` operations deterministic. However, making `tf.data` operations deterministic comes with a performance @@ -375,11 +387,11 @@ history = train_model(train_data, test_data)
``` Epoch 1/2 - 938/938 ━━━━━━━━━━━━━━━━━━━━ 26s 27ms/step - accuracy: 0.5418 - loss: 1.2867 - val_accuracy: 0.9291 - val_loss: 0.2303 + 938/938 ━━━━━━━━━━━━━━━━━━━━ 73s 73ms/step - accuracy: 0.5726 - loss: 1.2175 - val_accuracy: 0.9401 - val_loss: 0.1924 Epoch 2/2 - 938/938 ━━━━━━━━━━━━━━━━━━━━ 25s 26ms/step - accuracy: 0.9075 - loss: 0.2983 - val_accuracy: 0.9583 - val_loss: 0.1343 - 157/157 ━━━━━━━━━━━━━━━━━━━━ 1s 4ms/step - accuracy: 0.9512 - loss: 0.1559 -Model accuracy on test data: 95.83% + 938/938 ━━━━━━━━━━━━━━━━━━━━ 89s 81ms/step - accuracy: 0.9105 - loss: 0.2885 - val_accuracy: 0.9630 - val_loss: 0.1131 + 157/157 ━━━━━━━━━━━━━━━━━━━━ 3s 17ms/step - accuracy: 0.9553 - loss: 0.1353 +Model accuracy on test data: 96.30% ```
diff --git a/examples/keras_recipes/reproducibility_recipes.py b/examples/keras_recipes/reproducibility_recipes.py index 5787bd9f5b..8448c3c8a6 100644 --- a/examples/keras_recipes/reproducibility_recipes.py +++ b/examples/keras_recipes/reproducibility_recipes.py @@ -151,10 +151,13 @@ def train_model(train_data: tf.data.Dataset, test_data: tf.data.Dataset) -> dict ) model.compile( - optimizer="adam", loss="sparse_categorical_crossentropy", metrics=["accuracy"], jit_compile = False + optimizer="adam", + loss="sparse_categorical_crossentropy", + metrics=["accuracy"], + jit_compile=False, ) # jit_compile's default value is "auto" which will cause some problems in some - # ops, therefore it's set to False. + # ops, therefore it's set to False. # model.fit has a `shuffle` parameter which has a default value of `True`. # If you are using array-like objects, this will shuffle the data before