Skip to content

Commit 36b0a7d

Browse files
MarkDaoustcopybara-github
authored andcommitted
Update function doc to use public placeholder_value() API for TraceTypes.
PiperOrigin-RevId: 515666479
1 parent 775470f commit 36b0a7d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

site/en/guide/function.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,16 +572,23 @@
572572
"# can have significant performance benefits.\n",
573573
"\n",
574574
"class FruitTraceType(tf.types.experimental.TraceType):\n",
575-
" def __init__(self, fruit_type):\n",
576-
" self.fruit_type = fruit_type\n",
575+
" def __init__(self, fruit):\n",
576+
" self.fruit_type = type(fruit)\n",
577+
" self.fruit_value = fruit\n",
577578
"\n",
578579
" def is_subtype_of(self, other):\n",
580+
" # True if self subtypes `other` and `other`'s type matches FruitTraceType.\n",
579581
" return (type(other) is FruitTraceType and\n",
580582
" self.fruit_type is other.fruit_type)\n",
581583
"\n",
582584
" def most_specific_common_supertype(self, others):\n",
585+
" # `self` is the specific common supertype if all input types match it.\n",
583586
" return self if all(self == other for other in others) else None\n",
584587
"\n",
588+
" def placeholder_value(self, placeholder_context=None):\n",
589+
" # Use the fruit itself instead of the type for correct tracing.\n",
590+
" return self.fruit_value\n",
591+
"\n",
585592
" def __eq__(self, other):\n",
586593
" return type(other) is FruitTraceType and self.fruit_type == other.fruit_type\n",
587594
" \n",
@@ -591,7 +598,7 @@
591598
"class FruitWithTraceType:\n",
592599
"\n",
593600
" def __tf_tracing_type__(self, context):\n",
594-
" return FruitTraceType(type(self))\n",
601+
" return FruitTraceType(self)\n",
595602
"\n",
596603
"class AppleWithTraceType(FruitWithTraceType):\n",
597604
" flavor = tf.constant([1, 2])\n",
@@ -1831,8 +1838,8 @@
18311838
],
18321839
"metadata": {
18331840
"colab": {
1834-
"collapsed_sections": [],
18351841
"name": "function.ipynb",
1842+
"provenance": [],
18361843
"toc_visible": true
18371844
},
18381845
"kernelspec": {

0 commit comments

Comments
 (0)