{"action":"created","comment":{"url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/comments/212818170","pull_request_review_id":149527061,"id":212818170,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMjgxODE3MA==","diff_hunk":"@@ -385,40 +277,79 @@ class FusedElemwiseActivationKernel : public framework::OpKernel<T> {\n     auto &in_y = detail::Ref(ctx.Input<framework::Tensor>(\"Y\"),\n                              \"Cannot get input tensor %s, variable name = %s\",\n                              \"Y\", ctx.op().Input(\"Y\"));\n-    auto &output = detail::Ref(ctx.Output<framework::Tensor>(\"Out\"),\n-                               \"Cannot get input tensor %s, variable name = %s\",\n-                               \"Out\", ctx.op().Output(\"Out\"));\n+    auto outputs = ctx.MultiOutput<framework::Tensor>(\"Out\");\n \n-    RunFunctors<DeviceContext, T>(ctx, &in_x, &in_y, &output);\n+    if (!ctx.Attr<bool>(\"keep_intermediate_value\")) {\n+      outputs.push_back(nullptr);\n+    }\n+\n+    RunFunctors<DeviceContext, T>(ctx, in_x, in_y, &outputs);\n   }\n };\n \n template <typename DeviceContext, typename T>\n class FusedElemwiseActivationGradKernel : public framework::OpKernel<T> {\n  public:\n   void Compute(const framework::ExecutionContext &ctx) const override {\n-    auto &in_x = detail::Ref(ctx.Input<framework::Tensor>(\"X\"),\n-                             \"Cannot get input tensor %s, variable name = %s\",\n-                             \"X\", ctx.op().Input(\"X\"));\n-    auto &in_y = detail::Ref(ctx.Input<framework::Tensor>(\"Y\"),\n-                             \"Cannot get input tensor %s, variable name = %s\",\n-                             \"Y\", ctx.op().Input(\"Y\"));\n-    auto &in_out = detail::Ref(ctx.Input<framework::Tensor>(\"Out\"),\n-                               \"Cannot get input tensor %s, variable name = %s\",\n-                               \"Out\", ctx.op().Input(\"Out\"));\n-    auto &in_out_grad =\n-        detail::Ref(ctx.Input<framework::Tensor>(framework::GradVarName(\"Out\")),\n-                    \"Cannot get input tensor %s, variable name = %s\",\n-                    framework::GradVarName(\"Out\"),\n-                    ctx.op().Input(framework::GradVarName(\"Out\")));\n+    auto x = ctx.Input<framework::Tensor>(\"X\");\n+    auto y = ctx.Input<framework::Tensor>(\"Y\");\n+\n+    auto &in_outs = ctx.MultiInput<framework::Tensor>(\"Out\");\n+    auto &in_outs_grad =\n+        ctx.MultiInput<framework::Tensor>(framework::GradVarName(\"Out\"));\n \n     framework::Tensor *x_grad =\n         ctx.Output<framework::Tensor>(framework::GradVarName(\"X\"));\n     framework::Tensor *y_grad =\n         ctx.Output<framework::Tensor>(framework::GradVarName(\"Y\"));\n \n-    RunGradFunctors<DeviceContext, T>(ctx, &in_x, &in_y, &in_out, &in_out_grad,\n-                                      x_grad, y_grad);\n+    if (ctx.Attr<bool>(\"recomputation\")) {\n+      PADDLE_ENFORCE(\n+          x != nullptr,\n+          \"The recomputation is opened, so Input(X) should not be absent.\");\n+      PADDLE_ENFORCE(\n+          y != nullptr,\n+          \"The recomputation is opened, so Input(Y) should not be absent.\");\n+    } else {\n+      PADDLE_ENFORCE_GE(in_outs.size(), 1,\n+                        \"The recomputation is disabled,\"\n+                        \"so the Input('Out') should not be empty.\");\n+    }\n+\n+    framework::Tensor *in_x, *in_y;\n+    framework::Tensor *in_out, *in_intermediate_out;\n+    // If functor_list contains elementwise_add, the backward doesn't use\n+    // in_x,in_y and in_outs.\n+    auto functor_list = ctx.Attr<std::vector<std::string>>(\"functor_list\");\n+    if (functor_list[0] == \"elementwise_add\" ||\n+        functor_list[1] == \"elementwise_add\") {\n+      in_x = const_cast<framework::Tensor *>(in_outs_grad[0]);","path":"paddle/fluid/operators/fused_elemwise_activation_op.h","position":570,"original_position":570,"commit_id":"3dac8e64b2d8cd1712389de1836ef98dddc441fb","original_commit_id":"3dac8e64b2d8cd1712389de1836ef98dddc441fb","user":{"login":"panyx0718","id":2887803,"node_id":"MDQ6VXNlcjI4ODc4MDM=","avatar_url":"https://avatars0.githubusercontent.com/u/2887803?v=4","gravatar_id":"","url":"https://api.github.com/users/panyx0718","html_url":"https://github.com/panyx0718","followers_url":"https://api.github.com/users/panyx0718/followers","following_url":"https://api.github.com/users/panyx0718/following{/other_user}","gists_url":"https://api.github.com/users/panyx0718/gists{/gist_id}","starred_url":"https://api.github.com/users/panyx0718/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/panyx0718/subscriptions","organizations_url":"https://api.github.com/users/panyx0718/orgs","repos_url":"https://api.github.com/users/panyx0718/repos","events_url":"https://api.github.com/users/panyx0718/events{/privacy}","received_events_url":"https://api.github.com/users/panyx0718/received_events","type":"User","site_admin":false},"body":"should you use Output() above to avoid `const_cast` here and below?","created_at":"2018-08-26T08:02:03Z","updated_at":"2018-08-26T08:11:55Z","html_url":"https://github.com/PaddlePaddle/Paddle/pull/12837#discussion_r212818170","pull_request_url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/12837","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/comments/212818170"},"html":{"href":"https://github.com/PaddlePaddle/Paddle/pull/12837#discussion_r212818170"},"pull_request":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/12837"}}},"pull_request":{"url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/12837","id":209769535,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA5NzY5NTM1","html_url":"https://github.com/PaddlePaddle/Paddle/pull/12837","diff_url":"https://github.com/PaddlePaddle/Paddle/pull/12837.diff","patch_url":"https://github.com/PaddlePaddle/Paddle/pull/12837.patch","issue_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/12837","number":12837,"state":"open","locked":false,"title":"Enhance fused_elementwise_activation_op","user":{"login":"chengduoZH","id":30176695,"node_id":"MDQ6VXNlcjMwMTc2Njk1","avatar_url":"https://avatars2.githubusercontent.com/u/30176695?v=4","gravatar_id":"","url":"https://api.github.com/users/chengduoZH","html_url":"https://github.com/chengduoZH","followers_url":"https://api.github.com/users/chengduoZH/followers","following_url":"https://api.github.com/users/chengduoZH/following{/other_user}","gists_url":"https://api.github.com/users/chengduoZH/gists{/gist_id}","starred_url":"https://api.github.com/users/chengduoZH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chengduoZH/subscriptions","organizations_url":"https://api.github.com/users/chengduoZH/orgs","repos_url":"https://api.github.com/users/chengduoZH/repos","events_url":"https://api.github.com/users/chengduoZH/events{/privacy}","received_events_url":"https://api.github.com/users/chengduoZH/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-08-21T09:52:52Z","updated_at":"2018-08-26T08:11:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b87b45c4630f6dcc06e3bd26c74730dc608a61bf","assignee":null,"assignees":[],"requested_reviewers":[{"login":"reyoung","id":728699,"node_id":"MDQ6VXNlcjcyODY5OQ==","avatar_url":"https://avatars2.githubusercontent.com/u/728699?v=4","gravatar_id":"","url":"https://api.github.com/users/reyoung","html_url":"https://github.com/reyoung","followers_url":"https://api.github.com/users/reyoung/followers","following_url":"https://api.github.com/users/reyoung/following{/other_user}","gists_url":"https://api.github.com/users/reyoung/gists{/gist_id}","starred_url":"https://api.github.com/users/reyoung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reyoung/subscriptions","organizations_url":"https://api.github.com/users/reyoung/orgs","repos_url":"https://api.github.com/users/reyoung/repos","events_url":"https://api.github.com/users/reyoung/events{/privacy}","received_events_url":"https://api.github.com/users/reyoung/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/12837/commits","review_comments_url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/12837/comments","review_comment_url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/12837/comments","statuses_url":"https://api.github.com/repos/PaddlePaddle/Paddle/statuses/3dac8e64b2d8cd1712389de1836ef98dddc441fb","head":{"label":"chengduoZH:enhance_fused_elementwise_activation_op","ref":"enhance_fused_elementwise_activation_op","sha":"3dac8e64b2d8cd1712389de1836ef98dddc441fb","user":{"login":"chengduoZH","id":30176695,"node_id":"MDQ6VXNlcjMwMTc2Njk1","avatar_url":"https://avatars2.githubusercontent.com/u/30176695?v=4","gravatar_id":"","url":"https://api.github.com/users/chengduoZH","html_url":"https://github.com/chengduoZH","followers_url":"https://api.github.com/users/chengduoZH/followers","following_url":"https://api.github.com/users/chengduoZH/following{/other_user}","gists_url":"https://api.github.com/users/chengduoZH/gists{/gist_id}","starred_url":"https://api.github.com/users/chengduoZH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chengduoZH/subscriptions","organizations_url":"https://api.github.com/users/chengduoZH/orgs","repos_url":"https://api.github.com/users/chengduoZH/repos","events_url":"https://api.github.com/users/chengduoZH/events{/privacy}","received_events_url":"https://api.github.com/users/chengduoZH/received_events","type":"User","site_admin":false},"repo":{"id":99756501,"node_id":"MDEwOlJlcG9zaXRvcnk5OTc1NjUwMQ==","name":"Paddle","full_name":"chengduoZH/Paddle","owner":{"login":"chengduoZH","id":30176695,"node_id":"MDQ6VXNlcjMwMTc2Njk1","avatar_url":"https://avatars2.githubusercontent.com/u/30176695?v=4","gravatar_id":"","url":"https://api.github.com/users/chengduoZH","html_url":"https://github.com/chengduoZH","followers_url":"https://api.github.com/users/chengduoZH/followers","following_url":"https://api.github.com/users/chengduoZH/following{/other_user}","gists_url":"https://api.github.com/users/chengduoZH/gists{/gist_id}","starred_url":"https://api.github.com/users/chengduoZH/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chengduoZH/subscriptions","organizations_url":"https://api.github.com/users/chengduoZH/orgs","repos_url":"https://api.github.com/users/chengduoZH/repos","events_url":"https://api.github.com/users/chengduoZH/events{/privacy}","received_events_url":"https://api.github.com/users/chengduoZH/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chengduoZH/Paddle","description":"PArallel Distributed Deep LEarning","fork":true,"url":"https://api.github.com/repos/chengduoZH/Paddle","forks_url":"https://api.github.com/repos/chengduoZH/Paddle/forks","keys_url":"https://api.github.com/repos/chengduoZH/Paddle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chengduoZH/Paddle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chengduoZH/Paddle/teams","hooks_url":"https://api.github.com/repos/chengduoZH/Paddle/hooks","issue_events_url":"https://api.github.com/repos/chengduoZH/Paddle/issues/events{/number}","events_url":"https://api.github.com/repos/chengduoZH/Paddle/events","assignees_url":"https://api.github.com/repos/chengduoZH/Paddle/assignees{/user}","branches_url":"https://api.github.com/repos/chengduoZH/Paddle/branches{/branch}","tags_url":"https://api.github.com/repos/chengduoZH/Paddle/tags","blobs_url":"https://api.github.com/repos/chengduoZH/Paddle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chengduoZH/Paddle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chengduoZH/Paddle/git/refs{/sha}","trees_url":"https://api.github.com/repos/chengduoZH/Paddle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chengduoZH/Paddle/statuses/{sha}","languages_url":"https://api.github.com/repos/chengduoZH/Paddle/languages","stargazers_url":"https://api.github.com/repos/chengduoZH/Paddle/stargazers","contributors_url":"https://api.github.com/repos/chengduoZH/Paddle/contributors","subscribers_url":"https://api.github.com/repos/chengduoZH/Paddle/subscribers","subscription_url":"https://api.github.com/repos/chengduoZH/Paddle/subscription","commits_url":"https://api.github.com/repos/chengduoZH/Paddle/commits{/sha}","git_commits_url":"https://api.github.com/repos/chengduoZH/Paddle/git/commits{/sha}","comments_url":"https://api.github.com/repos/chengduoZH/Paddle/comments{/number}","issue_comment_url":"https://api.github.com/repos/chengduoZH/Paddle/issues/comments{/number}","contents_url":"https://api.github.com/repos/chengduoZH/Paddle/contents/{+path}","compare_url":"https://api.github.com/repos/chengduoZH/Paddle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chengduoZH/Paddle/merges","archive_url":"https://api.github.com/repos/chengduoZH/Paddle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chengduoZH/Paddle/downloads","issues_url":"https://api.github.com/repos/chengduoZH/Paddle/issues{/number}","pulls_url":"https://api.github.com/repos/chengduoZH/Paddle/pulls{/number}","milestones_url":"https://api.github.com/repos/chengduoZH/Paddle/milestones{/number}","notifications_url":"https://api.github.com/repos/chengduoZH/Paddle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chengduoZH/Paddle/labels{/name}","releases_url":"https://api.github.com/repos/chengduoZH/Paddle/releases{/id}","deployments_url":"https://api.github.com/repos/chengduoZH/Paddle/deployments","created_at":"2017-08-09T02:26:38Z","updated_at":"2018-08-22T12:53:20Z","pushed_at":"2018-08-25T07:44:42Z","git_url":"git://github.com/chengduoZH/Paddle.git","ssh_url":"git@github.com:chengduoZH/Paddle.git","clone_url":"https://github.com/chengduoZH/Paddle.git","svn_url":"https://github.com/chengduoZH/Paddle","homepage":"http://www.paddlepaddle.org/","size":96385,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":2,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"PaddlePaddle:develop","ref":"develop","sha":"21ba32b06503dee2d6b98653dc6ac241aed16ee0","user":{"login":"PaddlePaddle","id":23534030,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIzNTM0MDMw","avatar_url":"https://avatars3.githubusercontent.com/u/23534030?v=4","gravatar_id":"","url":"https://api.github.com/users/PaddlePaddle","html_url":"https://github.com/PaddlePaddle","followers_url":"https://api.github.com/users/PaddlePaddle/followers","following_url":"https://api.github.com/users/PaddlePaddle/following{/other_user}","gists_url":"https://api.github.com/users/PaddlePaddle/gists{/gist_id}","starred_url":"https://api.github.com/users/PaddlePaddle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PaddlePaddle/subscriptions","organizations_url":"https://api.github.com/users/PaddlePaddle/orgs","repos_url":"https://api.github.com/users/PaddlePaddle/repos","events_url":"https://api.github.com/users/PaddlePaddle/events{/privacy}","received_events_url":"https://api.github.com/users/PaddlePaddle/received_events","type":"Organization","site_admin":false},"repo":{"id":65711522,"node_id":"MDEwOlJlcG9zaXRvcnk2NTcxMTUyMg==","name":"Paddle","full_name":"PaddlePaddle/Paddle","owner":{"login":"PaddlePaddle","id":23534030,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIzNTM0MDMw","avatar_url":"https://avatars3.githubusercontent.com/u/23534030?v=4","gravatar_id":"","url":"https://api.github.com/users/PaddlePaddle","html_url":"https://github.com/PaddlePaddle","followers_url":"https://api.github.com/users/PaddlePaddle/followers","following_url":"https://api.github.com/users/PaddlePaddle/following{/other_user}","gists_url":"https://api.github.com/users/PaddlePaddle/gists{/gist_id}","starred_url":"https://api.github.com/users/PaddlePaddle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PaddlePaddle/subscriptions","organizations_url":"https://api.github.com/users/PaddlePaddle/orgs","repos_url":"https://api.github.com/users/PaddlePaddle/repos","events_url":"https://api.github.com/users/PaddlePaddle/events{/privacy}","received_events_url":"https://api.github.com/users/PaddlePaddle/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PaddlePaddle/Paddle","description":"PArallel Distributed Deep LEarning","fork":false,"url":"https://api.github.com/repos/PaddlePaddle/Paddle","forks_url":"https://api.github.com/repos/PaddlePaddle/Paddle/forks","keys_url":"https://api.github.com/repos/PaddlePaddle/Paddle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PaddlePaddle/Paddle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PaddlePaddle/Paddle/teams","hooks_url":"https://api.github.com/repos/PaddlePaddle/Paddle/hooks","issue_events_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/events{/number}","events_url":"https://api.github.com/repos/PaddlePaddle/Paddle/events","assignees_url":"https://api.github.com/repos/PaddlePaddle/Paddle/assignees{/user}","branches_url":"https://api.github.com/repos/PaddlePaddle/Paddle/branches{/branch}","tags_url":"https://api.github.com/repos/PaddlePaddle/Paddle/tags","blobs_url":"https://api.github.com/repos/PaddlePaddle/Paddle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PaddlePaddle/Paddle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PaddlePaddle/Paddle/git/refs{/sha}","trees_url":"https://api.github.com/repos/PaddlePaddle/Paddle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PaddlePaddle/Paddle/statuses/{sha}","languages_url":"https://api.github.com/repos/PaddlePaddle/Paddle/languages","stargazers_url":"https://api.github.com/repos/PaddlePaddle/Paddle/stargazers","contributors_url":"https://api.github.com/repos/PaddlePaddle/Paddle/contributors","subscribers_url":"https://api.github.com/repos/PaddlePaddle/Paddle/subscribers","subscription_url":"https://api.github.com/repos/PaddlePaddle/Paddle/subscription","commits_url":"https://api.github.com/repos/PaddlePaddle/Paddle/commits{/sha}","git_commits_url":"https://api.github.com/repos/PaddlePaddle/Paddle/git/commits{/sha}","comments_url":"https://api.github.com/repos/PaddlePaddle/Paddle/comments{/number}","issue_comment_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/comments{/number}","contents_url":"https://api.github.com/repos/PaddlePaddle/Paddle/contents/{+path}","compare_url":"https://api.github.com/repos/PaddlePaddle/Paddle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PaddlePaddle/Paddle/merges","archive_url":"https://api.github.com/repos/PaddlePaddle/Paddle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PaddlePaddle/Paddle/downloads","issues_url":"https://api.github.com/repos/PaddlePaddle/Paddle/issues{/number}","pulls_url":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls{/number}","milestones_url":"https://api.github.com/repos/PaddlePaddle/Paddle/milestones{/number}","notifications_url":"https://api.github.com/repos/PaddlePaddle/Paddle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PaddlePaddle/Paddle/labels{/name}","releases_url":"https://api.github.com/repos/PaddlePaddle/Paddle/releases{/id}","deployments_url":"https://api.github.com/repos/PaddlePaddle/Paddle/deployments","created_at":"2016-08-15T06:59:08Z","updated_at":"2018-08-26T07:28:17Z","pushed_at":"2018-08-26T08:06:40Z","git_url":"git://github.com/PaddlePaddle/Paddle.git","ssh_url":"git@github.com:PaddlePaddle/Paddle.git","clone_url":"https://github.com/PaddlePaddle/Paddle.git","svn_url":"https://github.com/PaddlePaddle/Paddle","homepage":"http://www.paddlepaddle.org/","size":124494,"stargazers_count":7452,"watchers_count":7452,"language":"C++","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":2036,"mirror_url":null,"archived":false,"open_issues_count":632,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":2036,"open_issues":632,"watchers":7452,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/12837"},"html":{"href":"https://github.com/PaddlePaddle/Paddle/pull/12837"},"issue":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/12837"},"comments":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/issues/12837/comments"},"review_comments":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/12837/comments"},"review_comment":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/pulls/12837/commits"},"statuses":{"href":"https://api.github.com/repos/PaddlePaddle/Paddle/statuses/3dac8e64b2d8cd1712389de1836ef98dddc441fb"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"panyx0718"}}