-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add einops and torch.nn.functional to both function whitelist, and pr…
…oxy wrapped einops (and subsequent changes to make work)
- Loading branch information
1 parent
2631325
commit 2961a04
Showing
6 changed files
with
55 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .functions import FUNCTIONS_WHITELIST | ||
from .functions import FUNCTIONS_WHITELIST, get_function_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,60 @@ | ||
import operator | ||
from inspect import getmembers, isbuiltin, ismethoddescriptor | ||
from inspect import getmembers, isbuiltin, isfunction, ismethoddescriptor | ||
|
||
import einops | ||
import torch | ||
|
||
from ... import util | ||
from ...tracing.Proxy import Proxy | ||
|
||
|
||
def get_function_name(fn): | ||
if isinstance(fn, str): | ||
return fn | ||
|
||
return f"{getattr(fn, '__module__', '')}.{fn.__qualname__}" | ||
|
||
|
||
FUNCTIONS_WHITELIST = {} | ||
FUNCTIONS_WHITELIST.update( | ||
{ | ||
f"_VariableFunctionsClass.{key}": value | ||
get_function_name(value): value | ||
for key, value in getmembers(torch._C._VariableFunctions, isbuiltin) | ||
} | ||
) | ||
FUNCTIONS_WHITELIST.update( | ||
{ | ||
f"Tensor.{key}": value | ||
get_function_name(value): value | ||
for key, value in getmembers(torch.nn.functional, isfunction) | ||
} | ||
) | ||
FUNCTIONS_WHITELIST.update( | ||
{ | ||
get_function_name(value): value | ||
for key, value in getmembers(torch._C._TensorBase, ismethoddescriptor) | ||
} | ||
) | ||
FUNCTIONS_WHITELIST.update( | ||
{ | ||
f"{key}": value | ||
get_function_name(value): value | ||
for key, value in getmembers(operator, isbuiltin) | ||
if not key.startswith("_") | ||
} | ||
) | ||
FUNCTIONS_WHITELIST.update( | ||
{ | ||
get_function_name(value): value | ||
for key, value in getmembers(einops.einops, isfunction) | ||
} | ||
) | ||
FUNCTIONS_WHITELIST.update( | ||
{ | ||
"null": "null", | ||
"module": "module", | ||
"argument": "argument", | ||
"swp": "swp", | ||
"grad": "grad", | ||
"fetch_attr": util.fetch_attr, | ||
"Proxy.proxy_call": Proxy.proxy_call, | ||
get_function_name(util.fetch_attr): util.fetch_attr, | ||
get_function_name(Proxy.proxy_call): Proxy.proxy_call, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters