{"action":"created","comment":{"url":"https://api.github.com/repos/microsoft/nni/pulls/comments/342402443","pull_request_review_id":311527385,"id":342402443,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDM0MjQwMjQ0Mw==","diff_hunk":"@@ -0,0 +1,103 @@\n+import torch\n+import torch.nn.functional as F\n+from torchvision import datasets, transforms\n+from nni.compression.torch import QAT_Quantizer\n+\n+\n+class Mnist(torch.nn.Module):\n+    def __init__(self):\n+        super().__init__()\n+        self.conv1 = torch.nn.Conv2d(1, 20, 5, 1)\n+        self.conv2 = torch.nn.Conv2d(20, 50, 5, 1)\n+        self.fc1 = torch.nn.Linear(4 * 4 * 50, 500)\n+        self.fc2 = torch.nn.Linear(500, 10)\n+        self.relu1 = torch.nn.ReLU6()\n+        self.relu2 = torch.nn.ReLU6()\n+        self.relu3 = torch.nn.ReLU6()\n+\n+    def forward(self, x):\n+        x = self.relu1(self.conv1(x))\n+        x = F.max_pool2d(x, 2, 2)\n+        x = self.relu2(self.conv2(x))\n+        x = F.max_pool2d(x, 2, 2)\n+        x = x.view(-1, 4 * 4 * 50)\n+        x = self.relu3(self.fc1(x))\n+        x = self.fc2(x)\n+        return F.log_softmax(x, dim=1)\n+\n+\n+def train(model, quantizer, device, train_loader, optimizer):\n+    model.train()\n+    for batch_idx, (data, target) in enumerate(train_loader):\n+        data, target = data.to(device), target.to(device)\n+        optimizer.zero_grad()\n+        output = model(data)\n+        loss = F.nll_loss(output, target)\n+        loss.backward()\n+        optimizer.step()\n+        quantizer.step()\n+        if batch_idx % 100 == 0:\n+            print('{:2.0f}%  Loss {}'.format(100 * batch_idx / len(train_loader), loss.item()))\n+\n+def test(model, device, test_loader):\n+    model.eval()\n+    test_loss = 0\n+    correct = 0\n+    with torch.no_grad():\n+        for data, target in test_loader:\n+            data, target = data.to(device), target.to(device)\n+            output = model(data)\n+            test_loss += F.nll_loss(output, target, reduction='sum').item()\n+            pred = output.argmax(dim=1, keepdim=True)\n+            correct += pred.eq(target.view_as(pred)).sum().item()\n+    test_loss /= len(test_loader.dataset)\n+\n+    print('Loss: {}  Accuracy: {}%)\\n'.format(\n+        test_loss, 100 * correct / len(test_loader.dataset)))\n+\n+def main():\n+    torch.manual_seed(0)\n+    device = torch.device('cpu')\n+\n+    trans = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.1307,), (0.3081,))])\n+    train_loader = torch.utils.data.DataLoader(\n+        datasets.MNIST('data', train=True, download=True, transform=trans),\n+        batch_size=64, shuffle=True)\n+    test_loader = torch.utils.data.DataLoader(\n+        datasets.MNIST('data', train=False, transform=trans),\n+        batch_size=1000, shuffle=True)\n+\n+    model = Mnist()\n+\n+    '''you can change this to DoReFaQuantizer to implement it\n+    DoReFaQuantizer(configure_list).compress(model)\n+    '''\n+    configure_list = [{\n+        'quant_types': ['weight'],\n+        'quant_bits': {\n+            'weight': 8,\n+        },\n+        'quant_delay': 7000,","path":"examples/model_compress/QAT_torch_quantizer.py","position":80,"original_position":80,"commit_id":"28976137f70b992ba30d62401865ec946131e2d2","original_commit_id":"28976137f70b992ba30d62401865ec946131e2d2","user":{"login":"QuanluZhang","id":16907603,"node_id":"MDQ6VXNlcjE2OTA3NjAz","avatar_url":"https://avatars1.githubusercontent.com/u/16907603?v=4","gravatar_id":"","url":"https://api.github.com/users/QuanluZhang","html_url":"https://github.com/QuanluZhang","followers_url":"https://api.github.com/users/QuanluZhang/followers","following_url":"https://api.github.com/users/QuanluZhang/following{/other_user}","gists_url":"https://api.github.com/users/QuanluZhang/gists{/gist_id}","starred_url":"https://api.github.com/users/QuanluZhang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/QuanluZhang/subscriptions","organizations_url":"https://api.github.com/users/QuanluZhang/orgs","repos_url":"https://api.github.com/users/QuanluZhang/repos","events_url":"https://api.github.com/users/QuanluZhang/events{/privacy}","received_events_url":"https://api.github.com/users/QuanluZhang/received_events","type":"User","site_admin":false},"body":"please update the doc to briefly describe this quantizer, and the supported fields of this quantizer.","created_at":"2019-11-05T06:49:07Z","updated_at":"2019-11-05T06:49:08Z","html_url":"https://github.com/microsoft/nni/pull/1698#discussion_r342402443","pull_request_url":"https://api.github.com/repos/microsoft/nni/pulls/1698","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/microsoft/nni/pulls/comments/342402443"},"html":{"href":"https://github.com/microsoft/nni/pull/1698#discussion_r342402443"},"pull_request":{"href":"https://api.github.com/repos/microsoft/nni/pulls/1698"}}},"pull_request":{"url":"https://api.github.com/repos/microsoft/nni/pulls/1698","id":336135678,"node_id":"MDExOlB1bGxSZXF1ZXN0MzM2MTM1Njc4","html_url":"https://github.com/microsoft/nni/pull/1698","diff_url":"https://github.com/microsoft/nni/pull/1698.diff","patch_url":"https://github.com/microsoft/nni/pull/1698.patch","issue_url":"https://api.github.com/repos/microsoft/nni/issues/1698","number":1698,"state":"open","locked":false,"title":"quantization_api_refactor","user":{"login":"Cjkkkk","id":25362393,"node_id":"MDQ6VXNlcjI1MzYyMzkz","avatar_url":"https://avatars0.githubusercontent.com/u/25362393?v=4","gravatar_id":"","url":"https://api.github.com/users/Cjkkkk","html_url":"https://github.com/Cjkkkk","followers_url":"https://api.github.com/users/Cjkkkk/followers","following_url":"https://api.github.com/users/Cjkkkk/following{/other_user}","gists_url":"https://api.github.com/users/Cjkkkk/gists{/gist_id}","starred_url":"https://api.github.com/users/Cjkkkk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cjkkkk/subscriptions","organizations_url":"https://api.github.com/users/Cjkkkk/orgs","repos_url":"https://api.github.com/users/Cjkkkk/repos","events_url":"https://api.github.com/users/Cjkkkk/events{/privacy}","received_events_url":"https://api.github.com/users/Cjkkkk/received_events","type":"User","site_admin":false},"body":"","created_at":"2019-11-04T06:25:19Z","updated_at":"2019-11-05T06:49:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cdd75e114593ee221b1fc0b7318c01411b04dc40","assignee":null,"assignees":[],"requested_reviewers":[{"login":"chicm-ms","id":38930155,"node_id":"MDQ6VXNlcjM4OTMwMTU1","avatar_url":"https://avatars1.githubusercontent.com/u/38930155?v=4","gravatar_id":"","url":"https://api.github.com/users/chicm-ms","html_url":"https://github.com/chicm-ms","followers_url":"https://api.github.com/users/chicm-ms/followers","following_url":"https://api.github.com/users/chicm-ms/following{/other_user}","gists_url":"https://api.github.com/users/chicm-ms/gists{/gist_id}","starred_url":"https://api.github.com/users/chicm-ms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chicm-ms/subscriptions","organizations_url":"https://api.github.com/users/chicm-ms/orgs","repos_url":"https://api.github.com/users/chicm-ms/repos","events_url":"https://api.github.com/users/chicm-ms/events{/privacy}","received_events_url":"https://api.github.com/users/chicm-ms/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/microsoft/nni/pulls/1698/commits","review_comments_url":"https://api.github.com/repos/microsoft/nni/pulls/1698/comments","review_comment_url":"https://api.github.com/repos/microsoft/nni/pulls/comments{/number}","comments_url":"https://api.github.com/repos/microsoft/nni/issues/1698/comments","statuses_url":"https://api.github.com/repos/microsoft/nni/statuses/28976137f70b992ba30d62401865ec946131e2d2","head":{"label":"Cjkkkk:master","ref":"master","sha":"28976137f70b992ba30d62401865ec946131e2d2","user":{"login":"Cjkkkk","id":25362393,"node_id":"MDQ6VXNlcjI1MzYyMzkz","avatar_url":"https://avatars0.githubusercontent.com/u/25362393?v=4","gravatar_id":"","url":"https://api.github.com/users/Cjkkkk","html_url":"https://github.com/Cjkkkk","followers_url":"https://api.github.com/users/Cjkkkk/followers","following_url":"https://api.github.com/users/Cjkkkk/following{/other_user}","gists_url":"https://api.github.com/users/Cjkkkk/gists{/gist_id}","starred_url":"https://api.github.com/users/Cjkkkk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cjkkkk/subscriptions","organizations_url":"https://api.github.com/users/Cjkkkk/orgs","repos_url":"https://api.github.com/users/Cjkkkk/repos","events_url":"https://api.github.com/users/Cjkkkk/events{/privacy}","received_events_url":"https://api.github.com/users/Cjkkkk/received_events","type":"User","site_admin":false},"repo":{"id":218706901,"node_id":"MDEwOlJlcG9zaXRvcnkyMTg3MDY5MDE=","name":"nni","full_name":"Cjkkkk/nni","private":false,"owner":{"login":"Cjkkkk","id":25362393,"node_id":"MDQ6VXNlcjI1MzYyMzkz","avatar_url":"https://avatars0.githubusercontent.com/u/25362393?v=4","gravatar_id":"","url":"https://api.github.com/users/Cjkkkk","html_url":"https://github.com/Cjkkkk","followers_url":"https://api.github.com/users/Cjkkkk/followers","following_url":"https://api.github.com/users/Cjkkkk/following{/other_user}","gists_url":"https://api.github.com/users/Cjkkkk/gists{/gist_id}","starred_url":"https://api.github.com/users/Cjkkkk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Cjkkkk/subscriptions","organizations_url":"https://api.github.com/users/Cjkkkk/orgs","repos_url":"https://api.github.com/users/Cjkkkk/repos","events_url":"https://api.github.com/users/Cjkkkk/events{/privacy}","received_events_url":"https://api.github.com/users/Cjkkkk/received_events","type":"User","site_admin":false},"html_url":"https://github.com/Cjkkkk/nni","description":"An open source AutoML toolkit for neural architecture search and hyper-parameter tuning.","fork":true,"url":"https://api.github.com/repos/Cjkkkk/nni","forks_url":"https://api.github.com/repos/Cjkkkk/nni/forks","keys_url":"https://api.github.com/repos/Cjkkkk/nni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Cjkkkk/nni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Cjkkkk/nni/teams","hooks_url":"https://api.github.com/repos/Cjkkkk/nni/hooks","issue_events_url":"https://api.github.com/repos/Cjkkkk/nni/issues/events{/number}","events_url":"https://api.github.com/repos/Cjkkkk/nni/events","assignees_url":"https://api.github.com/repos/Cjkkkk/nni/assignees{/user}","branches_url":"https://api.github.com/repos/Cjkkkk/nni/branches{/branch}","tags_url":"https://api.github.com/repos/Cjkkkk/nni/tags","blobs_url":"https://api.github.com/repos/Cjkkkk/nni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Cjkkkk/nni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Cjkkkk/nni/git/refs{/sha}","trees_url":"https://api.github.com/repos/Cjkkkk/nni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Cjkkkk/nni/statuses/{sha}","languages_url":"https://api.github.com/repos/Cjkkkk/nni/languages","stargazers_url":"https://api.github.com/repos/Cjkkkk/nni/stargazers","contributors_url":"https://api.github.com/repos/Cjkkkk/nni/contributors","subscribers_url":"https://api.github.com/repos/Cjkkkk/nni/subscribers","subscription_url":"https://api.github.com/repos/Cjkkkk/nni/subscription","commits_url":"https://api.github.com/repos/Cjkkkk/nni/commits{/sha}","git_commits_url":"https://api.github.com/repos/Cjkkkk/nni/git/commits{/sha}","comments_url":"https://api.github.com/repos/Cjkkkk/nni/comments{/number}","issue_comment_url":"https://api.github.com/repos/Cjkkkk/nni/issues/comments{/number}","contents_url":"https://api.github.com/repos/Cjkkkk/nni/contents/{+path}","compare_url":"https://api.github.com/repos/Cjkkkk/nni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Cjkkkk/nni/merges","archive_url":"https://api.github.com/repos/Cjkkkk/nni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Cjkkkk/nni/downloads","issues_url":"https://api.github.com/repos/Cjkkkk/nni/issues{/number}","pulls_url":"https://api.github.com/repos/Cjkkkk/nni/pulls{/number}","milestones_url":"https://api.github.com/repos/Cjkkkk/nni/milestones{/number}","notifications_url":"https://api.github.com/repos/Cjkkkk/nni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Cjkkkk/nni/labels{/name}","releases_url":"https://api.github.com/repos/Cjkkkk/nni/releases{/id}","deployments_url":"https://api.github.com/repos/Cjkkkk/nni/deployments","created_at":"2019-10-31T07:18:46Z","updated_at":"2019-11-05T06:42:41Z","pushed_at":"2019-11-05T06:42:39Z","git_url":"git://github.com/Cjkkkk/nni.git","ssh_url":"git@github.com:Cjkkkk/nni.git","clone_url":"https://github.com/Cjkkkk/nni.git","svn_url":"https://github.com/Cjkkkk/nni","homepage":"https://nni.readthedocs.io/en/latest/","size":47207,"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,"disabled":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"microsoft:master","ref":"master","sha":"6210625b9225a13518b74ca50b87a0f648a325b4","user":{"login":"microsoft","id":6154722,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYxNTQ3MjI=","avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/microsoft","html_url":"https://github.com/microsoft","followers_url":"https://api.github.com/users/microsoft/followers","following_url":"https://api.github.com/users/microsoft/following{/other_user}","gists_url":"https://api.github.com/users/microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/microsoft/subscriptions","organizations_url":"https://api.github.com/users/microsoft/orgs","repos_url":"https://api.github.com/users/microsoft/repos","events_url":"https://api.github.com/users/microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":135673451,"node_id":"MDEwOlJlcG9zaXRvcnkxMzU2NzM0NTE=","name":"nni","full_name":"microsoft/nni","private":false,"owner":{"login":"microsoft","id":6154722,"node_id":"MDEyOk9yZ2FuaXphdGlvbjYxNTQ3MjI=","avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/microsoft","html_url":"https://github.com/microsoft","followers_url":"https://api.github.com/users/microsoft/followers","following_url":"https://api.github.com/users/microsoft/following{/other_user}","gists_url":"https://api.github.com/users/microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/microsoft/subscriptions","organizations_url":"https://api.github.com/users/microsoft/orgs","repos_url":"https://api.github.com/users/microsoft/repos","events_url":"https://api.github.com/users/microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/microsoft/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/microsoft/nni","description":"An open source AutoML toolkit for neural architecture search and hyper-parameter tuning.","fork":false,"url":"https://api.github.com/repos/microsoft/nni","forks_url":"https://api.github.com/repos/microsoft/nni/forks","keys_url":"https://api.github.com/repos/microsoft/nni/keys{/key_id}","collaborators_url":"https://api.github.com/repos/microsoft/nni/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/microsoft/nni/teams","hooks_url":"https://api.github.com/repos/microsoft/nni/hooks","issue_events_url":"https://api.github.com/repos/microsoft/nni/issues/events{/number}","events_url":"https://api.github.com/repos/microsoft/nni/events","assignees_url":"https://api.github.com/repos/microsoft/nni/assignees{/user}","branches_url":"https://api.github.com/repos/microsoft/nni/branches{/branch}","tags_url":"https://api.github.com/repos/microsoft/nni/tags","blobs_url":"https://api.github.com/repos/microsoft/nni/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/microsoft/nni/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/microsoft/nni/git/refs{/sha}","trees_url":"https://api.github.com/repos/microsoft/nni/git/trees{/sha}","statuses_url":"https://api.github.com/repos/microsoft/nni/statuses/{sha}","languages_url":"https://api.github.com/repos/microsoft/nni/languages","stargazers_url":"https://api.github.com/repos/microsoft/nni/stargazers","contributors_url":"https://api.github.com/repos/microsoft/nni/contributors","subscribers_url":"https://api.github.com/repos/microsoft/nni/subscribers","subscription_url":"https://api.github.com/repos/microsoft/nni/subscription","commits_url":"https://api.github.com/repos/microsoft/nni/commits{/sha}","git_commits_url":"https://api.github.com/repos/microsoft/nni/git/commits{/sha}","comments_url":"https://api.github.com/repos/microsoft/nni/comments{/number}","issue_comment_url":"https://api.github.com/repos/microsoft/nni/issues/comments{/number}","contents_url":"https://api.github.com/repos/microsoft/nni/contents/{+path}","compare_url":"https://api.github.com/repos/microsoft/nni/compare/{base}...{head}","merges_url":"https://api.github.com/repos/microsoft/nni/merges","archive_url":"https://api.github.com/repos/microsoft/nni/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/microsoft/nni/downloads","issues_url":"https://api.github.com/repos/microsoft/nni/issues{/number}","pulls_url":"https://api.github.com/repos/microsoft/nni/pulls{/number}","milestones_url":"https://api.github.com/repos/microsoft/nni/milestones{/number}","notifications_url":"https://api.github.com/repos/microsoft/nni/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/microsoft/nni/labels{/name}","releases_url":"https://api.github.com/repos/microsoft/nni/releases{/id}","deployments_url":"https://api.github.com/repos/microsoft/nni/deployments","created_at":"2018-06-01T05:51:44Z","updated_at":"2019-11-05T06:27:19Z","pushed_at":"2019-11-05T06:46:14Z","git_url":"git://github.com/microsoft/nni.git","ssh_url":"git@github.com:microsoft/nni.git","clone_url":"https://github.com/microsoft/nni.git","svn_url":"https://github.com/microsoft/nni","homepage":"https://nni.readthedocs.io/en/latest/","size":24622,"stargazers_count":3518,"watchers_count":3518,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":483,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":135,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":483,"open_issues":135,"watchers":3518,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/microsoft/nni/pulls/1698"},"html":{"href":"https://github.com/microsoft/nni/pull/1698"},"issue":{"href":"https://api.github.com/repos/microsoft/nni/issues/1698"},"comments":{"href":"https://api.github.com/repos/microsoft/nni/issues/1698/comments"},"review_comments":{"href":"https://api.github.com/repos/microsoft/nni/pulls/1698/comments"},"review_comment":{"href":"https://api.github.com/repos/microsoft/nni/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/microsoft/nni/pulls/1698/commits"},"statuses":{"href":"https://api.github.com/repos/microsoft/nni/statuses/28976137f70b992ba30d62401865ec946131e2d2"}},"author_association":"NONE"}}
{"actor":{"display_login":"QuanluZhang"}}