mark_shareable#
- penzai.nn.parameters.mark_shareable(submodel: Any)[source]#
Marks all uninitialized parameters in
submodelas shareable.This function is used to annotate the parameters in part of a model as being shareable: all
UninitializedParameterinstances will be replaced by equivalentShareableUninitializedParameterinstances. The submodel can then be used multiple times, as long as all uses are wrapped in a single call toattach_shared_parameters.Parameter sharing is opt-in only to avoid accidentally sharing parameters due to name collisions. By convention, any caller that calls
make_shareableis also responsible for constructing theattach_shared_parameterswrapper that will actually own the shared parameters.- Parameters:
submodel – Part of a model whose parameters should be shared.
- Returns:
A copy of
submodelwhere allUninitializedParameterinstances have been replaced byShareableUninitializedParameterinstances.