Fix lr, weight_decay defaults for ViT-* trained on ImageNet-1k

This commit is contained in:
AlessandroMiola committed 2023-01-20 12:01:00 +01:00
1 parent 944534fe7b
commit 3defaddb0c
1 file changed
+5 -4
+5 -4
View File
@@ -3457,6 +3457,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "2554a736-ca45-4f83-abc3-41750c20ec58",
"metadata": {},
@@ -3471,9 +3472,9 @@
"\n",
"The authors set Adam's $\\beta$ (beta) values to $\\beta_{1}=0.9, \\beta_{2}=0.999$, these are the default values for the `betas` parameter in `torch.optim.Adam(betas=(0.9, 0.999))`.\n",
"\n",
"They also state the use of [weight decay](https://paperswithcode.com/method/weight-decay) (slowly reducing the values of the weights during optimization to prevent overfitting), we can set this with the `weight_decay` parameter in `torch.optim.Adam(weight_decay=0.1)`.\n",
"They also state the use of [weight decay](https://paperswithcode.com/method/weight-decay) (slowly reducing the values of the weights during optimization to prevent overfitting), we can set this with the `weight_decay` parameter in `torch.optim.Adam(weight_decay=0.3)` (according to the setting of ViT-* trained on ImageNet-1k).\n",
"\n",
"We'll set the learning rate of the optimizer to 0.1 as per Table 3.\n",
"We'll set the learning rate of the optimizer to 0.003 as per Table 3 (according to the setting of ViT-* trained on ImageNet-1k).\n",
"\n",
"And as discussed previously, we're going to use a lower batch size than 4096 due to hardware limitations (if you have a large GPU, feel free to increase this)."
]
@@ -3544,9 +3545,9 @@
"\n",
"# Setup the optimizer to optimize our ViT model parameters using hyperparameters from the ViT paper \n",
"optimizer = torch.optim.Adam(params=vit.parameters(), \n",
" lr=1e-3, # Base LR from Table 3 \n",
" lr=3e-3, # Base LR from Table 3 for ViT-* ImageNet-1k\n",
" betas=(0.9, 0.999), # default values but also mentioned in ViT paper section 4.1 (Training & Fine-tuning)\n",
" weight_decay=0.03) # from the ViT paper section 4.1 (Training & Fine-tuning)\n",
" weight_decay=0.3) # from the ViT paper section 4.1 (Training & Fine-tuning) and Table 3 for ViT-* ImageNet-1k\n",
"\n",
"# Setup the loss function for multi-class classification\n",
"loss_fn = torch.nn.CrossEntropyLoss()\n",