Skip to content

Commit 6720e82

Browse files
authored
Use signature (*args, **kwargs) when signature is unavailable (#2542)
1 parent afa82d9 commit 6720e82

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

thunder/core/codeutils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,10 @@ def get_siginfo(fn: Callable, args, kwargs, *, _make_named_inputs: bool = False)
436436
fn_ = fn_.meta
437437

438438
# Binds args and kwargs to signature
439-
sig = inspect.signature(fn_)
439+
try:
440+
sig = inspect.signature(fn_)
441+
except ValueError:
442+
sig = inspect.signature(lambda *args, **kwargs: None)
440443
kwargs.update(partial_kwargs)
441444
ba = sig.bind(*args, **kwargs)
442445

thunder/tests/test_core.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,19 @@ def bar(__a, __b):
16201620
thunder.trace()(bar, a, b)
16211621

16221622

1623+
# Tests if Thunder can trace a function without a valid signature
1624+
@instantiate(dtypes=NOTHING)
1625+
def test_no_signature(executor, device, _):
1626+
a = make_tensor((2, 3), device=device, dtype=torch.float32)
1627+
1628+
fn_trace = thunder.trace()(getattr, a, "mT")
1629+
1630+
jfn = executor.make_callable(fn_trace)
1631+
actual = jfn(a, "mT")
1632+
expected = getattr(a, "mT")
1633+
assert_close(actual, expected)
1634+
1635+
16231636
@instantiate(dtypes=NOTHING)
16241637
def test_trace_args_no_name_collision(executor, device, _):
16251638
from thunder.core.trace import detached_trace

0 commit comments

Comments
 (0)