{"action":"closed","issue":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/5022","repository_url":"https://api.github.com/repos/pytorch/pytorch","labels_url":"https://api.github.com/repos/pytorch/pytorch/issues/5022/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/5022/comments","events_url":"https://api.github.com/repos/pytorch/pytorch/issues/5022/events","html_url":"https://github.com/pytorch/pytorch/issues/5022","id":294021873,"number":5022,"title":"RuntimeError: hook 'hookFunc' has returned an incorrect number of values (got 1, but expected 4)","user":{"login":"tstandley","id":17170654,"avatar_url":"https://avatars2.githubusercontent.com/u/17170654?v=4","gravatar_id":"","url":"https://api.github.com/users/tstandley","html_url":"https://github.com/tstandley","followers_url":"https://api.github.com/users/tstandley/followers","following_url":"https://api.github.com/users/tstandley/following{/other_user}","gists_url":"https://api.github.com/users/tstandley/gists{/gist_id}","starred_url":"https://api.github.com/users/tstandley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tstandley/subscriptions","organizations_url":"https://api.github.com/users/tstandley/orgs","repos_url":"https://api.github.com/users/tstandley/repos","events_url":"https://api.github.com/users/tstandley/events{/privacy}","received_events_url":"https://api.github.com/users/tstandley/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-02-02T21:00:44Z","updated_at":"2018-02-06T18:16:58Z","closed_at":"2018-02-06T18:16:58Z","author_association":"NONE","body":"I'm having trouble with module.register_backward_hook(), and I think it might be a bug.\r\nHere's the relevant code:\r\n```\r\ndef instrument_model(model,fraction_list):\r\n    def register_hook(module):\r\n        def hookFunc(module, gradInput, gradOutput):\r\n            \r\n            if isinstance(gradOutput, tuple):\r\n                print(len(gradOutput))\r\n                for i in gradOutput:\r\n                    print(i.size())\r\n                ret = tuple([torch.zeros(g.size()) for g in gradOutput])\r\n                print(len(ret))\r\n                for i in ret:\r\n                    print(i.size())\r\n            else:\r\n                print(gradOutput.size())\r\n                ret = torch.zeros(gradOutput.size())\r\n                print(ret.size())\r\n            return ret\r\n            \r\n            \r\n            \r\n\r\n        module.register_backward_hook(hookFunc)\r\n    model.apply(register_hook)\r\n```\r\n\r\nFor which I get the following error:\r\n\r\n`RuntimeError: hook 'hookFunc' has returned an incorrect number of values (got 1, but expected 4)`\r\n\r\nThe print statements have confirmed that `ret` matches the shape of `gradInput` in both length of the tuple and size of all constituents.\r\n\r\nIdeally, this would set all gradients to zero.\r\n\r\nAny idea what's going on?\r\n"}}
{"actor":{"display_login":"apaszke"}}