Skip to content

Commit f2427a6

Browse files
Spyboticsguycopybara-github
authored andcommitted
Move TF1 hashing example out of code cell.
A planned change in TensorFlow will disable hashing of tensors in eager execution mode even when numpy-style equality is disabled (the TensorFlow 1 default). This will break the moved example. Since we cannot disable and re-enable eager execution after the beginning of the program, this example is no longer runnable under TF2 - even with the compatibility layer. As noted in the edited documentation, `set` requires its elements to be hashable - since this example runs under TF2 and we will no longer allow hashing of tensors in eager execution mode full-stop, the code _is_ valid TF1 code but cannot be run with the proposed changes to TF2. PiperOrigin-RevId: 520100823
1 parent 9159cb6 commit f2427a6

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

site/en/guide/migrate/tf1_vs_tf2.ipynb

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,28 +1027,12 @@
10271027
},
10281028
"source": [
10291029
"### Hashing tensors and variables\n",
1030-
"With TF1.x behaviors you used to be able to directly add variables and tensors to data structures that require hashing, such as `set` and `dict` keys."
1031-
]
1032-
},
1033-
{
1034-
"cell_type": "code",
1035-
"execution_count": null,
1036-
"metadata": {
1037-
"id": "fxi7EgKdBpd5"
1038-
},
1039-
"outputs": [],
1040-
"source": [
1041-
"tf.compat.v1.disable_tensor_equality()\n",
1030+
"With TF1.x behaviors you used to be able to directly add variables and tensors to data structures that require hashing, such as `set` and `dict` keys.\n",
1031+
"```python\n",
10421032
"x = tf.Variable(0.0)\n",
1043-
"set([x, tf.constant(2.0)])"
1044-
]
1045-
},
1046-
{
1047-
"cell_type": "markdown",
1048-
"metadata": {
1049-
"id": "LFgjR-PSajVQ"
1050-
},
1051-
"source": [
1033+
"set([x, tf.constant(2.0)])\n",
1034+
"```\n",
1035+
"\n",
10521036
"However, in TF2 with tensor equality enabled, tensors and variables are made unhashable due to the `==` and `!=` operator semantics changing to value equality checks."
10531037
]
10541038
},

0 commit comments

Comments
 (0)