Skip to content

Commit 4f5220c

Browse files
chenmoneygithubcopybara-github
authored andcommitted
Use legacy optimizer in TPU embedding.
PiperOrigin-RevId: 475892987
1 parent 993919c commit 4f5220c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

site/en/guide/migrate/tpu_embedding.ipynb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,10 @@
476476
"source": [
477477
"strategy = tf.distribute.TPUStrategy(cluster_resolver)\n",
478478
"with strategy.scope():\n",
479-
" optimizer = tf.keras.optimizers.Adagrad(learning_rate=0.05)\n",
479+
" if hasattr(tf.keras.optimizers, \"legacy\"):\n",
480+
" optimizer = tf.keras.optimizers.legacy.Adagrad(learning_rate=0.05)\n",
481+
" else:\n",
482+
" optimizer = tf.keras.optimizers.Adagrad(learning_rate=0.05)\n",
480483
" dense_input = tf.keras.Input(shape=(2,), dtype=tf.float32, batch_size=global_batch_size)\n",
481484
" sparse_input = tf.keras.Input(shape=(), dtype=tf.int32, batch_size=global_batch_size)\n",
482485
" embedded_input = tfrs.layers.embedding.TPUEmbedding(\n",
@@ -574,6 +577,7 @@
574577
"colab": {
575578
"collapsed_sections": [],
576579
"name": "tpu_embedding.ipynb",
580+
"provenance": [],
577581
"toc_visible": true
578582
},
579583
"kernelspec": {

0 commit comments

Comments
 (0)