{"action":"created","issue":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/5958","repository_url":"https://api.github.com/repos/pytorch/pytorch","labels_url":"https://api.github.com/repos/pytorch/pytorch/issues/5958/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/5958/comments","events_url":"https://api.github.com/repos/pytorch/pytorch/issues/5958/events","html_url":"https://github.com/pytorch/pytorch/issues/5958","id":307993060,"number":5958,"title":"How can I access the model's attribution created during forward pass when using dataparallel?","user":{"login":"sonack","id":12935189,"avatar_url":"https://avatars1.githubusercontent.com/u/12935189?v=4","gravatar_id":"","url":"https://api.github.com/users/sonack","html_url":"https://github.com/sonack","followers_url":"https://api.github.com/users/sonack/followers","following_url":"https://api.github.com/users/sonack/following{/other_user}","gists_url":"https://api.github.com/users/sonack/gists{/gist_id}","starred_url":"https://api.github.com/users/sonack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sonack/subscriptions","organizations_url":"https://api.github.com/users/sonack/orgs","repos_url":"https://api.github.com/users/sonack/repos","events_url":"https://api.github.com/users/sonack/events{/privacy}","received_events_url":"https://api.github.com/users/sonack/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-03-23T11:28:16Z","updated_at":"2018-03-23T15:53:37Z","closed_at":null,"author_association":"NONE","body":"For example, I have such a forward function():\r\n\r\n```python\r\n\r\ndef forward(self, x):\r\n    mgdata = self.encoder(x)\r\n    self.imp_mask_sigmoid = self.impmap_sigmoid(mgdata)\r\n    self.imp_mask = self.impmap_expand(self.imp_mask_sigmoid)\r\n    enc_data = mgdata * self.imp_mask\r\n    dec_data = self.decoder(enc_data)\r\n    return dec_data\r\n```\r\n\r\nWhen I using dataparallel, I always using `model.module` to access the wrapped original model.However, I found I can't access `model.module.imp_mask_sigmoid`, it will complain about `AttributeError: 'ContentWeightedCNN' object has no attribute 'imp_mask_sigmoid'`.\r\nHow to deal with it?\r\n\r\nThanks very much."},"comment":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/comments/375711646","html_url":"https://github.com/pytorch/pytorch/issues/5958#issuecomment-375711646","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/5958","id":375711646,"user":{"login":"Erotemic","id":3186211,"avatar_url":"https://avatars3.githubusercontent.com/u/3186211?v=4","gravatar_id":"","url":"https://api.github.com/users/Erotemic","html_url":"https://github.com/Erotemic","followers_url":"https://api.github.com/users/Erotemic/followers","following_url":"https://api.github.com/users/Erotemic/following{/other_user}","gists_url":"https://api.github.com/users/Erotemic/gists{/gist_id}","starred_url":"https://api.github.com/users/Erotemic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Erotemic/subscriptions","organizations_url":"https://api.github.com/users/Erotemic/orgs","repos_url":"https://api.github.com/users/Erotemic/repos","events_url":"https://api.github.com/users/Erotemic/events{/privacy}","received_events_url":"https://api.github.com/users/Erotemic/received_events","type":"User","site_admin":false},"created_at":"2018-03-23T15:53:37Z","updated_at":"2018-03-23T15:53:37Z","author_association":"CONTRIBUTOR","body":"Returning what you want from the top-level forward function should defiantly work. You could do this pretty easily with an additional wrapper. As such:\r\n\r\n```python\r\n\r\nclass NormalModel(nn.Module):\r\n    pass\r\n\r\nclass ExtraOutputWrapper(nn.Module):\r\n   def __init__(self, *args, **kw):\r\n       self.wrapped = NormalModel(*args, **kw)\r\n\r\n    def forward(self, input):\r\n        normal_output = self.wrapped(input)\r\n        extra_output = self.wrapped.layer_of_interest.property\r\n        return normal_output, extra_output\r\n```\r\n\r\nThen wrap `ExtraOutputWrapper` with `DataParallel` and it will return the property of interest.  This seems fairly clean to me. Is there an issue with this?"}}
{"actor":{"display_login":"Erotemic"}}