ott.neural.networks.potentials.BasePotential.lazy_init#
- BasePotential.lazy_init(rngs, *args, method=None, mutable=DenyList(deny='intermediates'), **kwargs)#
Initializes a module without providing actual input data.
Input data that is not needed for initialization can be passed as a
jax.ShapeDtypeStruct, which specifies the shape and dtype of the input but no concrete data. EachShapeDtypeStructis replaced with an all-zeros array of that shape and dtype before initialization runs.Example:
>>> model = nn.Dense(features=256) >>> variables = model.lazy_init( ... jax.random.key(0), jax.ShapeDtypeStruct((1, 128), jnp.float32))
The args and kwargs args passed to
lazy_initcan be a mix of concrete (jax arrays, scalars, bools) and abstract (ShapeDtypeStruct) values. Concrete values are necessary for arguments that affect the initialization of variables. For example, the model might expect a keyword arg that enables/disables a subpart of the model; an explicit value (True/False) should be passed for it. If a variable’s initialization depends on the value of an argument given as aShapeDtypeStruct, the variable is silently initialized as if that argument were all zeros.- Parameters:
rngs (
Array|dict[str,Array]) – The rngs for the variable collections.*args – arguments passed to the init function.
method (
Callable[...,Any] |None) – An optional method. If provided, applies this method. If not provided, applies the__call__method.mutable (
Union[bool,str,Collection[str],DenyList]) – Can be bool, str, or list. Specifies which collections should be treated as mutable:bool: all/no collections are mutable.str: The name of a single mutable collection.list: A list of names of mutable collections. By default all collections except “intermediates” are mutable.**kwargs – Keyword arguments passed to the init function.
- Return type:
FrozenDict[str,Mapping[str,Any]]- Returns:
The initialized variable dict.