[BE][dynamo] reorganize polyfill module hierarchy (#133977)

Changes:

1. Move `polyfill.py` -> `polyfills/__init__.py`. It can be used as `polyfill.xxx` -> `polyfills.xxx`.
2. Move submodule loading from `polyfills/__init__.py` to `polyfills/loader.py`.

Merge `polyfill.py` and `polyfills/` packages. Each polyfill module have its own namespace for better code organization.

The ultimate goal is make `polyfills/__init__.py` empty and all polyfill functions move to its own namespace.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/133977
Approved by: https://github.com/jansel
This commit is contained in:
Xuehai Pan
2024-08-22 22:54:31 +08:00
committed by PyTorch MergeBot
parent c95ddd4bf2
commit b6abac68ec
12 changed files with 66 additions and 28 deletions

View File

@ -4,7 +4,7 @@ import itertools
import operator
from typing import Dict, List, Optional, TYPE_CHECKING
from .. import polyfill, variables
from .. import polyfills, variables
from ..exc import (
handle_observed_exception,
ObservedUserStopIteration,
@ -178,7 +178,7 @@ class ItertoolsVariable(VariableTracker):
from .builder import SourcelessBuilder
return tx.inline_user_function_return(
SourcelessBuilder.create(tx, polyfill.islice), args, kwargs
SourcelessBuilder.create(tx, polyfills.islice), args, kwargs
)
elif self.value is itertools.repeat:
if len(args) < 2:
@ -189,18 +189,18 @@ class ItertoolsVariable(VariableTracker):
from .builder import SourcelessBuilder
return tx.inline_user_function_return(
SourcelessBuilder.create(tx, polyfill.repeat), args, kwargs
SourcelessBuilder.create(tx, polyfills.repeat), args, kwargs
)
elif self.value is itertools.count:
return variables.CountIteratorVariable(*args, mutable_local=MutableLocal())
elif self.value is itertools.cycle:
return variables.CycleIteratorVariable(*args, mutable_local=MutableLocal())
elif self.value is itertools.dropwhile:
return variables.UserFunctionVariable(polyfill.dropwhile).call_function(
return variables.UserFunctionVariable(polyfills.dropwhile).call_function(
tx, args, kwargs
)
elif self.value is itertools.zip_longest:
return variables.UserFunctionVariable(polyfill.zip_longest).call_function(
return variables.UserFunctionVariable(polyfills.zip_longest).call_function(
tx, args, kwargs
)
else: