Skip to content

Commit

Permalink
Add helper function to replace whitelisted functions
Browse files Browse the repository at this point in the history
  • Loading branch information
JadenFiotto-Kaufman committed Sep 22, 2024
1 parent 47758d6 commit e0c2e2e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/nnsight/schema/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, ismethod, ismethoddescriptor, isclass
from typing import Callable

import einops
import torch
Expand All @@ -24,6 +25,15 @@ def get_function_name(fn, module_name=None):

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

def update_function(function: str | Callable, new_function: Callable):

if not isinstance(function, str):

function = get_function_name(function)

new_function.__name__ = function

FUNCTIONS_WHITELIST[function] = new_function

FUNCTIONS_WHITELIST = {}

Expand Down

0 comments on commit e0c2e2e

Please sign in to comment.