From c63c90a0722d841a3f509a37240ce43863beb7fe Mon Sep 17 00:00:00 2001 From: James Reed Date: Wed, 21 Oct 2020 17:31:12 -0700 Subject: [PATCH] Update on "[FX] Make wrapped functions traceable" This patch does two things: 1. For the purpose of introspecting arguments, this patch adds a call to `inspect.unwrap` to unwrap any layers of `functools.wraps` decorators on the function. This is similar to what `inspect.signature` is doing as well. This allows for functions/methods with wrapping decorators applied to them to be traced 2. Fixes a poor error message where a variadic method without an explicit `self` argument was trying to be traced. I elected to just throw in this case for now. Conceptually we could support this but I was running into some weird correctness issues and I think that's better addressed in a follow-up PR. Closes https://github.com/pytorch/pytorch/issues/46665 Differential Revision: [D24465958](https://our.internmc.facebook.com/intern/diff/D24465958) [ghstack-poisoned] --- test/test_fx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_fx.py b/test/test_fx.py index 3ab3023bc73c..b5d03a86a177 100644 --- a/test/test_fx.py +++ b/test/test_fx.py @@ -117,12 +117,12 @@ def forward(self, *args, **kwargs): def test_args_kwargs_no_self(self): class T(torch.nn.Module): - def forward(*args, **kwargs): + def forward(*args, **kwargs): # noqa: B902 self = args[0] return torch.relu(args[1]) t = T() - with self.assertRaisesRegex(RuntimeError, 'cannot be part of \*args expansion'): + with self.assertRaisesRegex(RuntimeError, r'cannot be part of \*args expansion'): self.checkGraphModule(t, (torch.rand(1), torch.rand(1)), {'foo': torch.rand(1)}) def test_fx_shifts(self):