penzai.nn.parameters.add_parameter_prefix(prefix: str, tree: Any, delimiter: str = '.') Any[source]#

Prepends a prefix to all parameter names inside the tree.

This function can be used to avoid name conflicts when combining sublayers into a larger model layer. For instance, composite layers (subclasses of Sequential) can call add_parameter_prefix from their from_config, to ensure that none of their sublayers have conflicting names.


A version of tree where all Parameter, FrozenParameter, and UninitializedParameter instances, and any other subclass of SupportsParameterRenaming, have their names updated to new names with the format "{prefix}{delimiter}{original_name}".