mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Signed-off-by: Edward Z. Yang <ezyangfb.com> Pull Request resolved: https://github.com/pytorch/pytorch/pull/76089 Approved by: https://github.com/albanD
13 lines
351 B
Python
13 lines
351 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)
|
|
module = importlib.util.module_from_spec(spec)
|
|
cast(Loader, spec.loader).exec_module(module)
|
|
return module
|