{"notes":[{"id":"contrastive-learning/moco-v2","category":"contrastive-learning","legacyPath":"contrastive-learning/2003-moco-v2","legacySlug":"2003-moco-v2","legacyPaths":[],"title":"MoCo v2","subtitle":"A Comeback","author":"Z. Yuan","paperDate":"2020-03-09","publishedOn":"2025-02-10","paperTitle":"Improved Baselines with Momentum Contrastive Learning","paperUrl":"https://arxiv.org/abs/2003.04297","bibliography":{"title":"Improved Baselines with Momentum Contrastive Learning","authors":["Xinlei Chen","Haoqi Fan","Ross Girshick","Kaiming He"],"url":"https://arxiv.org/abs/2003.04297","pdfUrl":"https://arxiv.org/pdf/2003.04297","codeUrl":null,"preprint":{"id":"2003.04297","submittedOn":"2020-03-09","url":"https://arxiv.org/abs/2003.04297"},"publication":null,"citation":"@misc{contrastivelearningmocov22020,\n  title = {{Improved Baselines with Momentum Contrastive Learning}},\n  author = {Xinlei Chen and Haoqi Fan and Ross Girshick and Kaiming He},\n  year = {2020},\n  eprint = {2003.04297},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2003.04297}\n}\n","citationPath":"/content/papers/citations/contrastive-learning/moco-v2.3bd1c733148f.bib"},"thumbnail":{"src":"/content/papers/assets/0f817bf1235f2d95a4b7dbd5953fe29dfb2a5e0dd2f4890364d922d50c45d371.jpg","width":1200,"height":952},"locale":"en","path":"/content/papers/en/contrastive-learning/moco-v2.475f43e9d6fa.md","headings":[{"id":"problem-definition","text":"Problem Definition","depth":2},{"id":"solution","text":"Solution","depth":2},{"id":"enhanced-mlp-head","text":"Enhanced MLP Head","depth":3},{"id":"stronger-data-augmentation","text":"Stronger Data Augmentation","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"comparison-with-simclr","text":"Comparison with SimCLR","depth":3},{"id":"computational-load-and-resource-consumption","text":"Computational Load and Resource Consumption","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"contrastive-learning/moco-v1","relation":"background","topic":"Instance discrimination and momentum encoders"},{"id":"contrastive-learning/moco-v3","relation":"next","topic":"Instance discrimination and momentum encoders"}]},{"id":"contrastive-learning/moco-v1","category":"contrastive-learning","legacyPath":"contrastive-learning/1911-moco-v1","legacySlug":"1911-moco-v1","legacyPaths":[],"title":"MoCo v1","subtitle":"Momentum Contrastive Learning","author":"Z. Yuan","paperDate":"2019-11-13","publishedOn":"2025-02-02","paperTitle":"Momentum Contrast for Unsupervised Visual Representation Learning","paperUrl":"https://arxiv.org/abs/1911.05722","bibliography":{"title":"Momentum Contrast for Unsupervised Visual Representation Learning","authors":["Kaiming He","Haoqi Fan","Yuxin Wu","Saining Xie","Ross Girshick"],"url":"https://arxiv.org/abs/1911.05722","pdfUrl":"https://arxiv.org/pdf/1911.05722","codeUrl":"https://github.com/facebookresearch/moco","preprint":{"id":"1911.05722","submittedOn":"2019-11-13","url":"https://arxiv.org/abs/1911.05722"},"publication":{"venue":"CVPR","year":2020,"kind":"conference","url":"https://arxiv.org/abs/1911.05722"},"citation":"@misc{contrastivelearningmocov12019,\n  title = {{Momentum Contrast for Unsupervised Visual Representation Learning}},\n  author = {Kaiming He and Haoqi Fan and Yuxin Wu and Saining Xie and Ross Girshick},\n  year = {2019},\n  eprint = {1911.05722},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/1911.05722}\n}\n","citationPath":"/content/papers/citations/contrastive-learning/moco-v1.071856b9c037.bib"},"thumbnail":{"src":"/content/papers/assets/3a4882b957f17e3a6602961426e26fff6695a72aaeb56af2cebae22324f4018b.jpg","width":668,"height":540},"locale":"en","path":"/content/papers/en/contrastive-learning/moco-v1.14d2734486dd.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"algorithm-design","text":"Algorithm Design","depth":3},{"id":"pretext-task","text":"Pretext Task","depth":3},{"id":"discussion","text":"Discussion","depth":2},{"id":"feature-robustness","text":"Feature Robustness","depth":3},{"id":"impact-of-the-momentum-coefficient","text":"Impact of the Momentum Coefficient","depth":3},{"id":"comparison-with-other-methods","text":"Comparison with Other Methods","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"contrastive-learning/instdisc","relation":"background","topic":"Instance discrimination and momentum encoders"},{"id":"contrastive-learning/moco-v2","relation":"next","topic":"Instance discrimination and momentum encoders"}]},{"id":"contrastive-learning/moco-v3","category":"contrastive-learning","legacyPath":"contrastive-learning/2104-moco-v3","legacySlug":"2104-moco-v3","legacyPaths":[],"title":"MoCo v3","subtitle":"ViT Expedition Team","author":"Z. Yuan","paperDate":"2021-04-05","publishedOn":"2025-03-17","paperTitle":"An Empirical Study of Training Self-Supervised Vision Transformers","paperUrl":"https://arxiv.org/abs/2104.02057","bibliography":{"title":"An Empirical Study of Training Self-Supervised Vision Transformers","authors":["Xinlei Chen","Saining Xie","Kaiming He"],"url":"https://arxiv.org/abs/2104.02057","pdfUrl":"https://arxiv.org/pdf/2104.02057","codeUrl":"https://github.com/facebookresearch/moco-v3","preprint":{"id":"2104.02057","submittedOn":"2021-04-05","url":"https://arxiv.org/abs/2104.02057"},"publication":{"venue":"ICCV","year":2021,"kind":"conference","url":"https://arxiv.org/abs/2104.02057"},"citation":"@misc{contrastivelearningmocov32021,\n  title = {{An Empirical Study of Training Self-Supervised Vision Transformers}},\n  author = {Xinlei Chen and Saining Xie and Kaiming He},\n  year = {2021},\n  eprint = {2104.02057},\n  archivePrefix = {arXiv},\n  url = {https://arxiv.org/abs/2104.02057}\n}\n","citationPath":"/content/papers/citations/contrastive-learning/moco-v3.d8d03aec8967.bib"},"thumbnail":{"src":"/content/papers/assets/8cf8823ec857fb1ddda584da819f74f03009421d9ae70bab3c29052f280864e3.jpg","width":1040,"height":936},"locale":"en","path":"/content/papers/en/contrastive-learning/moco-v3.efb1b66b84c7.md","headings":[{"id":"defining-the-problem","text":"Defining the Problem","depth":2},{"id":"solving-the-problem","text":"Solving the Problem","depth":2},{"id":"discussion","text":"Discussion","depth":2},{"id":"vit-instability","text":"ViT Instability","depth":3},{"id":"solving-vit-instability-issues","text":"Solving ViT Instability Issues","depth":3},{"id":"comparison-of-self-supervised-learning-frameworks","text":"Comparison of Self-Supervised Learning Frameworks","depth":3},{"id":"ablation-study","text":"Ablation Study","depth":3},{"id":"comparison-with-other-methods","text":"Comparison with Other Methods","depth":3},{"id":"conclusion","text":"Conclusion","depth":2}],"anchorAliases":{},"guide":null,"relatedReading":[{"id":"contrastive-learning/moco-v2","relation":"background","topic":"Instance discrimination and momentum encoders"}]}],"text":"FAIR introduced MoCo v1, but before they could even enjoy their success, Google presented SimCLR, which showed a significant performance boost!\n\nThat landed quite a punch on FAIR. Surely they could not leave it there! About a month after SimCLR, FAIR took some of its good ideas and released MoCo v2. At least, that is how I picture this research exchange.\n\nThe message was clear: MoCo could still be the better choice!\n\n\n> [!TIP]\n> \n> The main comparison in this paper is with SimCLR, and interested readers can refer to our previous article:\n> \n> - [**[20.02] SimCLR v1: Winning with Batch Size**](/blog/papers/contrastive-learning/simclr-v1)\n\n\n## Problem Definition\n\nSimCLR made three major improvements in its implementation:\n\n1. **Very large batch sizes** (4k or 8k), ensuring a sufficient number of negative samples.\n2. **MLP head**: The output features of the encoder are passed through a 2-layer MLP (with ReLU) before applying contrastive loss. After training, the encoder’s output (without the MLP output) is usually used for downstream tasks.\n3. **Stronger data augmentation**: This includes stronger color jittering, blurring, etc.\n\nHowever, despite the excellent performance, the batch size in SimCLR is really too large, and most people cannot run it.\n\n\n> [!TIP]\n> \n> Google, with its ample resources, can use TPUs to handle 4k or 8k batch sizes.\n\n\nThus, the authors in this paper attempt to integrate SimCLR’s two major improvements into MoCo:\n\n1. **MLP projection head**\n2. **Stronger data augmentation**\n\nThey found that these improvements are also effective within the MoCo framework and can achieve results surpassing SimCLR even in a typical 8-GPU environment (without requiring ultra-large batch sizes).\n\nThis is clearly more user-friendly for general users and makes contrastive learning research easier to reproduce.\n\n## Solution\n\n\n\n![Figure 1: end-to-end versus momentum-contrast negative-key maintenance](/content/papers/assets/0f817bf1235f2d95a4b7dbd5953fe29dfb2a5e0dd2f4890364d922d50c45d371.jpg)\n\n\n\nThe diagram above shows the architectural differences between SimCLR and MoCo.\n\nSimCLR is an end-to-end mechanism, requiring a batch with enough negative samples, typically requiring a batch size of 4k to 8k.\n\nIn contrast, MoCo uses a momentum encoder to generate relatively consistent key representations. The negative keys are stored in a queue shared across batches. Even with a small batch, that queue can provide plenty of negatives.\n\nThus, MoCo does not need large batches to retain many negative samples and requires fewer hardware resources.\n\n### Enhanced MLP Head\n\n\n\n![Table 1: MoCo ablation of MLP, extra augmentation and cosine schedule, with the baseline and MLP-only ImageNet results circled](/content/papers/assets/5899b629eb7547a399e603fbac53478341999614cf58f4c2a3acc2f3fb4f6d70.jpg)\n\n\n\nThe authors replaced the original fully connected (fc) projection head in MoCo with a 2-layer MLP (2048 units in the intermediate layer, with ReLU), testing different temperature parameters $\\tau$.\n\nThe authors report the temperature sweep in the text, separately from the table above. At $\\tau=0.07$, replacing fc with MLP raises ImageNet linear accuracy from **60.6% to 62.9%**. With the MLP and $\\tau=0.2$, it reaches **66.2%**. Table 1 compares this tuned setting with the baseline; it does not show the temperature sweep.\n\nHowever, in transfer learning for object detection, the improvement from the MLP head is smaller. This raises a common question:\n\n- **\"Is a higher linear classification score always better? Does it directly correlate with actual downstream tasks?\"**\n\nSometimes, this is not entirely true. Linear classification scores are a reference indicator; evaluate each downstream task separately.\n\n### Stronger Data Augmentation\n\n\n\n![Table 1: the same ablation, highlighting MLP alone and MLP plus blur augmentation](/content/papers/assets/a228b5588f1d96f67a3b8ef0b2acc1e6ef40cca1ab2cc7e1ed67efd7e6f3d71d.jpg)\n\n\n\nThe augmentation change highlighted here is Gaussian blur from SimCLR. The authors also tested stronger color distortion but reported limited additional benefit. Without the MLP, the revised augmentation raises ImageNet linear accuracy from 60.6% to 63.4%; the detection gain is comparable to or greater than that of adding the MLP.\n\nWith both MLP and stronger augmentation, ImageNet linear accuracy reaches **67.3%**, and detection improves too. Interestingly, blur augmentation alone gives better VOC detection AP than the MLP alone, although its ImageNet linear score is lower. The later **67.5%** result also adds a cosine learning-rate schedule.\n\n## Discussion\n\n### Comparison with SimCLR\n\n\n\n![Table 2: ImageNet linear accuracy of MoCo and SimCLR at different batch sizes and pretraining durations](/content/papers/assets/27904ebbfb9ea0c997892e7b7ee46286d397101590ed563b6a827856cff6a522.jpg)\n\n\n\nIn the longer-run comparison here, SimCLR uses batch size 4096 for 1000 epochs and reaches 69.3% ImageNet linear accuracy.\n\nThe authors integrated the MLP head, stronger augmentation and cosine learning-rate schedule into MoCo under a more feasible hardware setup (8-GPU, batch size = 256), creating \"MoCo v2.\"\n\nThe results show:\n\n- At 200 epochs and batch size 256, MoCo v2 reaches 67.5%, 5.6 percentage points above SimCLR’s 61.9% under those same two conditions. It also exceeds SimCLR’s 66.6% at 200 epochs with batch size 8192.\n- At 800 epochs and batch size 256, MoCo v2 reaches 71.1%, above SimCLR’s 69.3% at 1000 epochs and batch size 4096. Those two longer runs differ in both duration and batch size, so they are not a matched-setting comparison.\n\nIn other words, MoCo can use the queue to handle plenty of negative samples without an enormous batch. Add the MLP head, stronger augmentation and cosine learning-rate schedule, and MoCo v2 wins these reported comparisons.\n\n### Computational Load and Resource Consumption\n\n\n\n![Table 3: per-GPU memory and 200-epoch time on eight 16GB V100s; 93GB is an estimate](/content/papers/assets/244ee64745843a24695f0d41ef071f15ba129b17df5a567eea1c53d69d598332.jpg)\n\n\n\nThe authors also compared the memory and time costs of the end-to-end mechanism and the MoCo mechanism on eight V100 GPUs with 16 GB each.\n\nAt batch size 4096, the authors estimate that end-to-end training would require 93 GB per GPU, beyond the 16 GB capacity used here; they report no measured training time for that row. Even at the shared batch size of 256, end-to-end requires 7.4 GB per GPU and about 65 hours for 200 epochs, versus MoCo’s 5.0 GB and 53 hours, because it backpropagates through both query and key encoders.\n\nMoCo backpropagates only through the query branch. Its key encoder is still updated by the momentum rule, so saying that the key encoder never changes would be incorrect.\n\n## Conclusion\n\nIn short, the two SimCLR improvements tested here also work in MoCo. Thanks to MoCo's queue, there is no need for a huge GPU batch to get these results. Under the paper's training setup, that is a pretty economical way to get strong performance.\n\nIn this round, FAIR successfully made a comeback against Google.\n","imageSizes":{"/content/papers/assets/0f817bf1235f2d95a4b7dbd5953fe29dfb2a5e0dd2f4890364d922d50c45d371.jpg":{"width":1200,"height":952},"/content/papers/assets/5899b629eb7547a399e603fbac53478341999614cf58f4c2a3acc2f3fb4f6d70.jpg":{"width":2112,"height":852},"/content/papers/assets/a228b5588f1d96f67a3b8ef0b2acc1e6ef40cca1ab2cc7e1ed67efd7e6f3d71d.jpg":{"width":2112,"height":852},"/content/papers/assets/27904ebbfb9ea0c997892e7b7ee46286d397101590ed563b6a827856cff6a522.jpg":{"width":980,"height":372},"/content/papers/assets/244ee64745843a24695f0d41ef071f15ba129b17df5a567eea1c53d69d598332.jpg":{"width":792,"height":176}}}
