Skip to content

Commit

Permalink
Update [recipes]sharing.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
ASEM000 committed Apr 6, 2024
1 parent 89e5889 commit 6142118
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions docs/notebooks/[recipes]sharing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In this example a simple `AutoEncoder` with shared `weight` between the encode/decoder is demonstrated. "
"In this example a simple `AutoEncoder` with shared `weight` between the encode/decoder is demonstrated."
]
},
{
Expand All @@ -66,7 +66,9 @@
"import functools as ft\n",
"\n",
"\n",
"def stateful(method):\n",
"def sharing(method):\n",
" # sharing simply copies the instance, executes the method, and returns the output\n",
" # **without modifying the original instance.**\n",
" @ft.wraps(method)\n",
" def wrapper(self, *args, **kwargs):\n",
" # `value_and_tree` executes any mutating method in a functional way\n",
Expand Down Expand Up @@ -95,7 +97,7 @@
" self.dec2 = Linear(20, 10, key=k3)\n",
" self.dec1 = Linear(10, 1, key=k4)\n",
"\n",
" @stateful\n",
" @sharing\n",
" def tied_call(self, input: jax.Array) -> jax.Array:\n",
" self.dec1.weight = self.enc1.weight.T\n",
" self.dec2.weight = self.enc2.weight.T\n",
Expand Down

0 comments on commit 6142118

Please sign in to comment.