GitHub PullRequestEvent at 2014-03-17 12:01:46
Repository: torch7
Actor: timharley
Payload: {"action":"opened","number":18,"pull_request":{"url":"https://api.github.com/repos/torch/torch7/pulls/18","id":13630738,"html_url":"https://github.com/torch/torch7/pull/18","diff_url":"https://github.com/torch/torch7/pull/18.diff","patch_url":"https://github.com/torch/torch7/pull/18.patch","issue_url":"https://api.github.com/repos/torch/torch7/issues/18","number":18,"state":"open","title":"Make luaT_classmodulename, THError & THArgCheck threadsafe","user":{"login":"timharley","id":4367998,"avatar_url":"https://gravatar.com/avatar/7a9abef843f730e6b4eab7331ed1ead3?d=https%3A%2F%2Fidenticons.github.com%2F4af115d2d1d39cbe4388885d42a42fcf.png&r=x","gravatar_id":"7a9abef843f730e6b4eab7331ed1ead3","url":"https://api.github.com/users/timharley","html_url":"https://github.com/timharley","followers_url":"https://api.github.com/users/timharley/followers","following_url":"https://api.github.com/users/timharley/following{/other_user}","gists_url":"https://api.github.com/users/timharley/gists{/gist_id}","starred_url":"https://api.github.com/users/timharley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timharley/subscriptions","organizations_url":"https://api.github.com/users/timharley/orgs","repos_url":"https://api.github.com/users/timharley/repos","events_url":"https://api.github.com/users/timharley/events{/privacy}","received_events_url":"https://api.github.com/users/timharley/received_events","type":"User","site_admin":false},"body":"These commits, once combined with the THGenerator pull request, make torch threadsafe.\r\n\r\nIt breaks the luaT API to return a string in a nice manner. I will patch the docs if noone objects to this.\r\n\r\nHere is the test I used, using the handy [luall_threads](https://github.com/Neopallium/lua-llthreads): \r\n\r\nWithout the relevant patches, you get a segfault.\r\nCombing this branch with the THGenerator pull request, it doesn't segfault and gives identical results in all threads.\r\n\r\n```\r\nlocal llthreads = require \"llthreads\"\r\n\r\nfunction thread_func(...)\r\n    -- print thread's parameter.\r\n    print(\"CHILD: received params:\", ...)\r\n\r\n    -- Do the requires here, to check luaT_classmodulename\r\n    require 'torch'\r\n    require 'nn'\r\n\r\n    -- Generate a few thousand THErrors.\r\n    for i = 1,10000 do \r\n        local ok = pcall( function ()\r\n            local unused = torch.Tensor(5)[torch.ByteTensor(6)]\r\n        end)\r\n    end\r\n\r\n    -- Generate a few thousand THArgErrors.\r\n    for i = 1,10000 do \r\n        local ok = pcall( function ()\r\n            local unused = torch.random(torch.Tensor(5),1,-2)\r\n        end)\r\n    end\r\n\r\n    torch.manualSeed(1)\r\n\r\n    -- Stress the random number generator\r\n    local mean = torch.randn(1000000):add(100):mean()\r\n    local m\r\n\r\n    for i=1,1000 do\r\n       local x= torch.rand(1000)\r\n       local go = torch.rand(10)\r\n       m = nn.Sequential():add(nn.Linear(1000,100)):add(nn.Tanh()):add(nn.Linear(100,10))\r\n       m:forward(x)\r\n       m:backward(x,go)\r\n       collectgarbage()\r\n    end\r\n    return {mean,m.gradInput:abs():sum()}\r\nend\r\n\r\nlocal main_thread_results = thread_func()\r\nlocal expectedMean, expectedGradInputSum = main_thread_results[1], main_thread_results[2]\r\n\r\nlocal nChildren = 12\r\nlocal children = {}\r\nfor i = 1, nChildren do\r\n   local child = llthreads.new(string.dump(thread_func), \"number:\", 1234, \"nil:\", nil, \"bool:\", true)\r\n   assert(child:start())\r\n   children[i] = child\r\nend\r\n\r\nlocal results = {}\r\nfor i, child in ipairs(children) do\r\n    local result = {child:join()}\r\n    results[i] = result\r\n    print(\"PARENT: child returned: \", result[1],unpack(result[2]))\r\nend\r\n\r\nfor i, result in ipairs(results) do\r\n   assert(results[i][1] == true, \"expecting success\")\r\n   assert(results[i][2][1] == expectedMean,\r\n\t  string.format(\"wrong result: %s ~= %s\", results[i][2][1], expectedMean))\r\n   assert(results[i][2][2] == expectedGradInputSum,\r\n\t  string.format(\"wrong result: %s ~= %s\", results[i][2][2], expectedGradInputSum))\r\nend\r\n```\r\n","created_at":"2014-03-17T12:01:45Z","updated_at":"2014-03-17T12:01:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/torch/torch7/pulls/18/commits","review_comments_url":"https://api.github.com/repos/torch/torch7/pulls/18/comments","review_comment_url":"https://api.github.com/repos/torch/torch7/pulls/comments/{number}","comments_url":"https://api.github.com/repos/torch/torch7/issues/18/comments","statuses_url":"https://api.github.com/repos/torch/torch7/statuses/7504955cc8fd207dfa0d362199a286331bc03347","head":{"label":"timharley:thread_safety","ref":"thread_safety","sha":"7504955cc8fd207dfa0d362199a286331bc03347","user":{"login":"timharley","id":4367998,"avatar_url":"https://gravatar.com/avatar/7a9abef843f730e6b4eab7331ed1ead3?d=https%3A%2F%2Fidenticons.github.com%2F4af115d2d1d39cbe4388885d42a42fcf.png&r=x","gravatar_id":"7a9abef843f730e6b4eab7331ed1ead3","url":"https://api.github.com/users/timharley","html_url":"https://github.com/timharley","followers_url":"https://api.github.com/users/timharley/followers","following_url":"https://api.github.com/users/timharley/following{/other_user}","gists_url":"https://api.github.com/users/timharley/gists{/gist_id}","starred_url":"https://api.github.com/users/timharley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timharley/subscriptions","organizations_url":"https://api.github.com/users/timharley/orgs","repos_url":"https://api.github.com/users/timharley/repos","events_url":"https://api.github.com/users/timharley/events{/privacy}","received_events_url":"https://api.github.com/users/timharley/received_events","type":"User","site_admin":false},"repo":{"id":17138074,"name":"torch7","full_name":"timharley/torch7","owner":{"login":"timharley","id":4367998,"avatar_url":"https://gravatar.com/avatar/7a9abef843f730e6b4eab7331ed1ead3?d=https%3A%2F%2Fidenticons.github.com%2F4af115d2d1d39cbe4388885d42a42fcf.png&r=x","gravatar_id":"7a9abef843f730e6b4eab7331ed1ead3","url":"https://api.github.com/users/timharley","html_url":"https://github.com/timharley","followers_url":"https://api.github.com/users/timharley/followers","following_url":"https://api.github.com/users/timharley/following{/other_user}","gists_url":"https://api.github.com/users/timharley/gists{/gist_id}","starred_url":"https://api.github.com/users/timharley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timharley/subscriptions","organizations_url":"https://api.github.com/users/timharley/orgs","repos_url":"https://api.github.com/users/timharley/repos","events_url":"https://api.github.com/users/timharley/events{/privacy}","received_events_url":"https://api.github.com/users/timharley/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/timharley/torch7","description":"","fork":true,"url":"https://api.github.com/repos/timharley/torch7","forks_url":"https://api.github.com/repos/timharley/torch7/forks","keys_url":"https://api.github.com/repos/timharley/torch7/keys{/key_id}","collaborators_url":"https://api.github.com/repos/timharley/torch7/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/timharley/torch7/teams","hooks_url":"https://api.github.com/repos/timharley/torch7/hooks","issue_events_url":"https://api.github.com/repos/timharley/torch7/issues/events{/number}","events_url":"https://api.github.com/repos/timharley/torch7/events","assignees_url":"https://api.github.com/repos/timharley/torch7/assignees{/user}","branches_url":"https://api.github.com/repos/timharley/torch7/branches{/branch}","tags_url":"https://api.github.com/repos/timharley/torch7/tags","blobs_url":"https://api.github.com/repos/timharley/torch7/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/timharley/torch7/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/timharley/torch7/git/refs{/sha}","trees_url":"https://api.github.com/repos/timharley/torch7/git/trees{/sha}","statuses_url":"https://api.github.com/repos/timharley/torch7/statuses/{sha}","languages_url":"https://api.github.com/repos/timharley/torch7/languages","stargazers_url":"https://api.github.com/repos/timharley/torch7/stargazers","contributors_url":"https://api.github.com/repos/timharley/torch7/contributors","subscribers_url":"https://api.github.com/repos/timharley/torch7/subscribers","subscription_url":"https://api.github.com/repos/timharley/torch7/subscription","commits_url":"https://api.github.com/repos/timharley/torch7/commits{/sha}","git_commits_url":"https://api.github.com/repos/timharley/torch7/git/commits{/sha}","comments_url":"https://api.github.com/repos/timharley/torch7/comments{/number}","issue_comment_url":"https://api.github.com/repos/timharley/torch7/issues/comments/{number}","contents_url":"https://api.github.com/repos/timharley/torch7/contents/{+path}","compare_url":"https://api.github.com/repos/timharley/torch7/compare/{base}...{head}","merges_url":"https://api.github.com/repos/timharley/torch7/merges","archive_url":"https://api.github.com/repos/timharley/torch7/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/timharley/torch7/downloads","issues_url":"https://api.github.com/repos/timharley/torch7/issues{/number}","pulls_url":"https://api.github.com/repos/timharley/torch7/pulls{/number}","milestones_url":"https://api.github.com/repos/timharley/torch7/milestones{/number}","notifications_url":"https://api.github.com/repos/timharley/torch7/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/timharley/torch7/labels{/name}","releases_url":"https://api.github.com/repos/timharley/torch7/releases{/id}","created_at":"2014-02-24T14:10:21Z","updated_at":"2014-03-17T12:01:45Z","pushed_at":"2014-03-14T19:11:14Z","git_url":"git://github.com/timharley/torch7.git","ssh_url":"git@github.com:timharley/torch7.git","clone_url":"https://github.com/timharley/torch7.git","svn_url":"https://github.com/timharley/torch7","homepage":null,"size":696,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master","master_branch":"master"}},"base":{"label":"torch:master","ref":"master","sha":"86f62cffc52b8292a92caefe2a74b4ed15208454","user":{"login":"torch","id":4978924,"avatar_url":"https://gravatar.com/avatar/26967197c3dd8dc0a7a5bf89e3c6550b?d=https%3A%2F%2Fidenticons.github.com%2Fe9fee491d2a483ca6eb386bbc8042c30.png&r=x","gravatar_id":"26967197c3dd8dc0a7a5bf89e3c6550b","url":"https://api.github.com/users/torch","html_url":"https://github.com/torch","followers_url":"https://api.github.com/users/torch/followers","following_url":"https://api.github.com/users/torch/following{/other_user}","gists_url":"https://api.github.com/users/torch/gists{/gist_id}","starred_url":"https://api.github.com/users/torch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/torch/subscriptions","organizations_url":"https://api.github.com/users/torch/orgs","repos_url":"https://api.github.com/users/torch/repos","events_url":"https://api.github.com/users/torch/events{/privacy}","received_events_url":"https://api.github.com/users/torch/received_events","type":"Organization","site_admin":false},"repo":{"id":13677187,"name":"torch7","full_name":"torch/torch7","owner":{"login":"torch","id":4978924,"avatar_url":"https://gravatar.com/avatar/26967197c3dd8dc0a7a5bf89e3c6550b?d=https%3A%2F%2Fidenticons.github.com%2Fe9fee491d2a483ca6eb386bbc8042c30.png&r=x","gravatar_id":"26967197c3dd8dc0a7a5bf89e3c6550b","url":"https://api.github.com/users/torch","html_url":"https://github.com/torch","followers_url":"https://api.github.com/users/torch/followers","following_url":"https://api.github.com/users/torch/following{/other_user}","gists_url":"https://api.github.com/users/torch/gists{/gist_id}","starred_url":"https://api.github.com/users/torch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/torch/subscriptions","organizations_url":"https://api.github.com/users/torch/orgs","repos_url":"https://api.github.com/users/torch/repos","events_url":"https://api.github.com/users/torch/events{/privacy}","received_events_url":"https://api.github.com/users/torch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/torch/torch7","description":"","fork":false,"url":"https://api.github.com/repos/torch/torch7","forks_url":"https://api.github.com/repos/torch/torch7/forks","keys_url":"https://api.github.com/repos/torch/torch7/keys{/key_id}","collaborators_url":"https://api.github.com/repos/torch/torch7/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/torch/torch7/teams","hooks_url":"https://api.github.com/repos/torch/torch7/hooks","issue_events_url":"https://api.github.com/repos/torch/torch7/issues/events{/number}","events_url":"https://api.github.com/repos/torch/torch7/events","assignees_url":"https://api.github.com/repos/torch/torch7/assignees{/user}","branches_url":"https://api.github.com/repos/torch/torch7/branches{/branch}","tags_url":"https://api.github.com/repos/torch/torch7/tags","blobs_url":"https://api.github.com/repos/torch/torch7/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/torch/torch7/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/torch/torch7/git/refs{/sha}","trees_url":"https://api.github.com/repos/torch/torch7/git/trees{/sha}","statuses_url":"https://api.github.com/repos/torch/torch7/statuses/{sha}","languages_url":"https://api.github.com/repos/torch/torch7/languages","stargazers_url":"https://api.github.com/repos/torch/torch7/stargazers","contributors_url":"https://api.github.com/repos/torch/torch7/contributors","subscribers_url":"https://api.github.com/repos/torch/torch7/subscribers","subscription_url":"https://api.github.com/repos/torch/torch7/subscription","commits_url":"https://api.github.com/repos/torch/torch7/commits{/sha}","git_commits_url":"https://api.github.com/repos/torch/torch7/git/commits{/sha}","comments_url":"https://api.github.com/repos/torch/torch7/comments{/number}","issue_comment_url":"https://api.github.com/repos/torch/torch7/issues/comments/{number}","contents_url":"https://api.github.com/repos/torch/torch7/contents/{+path}","compare_url":"https://api.github.com/repos/torch/torch7/compare/{base}...{head}","merges_url":"https://api.github.com/repos/torch/torch7/merges","archive_url":"https://api.github.com/repos/torch/torch7/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/torch/torch7/downloads","issues_url":"https://api.github.com/repos/torch/torch7/issues{/number}","pulls_url":"https://api.github.com/repos/torch/torch7/pulls{/number}","milestones_url":"https://api.github.com/repos/torch/torch7/milestones{/number}","notifications_url":"https://api.github.com/repos/torch/torch7/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/torch/torch7/labels{/name}","releases_url":"https://api.github.com/repos/torch/torch7/releases{/id}","created_at":"2013-10-18T12:13:58Z","updated_at":"2014-03-14T21:39:49Z","pushed_at":"2014-03-14T21:39:49Z","git_url":"git://github.com/torch/torch7.git","ssh_url":"git@github.com:torch/torch7.git","clone_url":"https://github.com/torch/torch7.git","svn_url":"https://github.com/torch/torch7","homepage":null,"size":993,"stargazers_count":27,"watchers_count":27,"language":"C","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":19,"mirror_url":null,"open_issues_count":9,"forks":19,"open_issues":9,"watchers":27,"default_branch":"master","master_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/torch/torch7/pulls/18"},"html":{"href":"https://github.com/torch/torch7/pull/18"},"issue":{"href":"https://api.github.com/repos/torch/torch7/issues/18"},"comments":{"href":"https://api.github.com/repos/torch/torch7/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/torch/torch7/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/torch/torch7/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/torch/torch7/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/torch/torch7/statuses/7504955cc8fd207dfa0d362199a286331bc03347"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":3,"additions":56,"deletions":42,"changed_files":7}}