code: def _validate_module_type_keys_factory(supported_modules):
      supported_module_names = [
          cls.__name__ for cls in supported_modules
      ]
  
      def validate_module_type_key(instance, attribute, value):
          if isinstance(value, str):
              assert value in supported_module_names, (
                  f"keys for module_type_configs must be one of "
                  f"{supported_module_names}. Received: {value}."
              )
          else:
              assert value in supported_modules, (
                  f"keys for module_type_configs must be one of "
                  f"{supported_modules}. Received: {value}."
              )
  
      return validate_module_type_key
  
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 4 for calling a global function with example usage: _validate_module_type_keys_factory(supported_modules) and returns: validate_module_type_key