torchwrench.nn.modules.container module

class torchwrench.nn.modules.container.EModuleDict(modules: Mapping[str, TypedModuleLike[InType, OutType3]] | None = None, *, strict_load: bool = False, config_to_extra_repr: bool = False, device_detect_mode: 'proxy' | 'first_param' | 'none' = _DEFAULT_DEVICE_DETECT_MODE)[source]
class torchwrench.nn.modules.container.EModuleDict(modules: Mapping[str, Module] | None = None, *, strict_load: bool = False, config_to_extra_repr: bool = False, device_detect_mode: '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 torchwrench.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 torchwrench.nn.modules.container.EModuleList(modules: Iterable[TypedModuleLike[InType, OutType3]] | None = None, *, strict_load: bool = False, config_to_extra_repr: bool = False, device_detect_mode: 'proxy' | 'first_param' | 'none' = _DEFAULT_DEVICE_DETECT_MODE)[source]
class torchwrench.nn.modules.container.EModuleList(modules: Iterable[Module] | None = None, *, strict_load: bool = False, config_to_extra_repr: bool = False, device_detect_mode: '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 torchwrench.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 torchwrench.nn.modules.container.EModulePartial(fn: Callable[[Concatenate[InType, P]], OutType], *args: __SPHINX_IMMATERIAL_TYPE_VAR__P_P, **kwargs: __SPHINX_IMMATERIAL_TYPE_VAR__P_P)[source]

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

Wrap a python callable to nn.Module class.

extra_repr() str[source]

Return 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, **kwargs: __SPHINX_IMMATERIAL_TYPE_VAR__P_P) 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.

torchwrench.nn.modules.container.ModulePartial

alias of EModulePartial