class penzai.nn.parameters.ParameterLike[source]#

Bases: Protocol, Generic[T]

Protocol for a parameter-like object.

ParameterLike defines the common API for parameters in penzai.nn. Any parameterized network layer should annotate its parameters as ParameterLike, and should not make assumptions about the exact implementation of ParameterLike used.

Rules for a ParameterLike implementation:

  • .value_structure should always be a concrete structure defining the structure of the parameter’s value, usually an instance of shapecheck.ArraySpec (with no dimension variables). Accessing this should never raise an exception.

  • .value should be the concrete value of the parameter if available. However, it is allowed for accessing .value to raise an exception if this type is a placeholder for a concrete runtime parameter. In particular, this can raise an exception if this parameter is uninitialized or if it is a reference to a shared parameter that has not been provided yet.

ParameterLike is a protocol, which means implementations of it do not have to explicitly subclass it. If you define value as a dataclass attribute rather than a property, you should avoid subclassing ParameterLike directly, since Python’s ABC system will not see that as an implementation of the method.


__init__(*args, **kwargs)



The value of the parameter.


The structure of the parameter.

abstract property value: T#

The value of the parameter. May raise an error for some instances.

abstract property value_structure: shapecheck.StructureAnnotation#

The structure of the parameter.