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
My goal is to implement a stateful module where the state, a memory bank, exists only temporary and is reset after a certain amount of iterations, which will be indicated through a parameter. What is the most idiomatic way of approaching this? I would like to keep this limited to just jax and stax, so no Haiku or Flax.
The idea I came up with is basically to store a list as part of the parameters, and in that list to store the state, and replace it as needed.
defMemoryModule(bank_size, G, O):
""" bank_size is the number of rows in the memory bank. G is a module from input x bank to bank O is a module from input x bank to output """definit_fun(rng, input_shape):
bank=jnp.zeros((bank_size, input_shape))
_, g_params=G[0](rng, input_shape)
out_dim, out_params=O[0](rng, input_shape)
returnout_dim, ([bank], g_params, out_params)
defapply_fun(params, inputs, **kwargs):
(bank,*_), g_params, out_params=paramsifkwargs.get("reset_bank", False):
bank=jnp.zeros((bank_size, bank.shape[1]))
bank=G[1](g_params, (inputs, bank), **kwargs)
params[0][0] =bankreturnO[1](out_params, (inputs, bank), **kwargs)
returninit_fun, apply_fun
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
My goal is to implement a stateful module where the state, a memory bank, exists only temporary and is reset after a certain amount of iterations, which will be indicated through a parameter. What is the most idiomatic way of approaching this? I would like to keep this limited to just jax and stax, so no Haiku or Flax.
The idea I came up with is basically to store a list as part of the parameters, and in that list to store the state, and replace it as needed.
Beta Was this translation helpful? Give feedback.
All reactions