code: def _structure_from_dict_hook_factory(
      conversion_cls: _Any,
  ) -> _Callable:
      def _structure_from_dict_hook(
          module_type_dict: _Dict[_Union[_Callable, str], _Any],
          type: _Any,
      ):
          return_dict = _OrderedDict()
          for key, value in module_type_dict.items():
              if value is None:
                  return_dict[key] = None
              else:
                  if isinstance(value, dict):
                      return_dict[key] = conversion_cls.from_dict(value)
                  else:
                      assert isinstance(value, conversion_cls), (
                          "value in module type dict should be either a dict or "
                          "a module config object."
                      )
                      return_dict[key] = value
          return return_dict
  
      return _structure_from_dict_hook
  
imports: from collections import OrderedDict
  from typing import IO
  from typing import Any
  from typing import Callable
  from typing import Dict
  from typing import List
  from typing import Optional
  from typing import Type
  from typing import Union
  import cattrs
  import torch
  import yaml
  from attr import Factory
  from attr import asdict
  from attr import define
label_desc: Use image node_id 1 for calling a global function with example usage: _structure_from_dict_hook_factory(conversion_cls) and returns: _structure_from_dict_hook, return_dict