BaseBlock#
- class deeplay.blocks.base.BaseBlock(*args, **kwargs)#
Bases:
SequentialBlockMethods Summary
activated([activation, mode, after])build(*args, **kwargs)Modifies the current instance of the module in place, finalizing its setup.
Calls the forward method with dummy data to build the block.
forward(x)Define the computation performed at every call.
Returns the default activation function for the block.
Returns the default merge operation for the block.
Returns the default normalization function for the block.
Returns the default shortcut function for the block.
multi([n])normalized([normalization, mode, after])set(name, module[, mode, after])Sets an attribute for the module, allowing for persistent configuration across checkpoints.
shortcut([merge, shortcut])Methods Documentation
- activated(activation: Type[Module] | DeeplayModule | None = None, mode='append', after=None) Self#
- build(*args, **kwargs)#
Modifies the current instance of the module in place, finalizing its setup.
The build method is essential for completing the initialization of the module. It applies the necessary configurations and adjustments directly to the existing instance. Unlike create, which generates a new module instance, build works on the current module instance. This method is particularly crucial for subclasses of dl.External, as it triggers the instantiation of actual torch layers (like Linear, Sigmoid, ReLU, etc.) within the module. For most other objects, build primarily serves to finalize their configuration.
Note that build is automatically called within the create method, ensuring that newly created instances are fully initialized and ready for use.
Parameters#
Returns#
- DeeplayModule
The current instance of the module after applying all configurations and adjustments.
Example Usage#
Finalizing the setup of a module instance with build:
` module = ExampleModule(a=0) module.configure(a=1) built_module = module.build() # `built_module` is the same instance as `module`, now fully configured and initialized `
- abstract call_with_dummy_data()#
Calls the forward method with dummy data to build the block.
- error_on_failed_forward()#
- forward(x)#
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
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- get_default_activation() DeeplayModule#
Returns the default activation function for the block.
- abstract get_default_normalization() DeeplayModule#
Returns the default normalization function for the block.
- get_default_shortcut() DeeplayModule#
Returns the default shortcut function for the block.
- multi(n=1) Self#
- normalized(normalization: Type[Module] | DeeplayModule | None = None, mode='append', after=None) Self#
- set(name, module: Type[Module] | DeeplayModule, mode='append', after=None) Self#
Sets an attribute for the module, allowing for persistent configuration across checkpoints.
This method is intended for setting module parameters or configurations that should be restored when loading a module from a saved checkpoint.
Parameters#
- name: str
The name of the attribute to set.
- value: any
The value to assign to the attribute.
Example#
>>> module.set("attribute", 42) >>> module.attribute 42
- shortcut(merge: MergeOp | None = None, shortcut: Type[Module] | DeeplayModule | None = None) Self#