You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: site/en/guide/migrate/tf1_vs_tf2.ipynb
+5-21Lines changed: 5 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -1027,28 +1027,12 @@
1027
1027
},
1028
1028
"source": [
1029
1029
"### 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",
1042
1032
"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",
1052
1036
"However, in TF2 with tensor equality enabled, tensors and variables are made unhashable due to the `==` and `!=` operator semantics changing to value equality checks."
0 commit comments