{"action":"created","comment":{"url":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/comments/244271061","pull_request_review_id":188230017,"id":244271061,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0NDI3MTA2MQ==","diff_hunk":"@@ -111,60 +142,89 @@ def evaluate():\n         Ls.append(ls)\n         step_loss += sum([L.asscalar() for L in Ls])\n         metric.update([label], [out])\n-    logging.info('validation accuracy: %s', metric.get()[1])\n+    logging.info('Validation accuracy: {:.3f}'.format(metric.get()[1]))\n \n \n def train():\n     \"\"\"Training function.\"\"\"\n-    trainer = gluon.Trainer(model.collect_params(), args.optimizer,\n-                            {'learning_rate': lr, 'epsilon': 1e-9})\n+    try:\n+        trainer = gluon.Trainer(model.collect_params(), args.optimizer,\n+                                {'learning_rate': lr, 'epsilon': 1e-6, 'wd': 0.01})\n+    except ValueError as e:\n+        warnings.warn(\"AdamW optimizer is not found. Please consider upgrading to \"\n+                      \"mxnet>=1.5.0. Now the original Adam optimizer is used instead.\")\n+        trainer = gluon.Trainer(model.collect_params(), 'adam',\n+                                {'learning_rate': lr, 'epsilon': 1e-6, 'wd': 0.01})\n \n     num_train_examples = len(data_train)\n-    num_train_steps = int(num_train_examples / batch_size * args.epochs)\n+    step_size = batch_size * accumulate if accumulate else batch_size\n+    num_train_steps = int(num_train_examples / step_size * args.epochs)\n     warmup_ratio = args.warmup_ratio\n     num_warmup_steps = int(num_train_steps * warmup_ratio)\n     step_num = 0\n-    differentiable_params = []\n+    params = []\n \n     # Do not apply weight decay on LayerNorm and bias terms\n     for _, v in model.collect_params('.*beta|.*gamma|.*bias').items():\n         v.wd_mult = 0.0\n-\n+    # Collect differentiable parameters\n     for p in model.collect_params().values():\n         if p.grad_req != 'null':\n-            differentiable_params.append(p)\n+            params.append(p)\n+    # Set grad_req if gradient accumulation is required\n+    if accumulate:\n+        for p in model.collect_params().values():\n+            p.grad_req = 'add'","path":"scripts/bert/finetune_classifier.py","position":170,"original_position":170,"commit_id":"df63e2c2a4d6b998289c25a38ffec8f4ff647ff4","original_commit_id":"df63e2c2a4d6b998289c25a38ffec8f4ff647ff4","user":{"login":"szha","id":2626883,"node_id":"MDQ6VXNlcjI2MjY4ODM=","avatar_url":"https://avatars2.githubusercontent.com/u/2626883?v=4","gravatar_id":"","url":"https://api.github.com/users/szha","html_url":"https://github.com/szha","followers_url":"https://api.github.com/users/szha/followers","following_url":"https://api.github.com/users/szha/following{/other_user}","gists_url":"https://api.github.com/users/szha/gists{/gist_id}","starred_url":"https://api.github.com/users/szha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szha/subscriptions","organizations_url":"https://api.github.com/users/szha/orgs","repos_url":"https://api.github.com/users/szha/repos","events_url":"https://api.github.com/users/szha/events{/privacy}","received_events_url":"https://api.github.com/users/szha/received_events","type":"User","site_admin":false},"body":"this seems wrong... it's setting all parameters to add even for those that had `grad_req = 'null'`","created_at":"2018-12-28T06:44:13Z","updated_at":"2018-12-28T06:44:14Z","html_url":"https://github.com/dmlc/gluon-nlp/pull/482#discussion_r244271061","pull_request_url":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/482","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/comments/244271061"},"html":{"href":"https://github.com/dmlc/gluon-nlp/pull/482#discussion_r244271061"},"pull_request":{"href":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/482"}}},"pull_request":{"url":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/482","id":240891047,"node_id":"MDExOlB1bGxSZXF1ZXN0MjQwODkxMDQ3","html_url":"https://github.com/dmlc/gluon-nlp/pull/482","diff_url":"https://github.com/dmlc/gluon-nlp/pull/482.diff","patch_url":"https://github.com/dmlc/gluon-nlp/pull/482.patch","issue_url":"https://api.github.com/repos/dmlc/gluon-nlp/issues/482","number":482,"state":"open","locked":false,"title":"[SCRIPT] Improve BERT fine-tuning script with AdamW optimizer, bucketing and gradient accumulation","user":{"login":"eric-haibin-lin","id":5545640,"node_id":"MDQ6VXNlcjU1NDU2NDA=","avatar_url":"https://avatars1.githubusercontent.com/u/5545640?v=4","gravatar_id":"","url":"https://api.github.com/users/eric-haibin-lin","html_url":"https://github.com/eric-haibin-lin","followers_url":"https://api.github.com/users/eric-haibin-lin/followers","following_url":"https://api.github.com/users/eric-haibin-lin/following{/other_user}","gists_url":"https://api.github.com/users/eric-haibin-lin/gists{/gist_id}","starred_url":"https://api.github.com/users/eric-haibin-lin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eric-haibin-lin/subscriptions","organizations_url":"https://api.github.com/users/eric-haibin-lin/orgs","repos_url":"https://api.github.com/users/eric-haibin-lin/repos","events_url":"https://api.github.com/users/eric-haibin-lin/events{/privacy}","received_events_url":"https://api.github.com/users/eric-haibin-lin/received_events","type":"User","site_admin":false},"body":"## Description ##\r\n- update command with adamw optimizer, which applies weight decay instead of l2 loss with Adam, as is used in the original TF bert repo.  (requires https://github.com/apache/incubator-mxnet/pull/13728)\r\n- update training script with option for gradient accumulation for bert_large model\r\n- update training script to use bucket sampler, which speeds up training by 2x\r\nOther ongoing BERT efforts may also benefit from this PR @fierceX @kenjewu @haven-jeon \r\n\r\n## Checklist ##\r\n### Essentials ###\r\n- [ ] PR's title starts with a category (e.g. [BUGFIX], [MODEL], [TUTORIAL], [FEATURE], [DOC], etc)\r\n- [ ] Changes are complete (i.e. I finished coding on this PR)\r\n- [ ] All changes have test coverage\r\n- [ ] Code is well-documented\r\n\r\n### Changes ###\r\n- [ ] Feature1, tests, (and when applicable, API doc)\r\n- [ ] Feature2, tests, (and when applicable, API doc)\r\n\r\n## Comments ##\r\n- If this change is a backward incompatible change, why must this change be made.\r\n- Interesting edge cases to note here\r\n","created_at":"2018-12-25T19:43:21Z","updated_at":"2018-12-28T06:44:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ca79a47d98dfafcfbc634faa71666fdb6f5997ed","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/482/commits","review_comments_url":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/482/comments","review_comment_url":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dmlc/gluon-nlp/issues/482/comments","statuses_url":"https://api.github.com/repos/dmlc/gluon-nlp/statuses/df63e2c2a4d6b998289c25a38ffec8f4ff647ff4","head":{"label":"eric-haibin-lin:optimizer","ref":"optimizer","sha":"df63e2c2a4d6b998289c25a38ffec8f4ff647ff4","user":{"login":"eric-haibin-lin","id":5545640,"node_id":"MDQ6VXNlcjU1NDU2NDA=","avatar_url":"https://avatars1.githubusercontent.com/u/5545640?v=4","gravatar_id":"","url":"https://api.github.com/users/eric-haibin-lin","html_url":"https://github.com/eric-haibin-lin","followers_url":"https://api.github.com/users/eric-haibin-lin/followers","following_url":"https://api.github.com/users/eric-haibin-lin/following{/other_user}","gists_url":"https://api.github.com/users/eric-haibin-lin/gists{/gist_id}","starred_url":"https://api.github.com/users/eric-haibin-lin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eric-haibin-lin/subscriptions","organizations_url":"https://api.github.com/users/eric-haibin-lin/orgs","repos_url":"https://api.github.com/users/eric-haibin-lin/repos","events_url":"https://api.github.com/users/eric-haibin-lin/events{/privacy}","received_events_url":"https://api.github.com/users/eric-haibin-lin/received_events","type":"User","site_admin":false},"repo":{"id":133543560,"node_id":"MDEwOlJlcG9zaXRvcnkxMzM1NDM1NjA=","name":"gluon-nlp","full_name":"eric-haibin-lin/gluon-nlp","private":false,"owner":{"login":"eric-haibin-lin","id":5545640,"node_id":"MDQ6VXNlcjU1NDU2NDA=","avatar_url":"https://avatars1.githubusercontent.com/u/5545640?v=4","gravatar_id":"","url":"https://api.github.com/users/eric-haibin-lin","html_url":"https://github.com/eric-haibin-lin","followers_url":"https://api.github.com/users/eric-haibin-lin/followers","following_url":"https://api.github.com/users/eric-haibin-lin/following{/other_user}","gists_url":"https://api.github.com/users/eric-haibin-lin/gists{/gist_id}","starred_url":"https://api.github.com/users/eric-haibin-lin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eric-haibin-lin/subscriptions","organizations_url":"https://api.github.com/users/eric-haibin-lin/orgs","repos_url":"https://api.github.com/users/eric-haibin-lin/repos","events_url":"https://api.github.com/users/eric-haibin-lin/events{/privacy}","received_events_url":"https://api.github.com/users/eric-haibin-lin/received_events","type":"User","site_admin":false},"html_url":"https://github.com/eric-haibin-lin/gluon-nlp","description":"NLP made easy","fork":true,"url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp","forks_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/forks","keys_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/teams","hooks_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/hooks","issue_events_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/issues/events{/number}","events_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/events","assignees_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/assignees{/user}","branches_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/branches{/branch}","tags_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/tags","blobs_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/git/refs{/sha}","trees_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/statuses/{sha}","languages_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/languages","stargazers_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/stargazers","contributors_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/contributors","subscribers_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/subscribers","subscription_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/subscription","commits_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/commits{/sha}","git_commits_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/git/commits{/sha}","comments_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/comments{/number}","issue_comment_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/issues/comments{/number}","contents_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/contents/{+path}","compare_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/merges","archive_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/downloads","issues_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/issues{/number}","pulls_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/pulls{/number}","milestones_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/milestones{/number}","notifications_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/labels{/name}","releases_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/releases{/id}","deployments_url":"https://api.github.com/repos/eric-haibin-lin/gluon-nlp/deployments","created_at":"2018-05-15T16:25:43Z","updated_at":"2018-12-03T19:44:48Z","pushed_at":"2018-12-28T06:31:55Z","git_url":"git://github.com/eric-haibin-lin/gluon-nlp.git","ssh_url":"git@github.com:eric-haibin-lin/gluon-nlp.git","clone_url":"https://github.com/eric-haibin-lin/gluon-nlp.git","svn_url":"https://github.com/eric-haibin-lin/gluon-nlp","homepage":"http://gluon-nlp.mxnet.io","size":3482,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"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":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"dmlc:master","ref":"master","sha":"f52339685ee30c128c7878db00772292b58d72be","user":{"login":"dmlc","id":11508361,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNTA4MzYx","avatar_url":"https://avatars2.githubusercontent.com/u/11508361?v=4","gravatar_id":"","url":"https://api.github.com/users/dmlc","html_url":"https://github.com/dmlc","followers_url":"https://api.github.com/users/dmlc/followers","following_url":"https://api.github.com/users/dmlc/following{/other_user}","gists_url":"https://api.github.com/users/dmlc/gists{/gist_id}","starred_url":"https://api.github.com/users/dmlc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmlc/subscriptions","organizations_url":"https://api.github.com/users/dmlc/orgs","repos_url":"https://api.github.com/users/dmlc/repos","events_url":"https://api.github.com/users/dmlc/events{/privacy}","received_events_url":"https://api.github.com/users/dmlc/received_events","type":"Organization","site_admin":false},"repo":{"id":128121076,"node_id":"MDEwOlJlcG9zaXRvcnkxMjgxMjEwNzY=","name":"gluon-nlp","full_name":"dmlc/gluon-nlp","private":false,"owner":{"login":"dmlc","id":11508361,"node_id":"MDEyOk9yZ2FuaXphdGlvbjExNTA4MzYx","avatar_url":"https://avatars2.githubusercontent.com/u/11508361?v=4","gravatar_id":"","url":"https://api.github.com/users/dmlc","html_url":"https://github.com/dmlc","followers_url":"https://api.github.com/users/dmlc/followers","following_url":"https://api.github.com/users/dmlc/following{/other_user}","gists_url":"https://api.github.com/users/dmlc/gists{/gist_id}","starred_url":"https://api.github.com/users/dmlc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmlc/subscriptions","organizations_url":"https://api.github.com/users/dmlc/orgs","repos_url":"https://api.github.com/users/dmlc/repos","events_url":"https://api.github.com/users/dmlc/events{/privacy}","received_events_url":"https://api.github.com/users/dmlc/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/dmlc/gluon-nlp","description":"NLP made easy","fork":false,"url":"https://api.github.com/repos/dmlc/gluon-nlp","forks_url":"https://api.github.com/repos/dmlc/gluon-nlp/forks","keys_url":"https://api.github.com/repos/dmlc/gluon-nlp/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dmlc/gluon-nlp/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dmlc/gluon-nlp/teams","hooks_url":"https://api.github.com/repos/dmlc/gluon-nlp/hooks","issue_events_url":"https://api.github.com/repos/dmlc/gluon-nlp/issues/events{/number}","events_url":"https://api.github.com/repos/dmlc/gluon-nlp/events","assignees_url":"https://api.github.com/repos/dmlc/gluon-nlp/assignees{/user}","branches_url":"https://api.github.com/repos/dmlc/gluon-nlp/branches{/branch}","tags_url":"https://api.github.com/repos/dmlc/gluon-nlp/tags","blobs_url":"https://api.github.com/repos/dmlc/gluon-nlp/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dmlc/gluon-nlp/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dmlc/gluon-nlp/git/refs{/sha}","trees_url":"https://api.github.com/repos/dmlc/gluon-nlp/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dmlc/gluon-nlp/statuses/{sha}","languages_url":"https://api.github.com/repos/dmlc/gluon-nlp/languages","stargazers_url":"https://api.github.com/repos/dmlc/gluon-nlp/stargazers","contributors_url":"https://api.github.com/repos/dmlc/gluon-nlp/contributors","subscribers_url":"https://api.github.com/repos/dmlc/gluon-nlp/subscribers","subscription_url":"https://api.github.com/repos/dmlc/gluon-nlp/subscription","commits_url":"https://api.github.com/repos/dmlc/gluon-nlp/commits{/sha}","git_commits_url":"https://api.github.com/repos/dmlc/gluon-nlp/git/commits{/sha}","comments_url":"https://api.github.com/repos/dmlc/gluon-nlp/comments{/number}","issue_comment_url":"https://api.github.com/repos/dmlc/gluon-nlp/issues/comments{/number}","contents_url":"https://api.github.com/repos/dmlc/gluon-nlp/contents/{+path}","compare_url":"https://api.github.com/repos/dmlc/gluon-nlp/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dmlc/gluon-nlp/merges","archive_url":"https://api.github.com/repos/dmlc/gluon-nlp/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dmlc/gluon-nlp/downloads","issues_url":"https://api.github.com/repos/dmlc/gluon-nlp/issues{/number}","pulls_url":"https://api.github.com/repos/dmlc/gluon-nlp/pulls{/number}","milestones_url":"https://api.github.com/repos/dmlc/gluon-nlp/milestones{/number}","notifications_url":"https://api.github.com/repos/dmlc/gluon-nlp/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dmlc/gluon-nlp/labels{/name}","releases_url":"https://api.github.com/repos/dmlc/gluon-nlp/releases{/id}","deployments_url":"https://api.github.com/repos/dmlc/gluon-nlp/deployments","created_at":"2018-04-04T20:57:13Z","updated_at":"2018-12-28T06:04:42Z","pushed_at":"2018-12-28T06:31:57Z","git_url":"git://github.com/dmlc/gluon-nlp.git","ssh_url":"git@github.com:dmlc/gluon-nlp.git","clone_url":"https://github.com/dmlc/gluon-nlp.git","svn_url":"https://github.com/dmlc/gluon-nlp","homepage":"http://gluon-nlp.mxnet.io","size":6244,"stargazers_count":1194,"watchers_count":1194,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":243,"mirror_url":null,"archived":false,"open_issues_count":76,"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":243,"open_issues":76,"watchers":1194,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/482"},"html":{"href":"https://github.com/dmlc/gluon-nlp/pull/482"},"issue":{"href":"https://api.github.com/repos/dmlc/gluon-nlp/issues/482"},"comments":{"href":"https://api.github.com/repos/dmlc/gluon-nlp/issues/482/comments"},"review_comments":{"href":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/482/comments"},"review_comment":{"href":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dmlc/gluon-nlp/pulls/482/commits"},"statuses":{"href":"https://api.github.com/repos/dmlc/gluon-nlp/statuses/df63e2c2a4d6b998289c25a38ffec8f4ff647ff4"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"szha"}}