docstr: 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
      Haiku parameters to pass to the constructor of the native module.
      Default is ``None``.
  rng_seed
      Seed used to initialize haiku parameters is initializing from a class.
      Default is ``0``.
  constructor_args
      Positional arguments to pass to the constructor of the native module.
      Default is ``None``.
  constructor_kwargs
      Key-word arguments to pass to the constructor of the native module.
       Default is ``None``.
  instance_args
      Positional arguments to pass to the forward pass of the native module.
      Default is ``None``.
  instance_kwargs
      Key-word arguments to pass to the forward pass of the native module.
       Default is ``None``.
  device
      The device on which to create module variables. Default is ``None``.
  devices
      The devices on which to create module variables. Default is ``None``.
  
  Returns
  -------
  ret
      The new trainable torch module instance.
docstr_tok: ["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","Haiku","parameters","to","pass","to","the","constructor","of","the","native","module",".","Default","is","``","None","``",".","rng_seed","Seed","used","to","initialize","haiku","parameters","is","initializing","from","a","class",".","Default","is","``","0","``",".","constructor_args","Positional","arguments","to","pass","to","the","constructor","of","the","native","module",".","Default","is","``","None","``",".","constructor_kwargs","Key-word","arguments","to","pass","to","the","constructor","of","the","native","module",".","Default","is","``","None","``",".","instance_args","Positional","arguments","to","pass","to","the","forward","pass","of","the","native","module",".","Default","is","``","None","``",".","instance_kwargs","Key-word","arguments","to","pass","to","the","forward","pass","of","the","native","module",".","Default","is","``","None","``",".","device","The","device","on","which","to","create","module","variables",".","Default","is","``","None","``",".","devices","The","devices","on","which","to","create","module","variables",".","Default","is","``","None","``",".","Returns","--","--","--","-","ret","The","new","trainable","torch","module","instance","."]
code: def from_haiku_module(
      native_module,
      params_hk=None,
      rng_seed=0,
      constructor_args: Optional[List] = None,
      constructor_kwargs: Optional[Dict] = None,
      instance_args: Optional[List] = None,
      instance_kwargs: Optional[Dict] = None,
      device=None,
      devices=None,
  ):
      """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
          Haiku parameters to pass to the constructor of the native module.
          Default is ``None``.
      rng_seed
          Seed used to initialize haiku parameters is initializing from a class.
          Default is ``0``.
      constructor_args
          Positional arguments to pass to the constructor of the native module.
          Default is ``None``.
      constructor_kwargs
          Key-word arguments to pass to the constructor of the native module.
           Default is ``None``.
      instance_args
          Positional arguments to pass to the forward pass of the native module.
          Default is ``None``.
      instance_kwargs
          Key-word arguments to pass to the forward pass of the native module.
           Default is ``None``.
      device
          The device on which to create module variables. Default is ``None``.
      devices
          The devices on which to create module variables. Default is ``None``.
  
      Returns
      -------
      ret
          The new trainable torch module instance.
      """
      try:
          import haiku as hk
      except ModuleNotFoundError as exc:
          raise ModuleNotFoundError(
              "`haiku` was not found installed on your system. Please proceed "
              "to install it and restart your interpreter to see the changes."
          ) from exc
  
      try:
          from haiku._src.data_structures import FlatMapping  # noqa
      except (ImportError, AttributeError) as exc:
          raise ImportError(
              "Unable to import `FlatMapping` from `haiku`. Please check if the "
              "requested attribute exists."
          ) from exc
  
      c_args = ivy.default(constructor_args, [])
      c_kwargs = ivy.default(constructor_kwargs, {})
      i_args = ivy.default(instance_args, [])
      i_kwargs = ivy.default(instance_kwargs, {})
      i_args, i_kwargs = ivy.args_to_native(*i_args, **i_kwargs)
      transformed_module = native_module
  
      if inspect.isclass(native_module):
          if len(i_args) == 0 and len(i_kwargs) == 0:
              raise ivy.utils.exceptions.IvyException(
                  "both instance_args and instance_kwargs cannot be none"
                  " when passing a native class"
              )
  
          def forward_fn(*a, **kw):
              model = native_module(*c_args, **c_kwargs)
              return model(*i_args, **i_kwargs)
  
          transformed_module = hk.transform(forward_fn)
          params_hk = transformed_module.init(
              rng_seed, *i_args, **i_kwargs
          )
      from ivy.stateful.module import _HaikuIvyModule
  
      return _HaikuIvyModule(
          *i_args,
          params_hk=params_hk,
          native_module=transformed_module,
          device=device,
          devices=devices,
          **i_kwargs,
      )
  
file_path: ivy/ivy/stateful/converters.py
imports: import functools
  from typing import Optional, Dict, List
  import re
  import inspect
  import ivy
  from ivy.utils.backend import current_backend
label_desc: Use image node_id 1 for calling the ModuleConverters obj's underlying member method code with example usage: obj.from_haiku_module(native_module, params_hk, rng_seed, constructor_args, constructor_kwargs, instance_args, instance_kwargs, device, devices) and returns: _HaikuIvyModule, model