ott.solvers.nn.models.MLP.variable#
- MLP.variable(col, name, init_fn=None, *init_args, unbox=True)#
Declares and returns a variable in this Module.
See
flax.core.variables
for more information. See alsoparam()
for a shorthand way to define read-only variables in the “params” collection.Contrary to
param()
, all arguments passing using init_fn should be passed on explicitly:key = self.make_rng('stats') mean = self.variable('stats', 'mean', lecun_normal(), key, (2, 2))
In the example above, the function lecun_normal expects two arguments: key and shape, and both have to be passed on. The PRNG for stats has to be provided explicitly when calling
init()
andapply()
.- Parameters:
col (
str
) – The variable collection name.name (
str
) – The variable name.init_fn (
Optional
[Callable
[...
,Any
]]) – The function that will be called to compute the initial value of this variable. This function will only be called the first time this variable is used in this module. If None, the variable must already be initialized otherwise an error is raised.*init_args – The arguments to pass to init_fn.
unbox (
bool
) – If True,AxisMetadata
instances are replaced by their unboxed value, seeflax.nn.meta.unbox
(default: True).
- Return type:
- Returns:
A
flax.core.variables.Variable
that can be read or set via “.value” attribute. Throws an error if the variable exists already.