mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
This reverts commit c5f6b72041.
Reverted https://github.com/pytorch/pytorch/pull/133801 on behalf of https://github.com/ZainRizvi due to Sorry, but this breaks internal tests because of using functools ([comment](https://github.com/pytorch/pytorch/pull/133778#issuecomment-2310445169))
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
# Used to load and initialize polyfill handlers when importing torch._dynamo
|
|
# Please add a new import when adding a new polyfill module.
|
|
|
|
import importlib
|
|
from typing import Tuple, TYPE_CHECKING
|
|
|
|
from .. import polyfills, trace_rules
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
from types import ModuleType
|
|
|
|
|
|
POLYFILLED_MODULE_NAMES: Tuple[str, ...] = (
|
|
"builtins",
|
|
"functools",
|
|
"itertools",
|
|
)
|
|
POLYFILLED_MODULES: Tuple["ModuleType", ...] = tuple(
|
|
importlib.import_module(f".{submodule}", package=polyfills.__name__)
|
|
for submodule in POLYFILLED_MODULE_NAMES
|
|
)
|
|
|
|
|
|
# Unregister the builtin functions from _builtin_function_ids to let them to be
|
|
# dispatched with the appropriate VariableTracker type. Otherwise, they will be
|
|
# dispatched with BuiltinVariable if present in _builtin_function_ids.
|
|
for polyfill_module in POLYFILLED_MODULES:
|
|
for polyfill_name in polyfill_module.__all__:
|
|
polyfill_handler = getattr(polyfill_module, polyfill_name)
|
|
original_fn = polyfill_handler.__torch_dynamo_original__
|
|
trace_rules._builtin_function_ids.remove(id(original_fn))
|