nnrl/nn/init.py
def initialize_(
    name: Optional[str] = None, activation: Union[str, dict] = None, **options
) -> Callable[[nn.Module], None]:
    """Return a callable to apply an initializer with the given name and options.

    If `gain` is part of the initializer's argspec and is not specified in options,
    the recommended value from `torch.nn.init.calculate_gain` is used.

    Arguments:
        name: Initializer function name
        activation: Optional specification of the activation function that
            follows linear layers
        **options: Keyword arguments to pass to the initializer

    Returns:
        A callable to be used with `nn.Module.apply`.
    """

    initializer = get_initializer(name)

    if isinstance(activation, dict):
        activation = activation["name"]
        options.update(activation.get("options", {}))

    if (
        activation in NONLINEARITY_MAP
        and "gain" not in options
        and "gain" in inspect.signature(initializer).parameters
    ):
        recommended_gain = nn.init.calculate_gain(
            NONLINEARITY_MAP[activation], param=options.get("negative_slope")
        )
        options["gain"] = recommended_gain
    func_ = functools.partial(initializer, **options)

    def init(module):
        if isinstance(module, nn.Linear):
            func_(module.weight)
            if module.bias is not None:
                nn.init.constant_(module.bias, 0)

    return init
Return a callable to apply an initializer with the given name and options.

    If `gain` is part of the initializer's argspec and is not specified in options,
    the recommended value from `torch.nn.init.calculate_gain` is used.

    Arguments:
        name: Initializer function name
        activation: Optional specification of the activation function that
            follows linear layers
        **options: Keyword arguments to pass to the initializer

    Returns:
        A callable to be used with `nn.Module.apply`.
    
Return a callable to apply an initializer with the given name and options.
If `gain` is part of the initializer's argspec and is not specified in options,
the recommended value from `torch.nn.init.calculate_gain` is used.
Return a callable to apply an initializer with the given name and options . If ` gain ` is part of the initializer ' s argspec and is not specified in options the recommended value from ` torch . nn . init . calculate_gain ` is used .
def initialize_(
    name: Optional[str] = None, activation: Union[str, dict] = None, **options
) -> Callable[[nn.Module], None]:
    initializer = get_initializer(name)
    if isinstance(activation, dict):
        activation = activation["name"]
        options.update(activation.get("options", {}))
    if (
        activation in NONLINEARITY_MAP
        and "gain" not in options
        and "gain" in inspect.signature(initializer).parameters
    ):
        recommended_gain = nn.init.calculate_gain(
            NONLINEARITY_MAP[activation], param=options.get("negative_slope")
        )
        options["gain"] = recommended_gain
    func_ = functools.partial(initializer, **options)
    def init(module):
        if isinstance(module, nn.Linear):
            func_(module.weight)
            if module.bias is not None:
                nn.init.constant_(module.bias, 0)
    return init
def initialize_ ( name : Optional [ str ] = None , activation : Union [ str , dict ] = None , ** options ) -> Callable [ [ nn . Module ] , None ] : initializer = get_initializer ( name ) if isinstance ( activation , dict ) : activation = activation [ "name" ] options . update ( activation . get ( "options" , { } ) ) if ( activation in NONLINEARITY_MAP and "gain" not in options and "gain" in inspect . signature ( initializer ) . parameters ) : recommended_gain = nn . init . calculate_gain ( NONLINEARITY_MAP [ activation ] , param = options . get ( "negative_slope" ) ) options [ "gain" ] = recommended_gain func_ = functools . partial ( initializer , ** options ) def init ( module ) : if isinstance ( module , nn . Linear ) : func_ ( module . weight ) if module . bias is not None : nn . init . constant_ ( module . bias , 0 ) return init
Return a callable to apply an initializer with the given name and options.
Return a callable to apply an initializer with the given name and options .
"""Return a callable to apply an initializer with the given name and options.

    If `gain` is part of the initializer's argspec and is not specified in options,
    the recommended value from `torch.nn.init.calculate_gain` is used.

    Arguments:
        name: Initializer function name
        activation: Optional specification of the activation function that
            follows linear layers
        **options: Keyword arguments to pass to the initializer

    Returns:
        A callable to be used with `nn.Module.apply`.
    """
A callable to be used with `nn.Module.apply`.
A callable to be used with ` nn . Module . apply ` .
name
Optional[str]
Initializer function name
Initializer function name
activation
Union[str, dict]
Optional specification of the activation function that
follows linear layers
Optional specification of the activation function that follows linear layers
**options
Keyword arguments to pass to the initializer
Keyword arguments to pass to the initializer