Converters#

Converters from Native Modules to Ivy Modules.

class ivy.stateful.converters.ModuleConverters[source]#

Bases: object

static from_flax_module(native_module, params_fx=None, rng_seed=0, constructor_args=None, constructor_kwargs=None, instance_args=None, instance_kwargs=None, device=None, devices=None)[source]#

Convert a Flax module instance to an Ivy module instance.

Parameters:
  • native_module – The module in the native framework to convert(class or instance).

  • params_fx (default: None) – Flax parameters to pass to the constructor of the native module. Default is None.

  • rng_seed (default: 0) – Seed used to initialize flax parameters is initializing from a class. Default is 0.

  • constructor_args (Optional[List], default: None) – Positional arguments to pass to the constructor of the native module. Default is None.

  • constructor_kwargs (Optional[Dict], default: None) –

    Key-word arguments to pass to the constructor of the native module.

    Default is None.

  • instance_args (Optional[List], default: None) – Positional arguments to pass to the forward pass of the native module. Default is None.

  • instance_kwargs (Optional[Dict], default: None) –

    Key-word arguments to pass to the forward pass of the native module.

    Default is None.

  • device (default: None) – The device on which to create module variables. Default is None.

  • devices (default: None) – The devices on which to create module variables. Default is None.

Returns:

ret – The new trainable ivy.Module instance.

static from_haiku_module(native_module, params_hk=None, rng_seed=0, constructor_args=None, constructor_kwargs=None, instance_args=None, instance_kwargs=None, device=None, devices=None)[source]#

Convert a Haiku module instance to an Ivy module instance.

Parameters:
  • native_module – The module in the native framework to convert(class or instance).

  • params_hk (default: None) – Haiku parameters to pass to the constructor of the native module. Default is None.

  • rng_seed (default: 0) – Seed used to initialize haiku parameters is initializing from a class. Default is 0.

  • constructor_args (Optional[List], default: None) – Positional arguments to pass to the constructor of the native module. Default is None.

  • constructor_kwargs (Optional[Dict], default: None) –

    Key-word arguments to pass to the constructor of the native module.

    Default is None.

  • instance_args (Optional[List], default: None) – Positional arguments to pass to the forward pass of the native module. Default is None.

  • instance_kwargs (Optional[Dict], default: None) –

    Key-word arguments to pass to the forward pass of the native module.

    Default is None.

  • device (default: None) – The device on which to create module variables. Default is None.

  • devices (default: None) – The devices on which to create module variables. Default is None.

Returns:

ret – The new trainable torch module instance.

static from_keras_module(native_module=None, constructor_args=None, constructor_kwargs=None, instance_args=None, instance_kwargs=None, device=None, devices=None)[source]#

Convert a Keras module instance to an Ivy module instance.

Parameters:
  • native_module (default: None) – The module in the native framework to convert(class or instance).

  • constructor_args (Optional[List], default: None) – Positional arguments to pass to the constructor of the native module. Default is None.

  • constructor_kwargs (Optional[Dict], default: None) –

    Key-word arguments to pass to the constructor of the native module.

    Default is None.

  • instance_args (Optional[List], default: None) – Positional arguments to pass to the forward pass of the native module. Default is None.

  • instance_kwargs (Optional[Dict], default: None) –

    Key-word arguments to pass to the forward pass of the native module.

    Default is None.

  • device (default: None) – The device on which to create module variables. Default is None.

  • devices (default: None) – The devices on which to create module variables. Default is None.

Returns:

ret – The new trainable ivy.Module instance.

static from_paddle_module(native_module=None, constructor_args=None, constructor_kwargs=None, instance_args=None, instance_kwargs=None, device=None, devices=None)[source]#

Convert a Paddle layer instance to an Ivy module instance.

Parameters:
  • native_module (default: None) – The module in the native framework to convert(class or instance)

  • constructor_args (Optional[List], default: None) – Positional arguments to pass to the constructor of the native module. Default is None.

  • constructor_kwargs (Optional[Dict], default: None) –

    Key-word arguments to pass to the constructor of the native module.

    Default is None.

  • instance_args (Optional[List], default: None) – Positional arguments to pass to the forward pass of the native module. Default is None.

  • instance_kwargs (Optional[Dict], default: None) –

    Key-word arguments to pass to the forward pass of the native module.

    Default is None.

  • device (default: None) – The device on which to create module variables. Default is None.

  • devices (default: None) – The devices on which to create module variables. Default is None.

Returns:

ret – The new trainable ivy.Module instance.

static from_torch_module(native_module=None, constructor_args=None, constructor_kwargs=None, instance_args=None, instance_kwargs=None, device=None, devices=None, inplace_update=False)[source]#

Convert a Torch module instance to an Ivy module instance.

Parameters:
  • native_module (default: None) – The module in the native framework to convert(class or instance)

  • constructor_args (Optional[List], default: None) – Positional arguments to pass to the constructor of the native module. Default is None.

  • constructor_kwargs (Optional[Dict], default: None) –

    Key-word arguments to pass to the constructor of the native module.

    Default is None.

  • instance_args (Optional[List], default: None) – Positional arguments to pass to the forward pass of the native module. Default is None.

  • instance_kwargs (Optional[Dict], default: None) –

    Key-word arguments to pass to the forward pass of the native module.

    Default is None.

  • device (default: None) – The device on which to create module variables. Default is None.

  • devices (default: None) – The devices on which to create module variables. Default is None.

  • inplace_update (default: False) – For backends with dedicated variable classes, whether to update these inplace. Default is False.

Returns:

ret – The new trainable ivy.Module instance.

to_keras_module()[source]#

Convert a ivy.Module module instance to a tf.keras.Model instance.

Returns:

ret – The new trainable tf.keras.Model instance.

ivy.stateful.converters.to_ivy_module(native_module=None, native_module_class=None, args=None, kwargs=None, device=None, devices=None, inplace_update=False)[source]#

Convert an instance of a trainable module from a native framework into a trainable ivy.Module instance.

Parameters:
  • native_module (default: None) – The module in the native framework to convert, required if native_module_class is not given. Default is None.

  • native_module_class (default: None) – The class of the native module, required if native_module is not given. Default is None.

  • args (default: None) – Positional arguments to pass to the native module class. Default is None.

  • kwargs (default: None) – Key-word arguments to pass to the native module class. Default is None.

  • device (default: None) – The device on which to create module variables. Default is None.

  • devices (default: None) – The devices on which to create module variables. Default is None.

  • inplace_update (default: False) – For backends with dedicated variable classes, whether to update these inplace. Default is False.

Returns:

ret – The new trainable ivy.Module instance.

This should have hopefully given you an overview of the converters submodule, if you have any questions, please feel free to reach out on our discord!