def get_class_in_module(class_name, module_path, pretrained_model_name_or_path=None):
    """
    Import a module on the cache directory for modules and extract a class from it.
    """
    module_path = module_path.replace(os.path.sep, ".")
    try:
        module = importlib.import_module(module_path)
    except ModuleNotFoundError as e:
        # This can happen when the repo id contains ".", which Python's import machinery interprets as a directory
        # separator. We do a bit of monkey patching to detect and fix this case.
        if not (
            pretrained_model_name_or_path is not None
            and "." in pretrained_model_name_or_path
            and module_path.startswith("diffusers_modules")
            and pretrained_model_name_or_path.replace("/", "--") in module_path
        ):
            raise e  # We can't figure this one out, just reraise the original error

        corrected_path = os.path.join(HF_MODULES_CACHE, module_path.replace(".", "/")) + ".py"
        corrected_path = corrected_path.replace(
            pretrained_model_name_or_path.replace("/", "--").replace(".", "/"),
            pretrained_model_name_or_path.replace("/", "--"),
        )
        module = importlib.machinery.SourceFileLoader(module_path, corrected_path).load_module()

    if class_name is None:
        return find_pipeline_class(module)
    return getattr(module, class_name)

    Import a module on the cache directory for modules and extract a class from it.
    
src/diffusers/utils/dynamic_modules_utils.py