External#

class deeplay.external.external.External(*args, **kwargs)#

Bases: DeeplayModule

Attributes Summary

Methods Summary

assert_not_positional_only_and_variadic()

build()

Modifies the current instance of the module in place, finalizing its setup.

build_arguments_from(*args, classtype, **kwargs)

configure()

Configures the module with specified arguments.

create()

Creates and returns a new instance of the module, fully initialized with the current configuration.

get_argspec()

get_init_args()

get_signature()

Attributes Documentation

kwargs#

Methods Documentation

assert_not_positional_only_and_variadic()#
build() Module#

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#

*args, **kwargsAny

Example input to the forward method used to

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 `

build_arguments_from(*args, classtype, **kwargs)#
configure(classtype, **kwargs) None#
configure(**kwargs: Any) None

Configures the module with specified arguments.

This method allows dynamic configuration of the module’s properties and behaviors. It can be used to set or modify the attributes and parameters of the module and, if applicable, its child modules. The method intelligently handles both direct attribute configuration and delegation to child modules’ configure methods.

Parameters#

*argsAny

Positional arguments specifying the configuration settings. When the first argument is a string matching a configurable attribute, the method expects either one or two arguments: the attribute name and, optionally, its value. If the attribute is itself a DeeplayModule, subsequent arguments are passed to its configure method.

**kwargsAny

Keyword arguments for configuration settings. If provided, these are used to update the module’s configuration directly.

Raises#

ValueError

Raised if a configuration key is not recognized as a valid configurable for the module or if the provided arguments do not match the expected pattern for configuration.

Example Usage#

To configure a single attribute: ` module.configure('attribute_name', attribute_value) # or module.configure(attribute_name=attribute_value) `

To configure multiple attributes using keyword arguments: ` module.configure(attribute1=value1, attribute2=value2) `

To configure a child module’s attribute: ` module.configure('child_module_attribute', child_attribute=child_attribute_value) # or module.child_module.configure(child_attribute=child_attribute_value) `

create() Module#

Creates and returns a new instance of the module, fully initialized with the current configuration.

This method differs from build in that it generates a new, independent instance of the module, rather than modifying the existing one. It’s particularly relevant for subclasses of dl.External, where actual torch layers (like Linear, Sigmoid, ReLU, etc.) are instantiated during the build process. For these subclasses, create not only configures but also instantiates the specified torch layers. For most other objects, the .build() step, which is internally called in create, has no additional effect beyond configuration.

Returns#

DeeplayModule

A new instance of the DeeplayModule (or its subclass), initialized with the current module’s configuration and, for dl.External subclasses, with instantiated torch layers.

Example Usage#

Creating a dl.Layer instance and then fully initializing it with create: ` layer = dl.Layer(nn.Linear, in_features=20, out_features=40) # At this point, `layer` has not instantiated nn.Linear built_layer = layer.create() # Now, `built_layer` is an instance of nn.Linear(in_features=20, out_features=40) `

get_argspec()#
get_init_args()#
get_signature()#