named_sequential#

delu.nn.named_sequential(
*names_and_modules: Tuple[str, Module],
) Sequential[source]#

A shortcut for creating torch.nn.Sequential with named modules without using collections.OrderedDict.

The sole purpose of this function is to improve the ergonomics and readability of the common construction.

Usage

This …

>>> m = delu.nn.named_sequential(
...     ('linear1', nn.Linear(10, 20)),
...     ('activation', nn.ReLU()),
...     ('linear2', nn.Linear(20, 1)),
... )

… is equivalent to this:

>>> from collections import OrderedDict
>>> m = torch.nn.Sequential(
...     OrderedDict(
...         [
...             ('linear1', nn.Linear(10, 20)),
...             ('activation', nn.ReLU()),
...             ('linear2', nn.Linear(20, 1)),
...         ]
...     )
... )
Parameters:

names_and_modules – the names and the modules.