{"action":"created","issue":{"url":"https://api.github.com/repos/torch/nn/issues/526","labels_url":"https://api.github.com/repos/torch/nn/issues/526/labels{/name}","comments_url":"https://api.github.com/repos/torch/nn/issues/526/comments","events_url":"https://api.github.com/repos/torch/nn/issues/526/events","html_url":"https://github.com/torch/nn/pull/526","id":121936452,"number":526,"title":"clearState","user":{"login":"szagoruyko","id":4953728,"avatar_url":"https://avatars.githubusercontent.com/u/4953728?v=3","gravatar_id":"","url":"https://api.github.com/users/szagoruyko","html_url":"https://github.com/szagoruyko","followers_url":"https://api.github.com/users/szagoruyko/followers","following_url":"https://api.github.com/users/szagoruyko/following{/other_user}","gists_url":"https://api.github.com/users/szagoruyko/gists{/gist_id}","starred_url":"https://api.github.com/users/szagoruyko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szagoruyko/subscriptions","organizations_url":"https://api.github.com/users/szagoruyko/orgs","repos_url":"https://api.github.com/users/szagoruyko/repos","events_url":"https://api.github.com/users/szagoruyko/events{/privacy}","received_events_url":"https://api.github.com/users/szagoruyko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-12-13T18:52:28Z","updated_at":"2016-01-06T12:31:02Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/torch/nn/pulls/526","html_url":"https://github.com/torch/nn/pull/526","diff_url":"https://github.com/torch/nn/pull/526.diff","patch_url":"https://github.com/torch/nn/pull/526.patch"},"body":"This introduces sanitization of nn modules so that\r\n```lua\r\ntorch.save('model.t7', model:clearState())\r\n```\r\nwill save a model without any internal buffers.\r\n`nn.Module` has it's default clearState that clears `output` and `gradInput`.\r\nAny module that uses buffers should have it's own clearState, I went over nn modules and fixed the ones I knew, it is possible that I missed something.\r\n\r\nTest added into `Jacobian.testIO` that calls clearState before serializing the module. There might be a better solution because it does not test the old behaviour.\r\n\r\nI will add `clearState` to `cudnn`, `inn` and nn.DataParallelTable with `cunn` tests later.\r\n\r\nComments? the original name was `sanitize`, we should discuss if the new name is better.\r\n\r\nWas implemented when I was at facebook, it's been in use for a couple of months, pretty stable."},"comment":{"url":"https://api.github.com/repos/torch/nn/issues/comments/169313470","html_url":"https://github.com/torch/nn/pull/526#issuecomment-169313470","issue_url":"https://api.github.com/repos/torch/nn/issues/526","id":169313470,"user":{"login":"hughperkins","id":123560,"avatar_url":"https://avatars.githubusercontent.com/u/123560?v=3","gravatar_id":"","url":"https://api.github.com/users/hughperkins","html_url":"https://github.com/hughperkins","followers_url":"https://api.github.com/users/hughperkins/followers","following_url":"https://api.github.com/users/hughperkins/following{/other_user}","gists_url":"https://api.github.com/users/hughperkins/gists{/gist_id}","starred_url":"https://api.github.com/users/hughperkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hughperkins/subscriptions","organizations_url":"https://api.github.com/users/hughperkins/orgs","repos_url":"https://api.github.com/users/hughperkins/repos","events_url":"https://api.github.com/users/hughperkins/events{/privacy}","received_events_url":"https://api.github.com/users/hughperkins/received_events","type":"User","site_admin":false},"created_at":"2016-01-06T12:31:02Z","updated_at":"2016-01-06T12:31:02Z","body":"(By the way, if anyone is wondering, why would one ever want to clear the weights? well... in [char-rnn-er](https://github.com/hughperkins/char-rnn-er), I'm [saving the current network](https://github.com/hughperkins/char-rnn-er/blob/364de5e6486bf1eb2c88a03ecf5eb79be12f70f9/train.lua#L366-L372) , and in order to avoid going down the rabbit hole of figuring out how to [convert between saved cuda-network, cpu-network, cl-network](https://github.com/karpathy/char-rnn/issues/35) , so I save in two parts:\r\n- network architecture, ie how many hidden layers, size of each layer.  Essentially this could be saved as the network, without buffers, and also without weights, though I'm simply saving the network sizes for now, [define netParams](https://github.com/hughperkins/char-rnn-er/blob/364de5e6486bf1eb2c88a03ecf5eb79be12f70f9/train.lua#L93) , [store them](https://github.com/hughperkins/char-rnn-er/blob/364de5e6486bf1eb2c88a03ecf5eb79be12f70f9/train.lua#L368)\r\n- the weights themselves, which I simply clone to Floats, then write to disk [get params](https://github.com/hughperkins/char-rnn-er/blob/364de5e6486bf1eb2c88a03ecf5eb79be12f70f9/train.lua#L216) [store params](https://github.com/hughperkins/char-rnn-er/blob/364de5e6486bf1eb2c88a03ecf5eb79be12f70f9/train.lua#L369)\r\n\r\nThe first part, saving the network architecture, could plausibly be accomplished by saving the class structure of the network, including the module hyper-parameters (size of each Linear for example), but with neither weights nor buffers (nor hidden state, in case of LSTM module).\r\n)"}}