pytorch
a583b9cd - Fixing "naive" `forward` of `ModuleList` and `ModuleDict (#48785)

Commit
3 years ago
Fixing "naive" `forward` of `ModuleList` and `ModuleDict (#48785) Summary: **Goal:** Making sure "calling"/"forwarding" a `ModuleList` or `ModuleDict` produce the intended `NotImpmentedError`. **Current behavior:** Currently, when naively calling `forward` user ends up with the confusing error message: ```python TypeError: forward() takes 1 positional argument but 2 were given ``` Instead of the intended `NotImplementedError.` This minor issue was brought up by vadimkantorov in issue https://github.com/pytorch/pytorch/issues/37718 [here][1], also by a confused stackoverflow user [here][2]. **What this PR includes:** Remove `forward` altogether from `ModuleList` and `ModuleDict` to fall back on the `_forward_unimplemented` of `Module` that properly throws `NotImplementedError` regardless of input arguments. Appropriate test was added to `test_nn.py` Fixes previous PR https://github.com/pytorch/pytorch/issues/48698 and PR https://github.com/pytorch/pytorch/issues/48783 (third time's a charm? I'm really sorry for the mess) Test added according to ngimel [request][3]. [1]: https://github.com/pytorch/pytorch/issues/37718#issuecomment-736333345 [2]: https://stackoverflow.com/q/65096679/1714410 [3]: https://github.com/pytorch/pytorch/pull/48698#issuecomment-737398693 Pull Request resolved: https://github.com/pytorch/pytorch/pull/48785 Reviewed By: zhangguanheng66 Differential Revision: D25359759 Pulled By: jbschlosser fbshipit-source-id: 28f82386f2e9a2a9b0b0b81b16dba6b79398bd34
Author
Parents
Loading