Skip to content

Commit

Permalink
updated flax_basics
Browse files Browse the repository at this point in the history
  • Loading branch information
chiamp committed Sep 16, 2023
1 parent 5d846a5 commit 7367002
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 2 additions & 4 deletions docs/guides/flax_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"source": [
"import jax\n",
"from typing import Any, Callable, Sequence\n",
"from jax import lax, random, numpy as jnp\n",
"from jax import random, numpy as jnp\n",
"import flax\n",
"from flax import linen as nn"
]
Expand Down Expand Up @@ -775,8 +775,7 @@
" kernel = self.param('kernel',\n",
" self.kernel_init, # Initialization function\n",
" (inputs.shape[-1], self.features)) # shape info.\n",
" y = lax.dot_general(inputs, kernel,\n",
" (((inputs.ndim - 1,), (0,)), ((), ())),) # TODO Why not jnp.dot?\n",
" y = jnp.dot(inputs, kernel)\n",
" bias = self.param('bias', self.bias_init, (self.features,))\n",
" y = y + bias\n",
" return y\n",
Expand Down Expand Up @@ -866,7 +865,6 @@
" ra_mean = self.variable('batch_stats', 'mean',\n",
" lambda s: jnp.zeros(s),\n",
" x.shape[1:])\n",
" mean = ra_mean.value # This will either get the value or trigger init\n",
" bias = self.param('bias', lambda rng, shape: jnp.zeros(shape), x.shape[1:])\n",
" if is_initialized:\n",
" ra_mean.value = self.decay * ra_mean.value + (1.0 - self.decay) * jnp.mean(x, axis=0, keepdims=True)\n",
Expand Down
6 changes: 2 additions & 4 deletions docs/guides/flax_basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Here we provide the code needed to set up the environment for our notebook.
import jax
from typing import Any, Callable, Sequence
from jax import lax, random, numpy as jnp
from jax import random, numpy as jnp
import flax
from flax import linen as nn
```
Expand Down Expand Up @@ -394,8 +394,7 @@ class SimpleDense(nn.Module):
kernel = self.param('kernel',
self.kernel_init, # Initialization function
(inputs.shape[-1], self.features)) # shape info.
y = lax.dot_general(inputs, kernel,
(((inputs.ndim - 1,), (0,)), ((), ())),) # TODO Why not jnp.dot?
y = jnp.dot(inputs, kernel)
bias = self.param('bias', self.bias_init, (self.features,))
y = y + bias
return y
Expand Down Expand Up @@ -448,7 +447,6 @@ class BiasAdderWithRunningMean(nn.Module):
ra_mean = self.variable('batch_stats', 'mean',
lambda s: jnp.zeros(s),
x.shape[1:])
mean = ra_mean.value # This will either get the value or trigger init
bias = self.param('bias', lambda rng, shape: jnp.zeros(shape), x.shape[1:])
if is_initialized:
ra_mean.value = self.decay * ra_mean.value + (1.0 - self.decay) * jnp.mean(x, axis=0, keepdims=True)
Expand Down

0 comments on commit 7367002

Please sign in to comment.