Allow optional positional arguments for torch.func.functional_call (#134643)

This PR resolves #134408. Add an additional test and have passed the local test.

Do you think we should add a post-check to ensure `args` and `kwargs` are not both `None`? It seems to be possible to have modules without inputs.

This PR does not include any such post-check.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/134643
Approved by: https://github.com/zou3519
This commit is contained in:
whywhy-rtx3090
2024-09-12 15:22:06 +00:00
committed by PyTorch MergeBot
parent d67cc58181
commit 7647c398ff
3 changed files with 8 additions and 4 deletions

View File

@ -738,6 +738,8 @@ class TestStatelessFunctionalAPI(TestCase):
self.assertEqual(res, other_inp)
res_1 = functional_call(mod, a, (), {'inp': inp, 'other_inp': other_inp})
self.assertEqual(res, res_1)
res_2 = functional_call(mod, a, kwargs={'inp': inp, 'other_inp': other_inp})
self.assertEqual(res, res_2)
def test_functional_call_tuple_dicts(self):
mod = MockModule()