brainstate.nn.call_all_fns

Contents

brainstate.nn.call_all_fns#

brainstate.nn.call_all_fns(target, fn_name, args=(), kwargs=None, node_to_exclude=None, fn_if_not_exist='raise')#

Call a specified function on all module nodes within a target, respecting call order.

This function traverses all module nodes in the target and invokes the specified method on each node. Functions decorated with @call_order() are executed in ascending order of their level values, while functions without the decorator are executed first.

Parameters:
Raises:
  • TypeError – If fun_name is not a string or kwargs is not a mapping.

  • ValueError – If fn_if_not_exist is not one of the allowed values.

  • AttributeError – If the specified method doesn’t exist on a node and fn_if_not_exist is ‘raise’.

Return type:

TypeVar(T, bound= Module)

Examples

>>> import brainstate
>>>
>>> net = brainstate.nn.Sequential(brainstate.nn.Linear(10, 20), brainstate.nn.ReLU())
>>> brainstate.nn.call_all_fns(net, 'init_state')