{"action":"created","issue":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/3232","repository_url":"https://api.github.com/repos/pytorch/pytorch","labels_url":"https://api.github.com/repos/pytorch/pytorch/issues/3232/labels{/name}","comments_url":"https://api.github.com/repos/pytorch/pytorch/issues/3232/comments","events_url":"https://api.github.com/repos/pytorch/pytorch/issues/3232/events","html_url":"https://github.com/pytorch/pytorch/issues/3232","id":267630902,"number":3232,"title":"nn.Module.register_buffer() broken","user":{"login":"loudinthecloud","id":3178431,"avatar_url":"https://avatars1.githubusercontent.com/u/3178431?v=4","gravatar_id":"","url":"https://api.github.com/users/loudinthecloud","html_url":"https://github.com/loudinthecloud","followers_url":"https://api.github.com/users/loudinthecloud/followers","following_url":"https://api.github.com/users/loudinthecloud/following{/other_user}","gists_url":"https://api.github.com/users/loudinthecloud/gists{/gist_id}","starred_url":"https://api.github.com/users/loudinthecloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/loudinthecloud/subscriptions","organizations_url":"https://api.github.com/users/loudinthecloud/orgs","repos_url":"https://api.github.com/users/loudinthecloud/repos","events_url":"https://api.github.com/users/loudinthecloud/events{/privacy}","received_events_url":"https://api.github.com/users/loudinthecloud/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-10-23T11:21:29Z","updated_at":"2017-10-23T16:15:03Z","closed_at":null,"author_association":"NONE","body":"The following script fails to register a buffer -\r\n\r\n```python\r\nimport torch\r\nfrom torch import nn\r\nfrom torch.autograd import Variable\r\n\r\nclass Model(nn.Module):\r\n    def __init__(self):\r\n        super(Model, self).__init__()\r\n        self.blah = Variable(torch.Tensor(10, 10))\r\n        print(self._buffers)\r\n        self.register_buffer('blah', self.blah.data)\r\n\r\nnet = Model()\r\n```\r\n\r\nThis is the output:\r\n```\r\nOrderedDict()\r\n---------------------------------------------------------------------------\r\nKeyError                                  Traceback (most recent call last)\r\n<ipython-input-175-a6c6e417abc2> in <module>()\r\n     10         self.register_buffer('blah', self.blah)\r\n     11 \r\n---> 12 net = Model()\r\n\r\n<ipython-input-175-a6c6e417abc2> in __init__(self)\r\n      8         self.blah = Variable(torch.Tensor(10, 10))\r\n      9         print(self._buffers)\r\n---> 10         self.register_buffer('blah', self.blah)\r\n     11 \r\n     12 net = Model()\r\n\r\ntorch/nn/modules/module.py in register_buffer(self, name, tensor)\r\n     78         \"\"\"\r\n     79         if hasattr(self, name) and name not in self._buffers:\r\n---> 80             raise KeyError(\"attribute '{}' already exists\".format(name))\r\n     81 \r\n     82         self._buffers[name] = tensor\r\n\r\nKeyError: \"attribute 'blah' already exists\"\r\n```"},"comment":{"url":"https://api.github.com/repos/pytorch/pytorch/issues/comments/338712809","html_url":"https://github.com/pytorch/pytorch/issues/3232#issuecomment-338712809","issue_url":"https://api.github.com/repos/pytorch/pytorch/issues/3232","id":338712809,"user":{"login":"colesbury","id":655866,"avatar_url":"https://avatars1.githubusercontent.com/u/655866?v=4","gravatar_id":"","url":"https://api.github.com/users/colesbury","html_url":"https://github.com/colesbury","followers_url":"https://api.github.com/users/colesbury/followers","following_url":"https://api.github.com/users/colesbury/following{/other_user}","gists_url":"https://api.github.com/users/colesbury/gists{/gist_id}","starred_url":"https://api.github.com/users/colesbury/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colesbury/subscriptions","organizations_url":"https://api.github.com/users/colesbury/orgs","repos_url":"https://api.github.com/users/colesbury/repos","events_url":"https://api.github.com/users/colesbury/events{/privacy}","received_events_url":"https://api.github.com/users/colesbury/received_events","type":"User","site_admin":false},"created_at":"2017-10-23T16:15:03Z","updated_at":"2017-10-23T16:15:03Z","author_association":"OWNER","body":"This is the expected behavior: `register_buffer` adds a new attribute."}}
{"actor":{"display_login":"colesbury"}}