xref: /aosp_15_r20/external/pytorch/tools/shared/module_loader.py (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1from importlib.abc import Loader
2from types import ModuleType
3from typing import cast
4
5
6def import_module(name: str, path: str) -> ModuleType:
7    import importlib.util
8
9    spec = importlib.util.spec_from_file_location(name, path)
10    assert spec is not None
11    module = importlib.util.module_from_spec(spec)
12    cast(Loader, spec.loader).exec_module(module)
13    return module
14