Repository: pytorch
Issue: nn.modules.functional.h does not support optional arguments
Labels: module: cpp,module: nn,triaged

## 🐛 Bug

FunctionalImpl binds a function one-to-one with its' arguments and does not allow to add new optional argument. If you add not-optional argument, it will break BC.

## To Reproduce

Steps to reproduce the behavior:

1. I changed signature of avg_pool2d method, added optional argument 
2. Got failure:
```
Jun 19 19:06:25 /opt/conda/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/pimpl.h:66:41:   required from 'torch::nn::ModuleHolder<Contained>::ModuleHolder(Head&&, Tail&& ...) [with Head = at::Tensor (&)(const at::Tensor&, c10::ArrayRef<long int>, c10::ArrayRef<long int>, c10::ArrayRef<long int>, bool, bool, c10::optional<long int>); Tail = {int, int, int, bool, bool}; <template-parameter-2-3> = void; Contained = torch::nn::FunctionalImpl]'
Jun 19 19:06:25 /opt/conda/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/modules/functional.h:101:1:   required from here
Jun 19 19:06:25 /usr/include/c++/5/functional:1410:7: error: static assertion failed: Wrong number of arguments for function
Jun 19 19:06:25        static_assert(sizeof...(_BoundArgs) == sizeof...(_Args),
Jun 19 19:06:25        ^
Jun 19 19:06:25 In file included from /opt/conda/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/modules.h:8:0,
Jun 19 19:06:25                  from /opt/conda/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn.h:6,
Jun 19 19:06:25                  from /opt/conda/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/all.h:6,
Jun 19 19:06:25                  from /opt/conda/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/torch.h:3,
Jun 19 19:06:25                  from /var/lib/jenkins/workspace/vision/torchvision/csrc/models/densenet.h:4,
Jun 19 19:06:25                  from /var/lib/jenkins/workspace/vision/torchvision/csrc/models/densenet.cpp:1:
Jun 19 19:06:25 /opt/conda/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/modules/functional.h: In instantiation of 'torch::nn::FunctionalImpl::FunctionalImpl(SomeFunction, Args&& ...) [with SomeFunction = at::Tensor (*)(const at::Tensor&, c10::ArrayRef<long int>, c10::ArrayRef<long int>, c10::ArrayRef<long int>, bool, bool, c10::optional<long int>); Args = {int, int, int, bool, bool}; <template-parameter-1-3> = void]':
Jun 19 19:06:25 /opt/conda/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/pimpl.h:66:41:   required from 'torch::nn::ModuleHolder<Contained>::ModuleHolder(Head&&, Tail&& ...) [with Head = at::Tensor (&)(const at::Tensor&, c10::ArrayRef<long int>, c10::ArrayRef<long int>, c10::ArrayRef<long int>, bool, bool, c10::optional<long int>); Tail = {int, int, int, bool, bool}; <template-parameter-2-3> = void; Contained = torch::nn::FunctionalImpl]'
Jun 19 19:06:25 /opt/conda/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/modules/functional.h:101:1:   required from here
Jun 19 19:06:25 /opt/conda/lib/python3.6/site-packages/torch/include/torch/csrc/api/include/torch/nn/modules/functional.h:73:41: error: no matching function for call to 'std::function<at::Tensor(at::Tensor)>::function(std::_Bind_helper<false, at::Tensor (*&)(const at::Tensor&, c10::ArrayRef<long int>, c10::ArrayRef<long int>, c10::ArrayRef<long int>, bool, bool, c10::optional<long int>), const std::_Placeholder<1>&, int, int, int, bool, bool>::type)'
Jun 19 19:06:25              std::forward<Args>(args)...)) {
```

## Expected behavior

Should allow to add optional arguments to the function and should not break BC.