Skip to content

Dev #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 22, 2024
Merged

Dev #57

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions src/nnsight/pydantics/format/functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import operator
from inspect import getmembers, isbuiltin, isfunction, ismethoddescriptor
from inspect import (getmembers, isbuiltin, isfunction, ismethod,
ismethoddescriptor)

import einops
import torch
@@ -8,11 +9,19 @@
from ...tracing.Proxy import Proxy


def get_function_name(fn):
def get_function_name(fn, module_name=None):
if isinstance(fn, str):
return fn

return f"{getattr(fn, '__module__', '')}.{fn.__qualname__}"
if module_name is not None:
return f"{module_name}.{fn.__name__}"

module_name = getattr(fn, "__module__", None)

if module_name is None:
return fn.__qualname__

return f"{module_name}.{fn.__qualname__}"


FUNCTIONS_WHITELIST = {}
@@ -30,8 +39,8 @@ def get_function_name(fn):
)
FUNCTIONS_WHITELIST.update(
{
get_function_name(value): value
for key, value in getmembers(torch._C._TensorBase, ismethoddescriptor)
get_function_name(value, module_name="Tensor"): value
for key, value in getmembers(torch.Tensor, ismethoddescriptor)
}
)
FUNCTIONS_WHITELIST.update(