{"id":17998877,"url":"https://github.com/szagoruyko/binary-wide-resnet","last_synced_at":"2025-07-28T23:35:01.383Z","repository":{"id":82253332,"uuid":"146195262","full_name":"szagoruyko/binary-wide-resnet","owner":"szagoruyko","description":"PyTorch implementation of Wide Residual Networks with 1-bit weights by McDonnell (ICLR 2018)","archived":false,"fork":false,"pushed_at":"2018-09-06T12:59:12.000Z","size":13,"stargazers_count":123,"open_issues_count":2,"forks_count":15,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-07T01:40:07.956Z","etag":null,"topics":["pytorch","wide-residual-networks"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/szagoruyko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-26T16:03:17.000Z","updated_at":"2025-04-03T02:21:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"759327e9-9875-44f6-8d52-b2f8720eb26f","html_url":"https://github.com/szagoruyko/binary-wide-resnet","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/szagoruyko/binary-wide-resnet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szagoruyko%2Fbinary-wide-resnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szagoruyko%2Fbinary-wide-resnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szagoruyko%2Fbinary-wide-resnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szagoruyko%2Fbinary-wide-resnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/szagoruyko","download_url":"https://codeload.github.com/szagoruyko/binary-wide-resnet/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/szagoruyko%2Fbinary-wide-resnet/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267604408,"owners_count":24114532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pytorch","wide-residual-networks"],"created_at":"2024-10-29T22:08:54.882Z","updated_at":"2025-07-28T23:35:01.336Z","avatar_url":"https://github.com/szagoruyko.png","language":"Python","funding_links":[],"categories":["Paper implementations｜论文实现","Paper implementations"],"sub_categories":["Other libraries｜其他库:","Other libraries:"],"readme":"1-bit Wide ResNet\n===========\n\nPyTorch implementation of training 1-bit Wide ResNets from this paper:\n\n*Training wide residual networks for deployment using a single bit for each weight* by **Mark D. McDonnell** at ICLR 2018\n\n\u003chttps://openreview.net/forum?id=rytNfI1AZ\u003e\n\n\u003chttps://arxiv.org/abs/1802.08530\u003e\n\nThe idea is very simple but surprisingly effective for training ResNets with binary weights. Here is the proposed weight parameterization as PyTorch autograd function:\n\n```python\nclass ForwardSign(torch.autograd.Function):\n    @staticmethod\n    def forward(ctx, w):\n        return math.sqrt(2. / (w.shape[1] * w.shape[2] * w.shape[3])) * w.sign()\n\n    @staticmethod\n    def backward(ctx, g):\n        return g\n```\n\nOn forward, we take sign of the weights and scale it by He-init constant. On backward, we propagate gradient without changes. WRN-20-10 trained with such parameterization is only slightly off from it's full precision variant, here is what I got myself with this code on CIFAR-100:\n\n| network | accuracy (5 runs mean +- std) | checkpoint (Mb) |\n|:---|:---:|:---:|\n| WRN-20-10 | 80.5 +- 0.24 | 205 Mb |\n| WRN-20-10-1bit | 80.0 +- 0.26 | 3.5 Mb |\n\n## Details\n\nHere are the differences with WRN code \u003chttps://github.com/szagoruyko/wide-residual-networks\u003e:\n\n* BatchNorm has no affine weight and bias parameters\n* First layer has 16 * width channels\n* Last fc layer is removed in favor of 1x1 conv + F.avg_pool2d\n* Downsample is done by F.avg_pool2d + torch.cat instead of strided conv\n* SGD with cosine annealing and warm restarts\n\nI used PyTorch 0.4.1 and Python 3.6 to run the code.\n\nReproduce WRN-20-10 with 1-bit training on CIFAR-100:\n\n```bash\npython main.py --binarize --save ./logs/WRN-20-10-1bit_$RANDOM --width 10 --dataset CIFAR100\n```\n\nConvergence plot (train error in dash):\n\n\u003cimg width=\"950\" alt=\"download\" src=\"https://user-images.githubusercontent.com/4953728/44685365-968ea500-aa4b-11e8-8615-684120f13953.png\"\u003e\n\nI've also put 3.5 Mb checkpoint with binary weights packed with `np.packbits`, and a very short script to evaluate it:\n\n```bash\npython evaluate_packed.py --checkpoint wrn20-10-1bit-packed.pth.tar --width 10 --dataset CIFAR100\n```\n\nS3 url to checkpoint: \u003chttps://s3.amazonaws.com/modelzoo-networks/wrn20-10-1bit-packed.pth.tar\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszagoruyko%2Fbinary-wide-resnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fszagoruyko%2Fbinary-wide-resnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fszagoruyko%2Fbinary-wide-resnet/lists"}