Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose module.merge_param in RTD and fix docstring #2680

Merged
merged 2 commits into from
Dec 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions flax/linen/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,10 +1657,11 @@ def __call__(self, x):
_ParentType = Union[Type[Module], Type[Scope], Type[_Sentinel], None]

def merge_param(name: str, a: Optional[T], b: Optional[T]) -> T:
"""Merges construction and call time argument.
"""Merges construction- and call-time argument.

This is a utility for supporting the pattern where a Module hyper parameter
can be passed to ``__init__`` or ``__call__``.
This is a utility for supporting a pattern where a Module hyperparameter
can be passed either to ``__init__`` or ``__call__``, and the value that is
not `None` will be used.

Example::

Expand All @@ -1670,7 +1671,8 @@ class Foo(nn.Module):
def __call__(self, train: Optional[bool] = None):
train = nn.merge_param('train', self.train, train)

An error is thrown when both arguments are `None` or both values are not `None`.
An error is thrown when both arguments are `None` or both values are not
`None`.

Args:
name: the name of the parameter. Used for error messages.
Expand Down