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 isNone
.rng_seed (default:
0
) – Seed used to initialize flax parameters is initializing from a class. Default is0
.constructor_args (
Optional
[List
], default:None
) – Positional arguments to pass to the constructor of the native module. Default isNone
.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 isNone
.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 isNone
.devices (default:
None
) – The devices on which to create module variables. Default isNone
.
- 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 isNone
.rng_seed (default:
0
) – Seed used to initialize haiku parameters is initializing from a class. Default is0
.constructor_args (
Optional
[List
], default:None
) – Positional arguments to pass to the constructor of the native module. Default isNone
.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 isNone
.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 isNone
.devices (default:
None
) – The devices on which to create module variables. Default isNone
.
- 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 isNone
.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 isNone
.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 isNone
.devices (default:
None
) – The devices on which to create module variables. Default isNone
.
- 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 isNone
.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 isNone
.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 isNone
.devices (default:
None
) – The devices on which to create module variables. Default isNone
.
- 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 isNone
.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 isNone
.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 isNone
.devices (default:
None
) – The devices on which to create module variables. Default isNone
.inplace_update (default:
False
) – For backends with dedicated variable classes, whether to update these inplace. Default isFalse
.
- Returns:
ret – The new trainable ivy.Module 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 isNone
.native_module_class (default:
None
) – The class of the native module, required if native_module is not given. Default isNone
.args (default:
None
) – Positional arguments to pass to the native module class. Default isNone
.kwargs (default:
None
) – Key-word arguments to pass to the native module class. Default isNone
.device (default:
None
) – The device on which to create module variables. Default isNone
.devices (default:
None
) – The devices on which to create module variables. Default isNone
.inplace_update (default:
False
) – For backends with dedicated variable classes, whether to update these inplace. Default isFalse
.
- 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!