Module

Base class for deriving trainable modules

class ivy.stateful.module.Module(device=None, v=None, build_mode='on_init', compile_on_next_step=False, store_vars=True, stateful=None, arg_stateful_idxs=None, kwarg_stateful_idxs=None, fallback_to_non_compiled=False, with_partial_v=False, devices=None, dtype=None)[source]

Bases: ABC

__init__(device=None, v=None, build_mode='on_init', compile_on_next_step=False, store_vars=True, stateful=None, arg_stateful_idxs=None, kwarg_stateful_idxs=None, fallback_to_non_compiled=False, with_partial_v=False, devices=None, dtype=None)[source]

Initialze Ivy layer, which is a stateful object consisting of trainable variables.

Parameters
  • device – device on which to create the module’s variables ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None)

  • v – Ivy container of trainable variables. Created internally by default.

  • build_mode – How the Module is built, either on initialization (now), explicitly by the user by calling build(), or the first time the __call__ method is run. Default is on initialization.

  • compile_on_next_step – Whether to compile the network on the next forward pass. Default is False.

  • store_vars – Whether or not to store the variables created. Default is True.

  • stateful – The constant id stateful items to track as part of the forward pass. Used when graph compiling, default is None.

  • arg_stateful_idxs – The nested argument indices of stateful items to track as part of the forward pass. Used when graph compiling, default is None.

  • kwarg_stateful_idxs – The nested keyword argument indices of stateful items to track as part of the forward pass. Used when graph compiling, default is None.

  • fallback_to_non_compiled – Whether to fall back to non-compiled forward call in the case that an error is raised during the compiled forward pass. Default is True.

  • with_partial_v – Whether to allow partial specification of variables. Default is False.

  • devices – devices on which to distribute the module’s variables ‘cuda:0’, ‘cuda:1’, ‘cpu’ etc. (Default value = None)

build(*args, from_call=False, device=None, dtype=None, **kwargs)[source]

Build the internal layers and variables for this module.

property build_mode
property built
check_submod_rets()[source]
get_mod_key(top_mod=None)[source]
mod_depth()[source]
mod_height()[source]
mod_with_top_mod_key_chain(depth=None, flatten_key_chain=False)[source]
save_weights(weights_path)[source]

Save the weights on the Module.

Parameters

weights_path – The hdf5 file for saving the weights.

show_mod_in_top_mod(upper_depth=None, lower_depth=None, flatten_key_chains=False)[source]
show_structure()[source]
show_v_in_top_v(depth=None)[source]
sub_mods(show_v=True, depth=None, flatten_key_chains=False)[source]
track_submod_call_order()[source]
track_submod_rets()[source]
v_with_top_v_key_chains(depth=None, flatten_key_chains=False)[source]