torchoutil.nn.modules.container module

class EModuleDict(
modules: Mapping[str, SupportsTypedForward[InType, OutType3] | EModule[InType, OutType]] | None = None,
*,
strict_load: bool = False,
config_to_extra_repr: bool = False,
device_detect_mode: Literal['proxy', 'first_param', 'none'] = _DEFAULT_DEVICE_DETECT_MODE,
)[source]
class EModuleDict(
modules: Mapping[str, Module] | None = None,
*,
strict_load: bool = False,
config_to_extra_repr: bool = False,
device_detect_mode: Literal['proxy', 'first_param', 'none'] = _DEFAULT_DEVICE_DETECT_MODE,
)

Bases: Generic[InType, OutType3], EModule[InType, Dict[str, OutType3]], ModuleDict

Enriched torch.nn.ModuleDict with proxy device, forward typing and automatic configuration detection from attributes.

Designed to work with torchoutil.nn.EModule instances. The default behaviour is the same than PyTorch ModuleDict class, except for the forward call which returns a dict containing the output of each module called separately.

forward(
*args: InType,
**kwargs: InType,
) Dict[str, OutType3][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class EModuleList(
modules: Iterable[SupportsTypedForward[InType, OutType3] | EModule[InType, OutType]] | None = None,
*,
strict_load: bool = False,
config_to_extra_repr: bool = False,
device_detect_mode: Literal['proxy', 'first_param', 'none'] = _DEFAULT_DEVICE_DETECT_MODE,
)[source]
class EModuleList(
modules: Iterable[Module] | None = None,
*,
strict_load: bool = False,
config_to_extra_repr: bool = False,
device_detect_mode: Literal['proxy', 'first_param', 'none'] = _DEFAULT_DEVICE_DETECT_MODE,
)

Bases: Generic[InType, OutType3], EModule[InType, List[OutType3]], ModuleList

Enriched torch.nn.ModuleList with proxy device, forward typing and automatic configuration detection from attributes.

Designed to work with torchoutil.nn.EModule instances. The default behaviour is the same than PyTorch ModuleList class, except for the forward call which returns a list containing the output of each module called separately.

forward(
*args: InType,
**kwargs: InType,
) List[OutType3][source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class EModulePartial(
fn: Callable[[InType, P], OutType],
*args: P,
**kwargs: P,
)[source]

Bases: Generic[InType, OutType], EModule[InType, OutType]

extra_repr() str[source]

Set the extra representation of the module.

To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.

forward(
x: InType,
) OutType[source]

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

ModuleDict

alias of EModuleDict

ModuleList

alias of EModuleList

ModulePartial

alias of EModulePartial