mirror of
https://github.com/pytorch/pytorch.git
synced 2026-11-20 09:04:25 +08:00
3367575bee
Pull Request resolved: https://github.com/pytorch/pytorch/pull/173827 Approved by: https://github.com/soulitzer ghstack dependencies: #173813, #173814, #173825
15 lines
448 B
Python
15 lines
448 B
Python
from importlib.abc import Loader
|
|
from types import ModuleType
|
|
from typing import cast
|
|
|
|
|
|
def import_module(name: str, path: str) -> ModuleType:
|
|
import importlib.util
|
|
|
|
spec = importlib.util.spec_from_file_location(name, path)
|
|
if spec is None:
|
|
raise AssertionError(f"Failed to load spec for {name} from {path}")
|
|
module = importlib.util.module_from_spec(spec)
|
|
cast(Loader, spec.loader).exec_module(module)
|
|
return module
|