Last active
August 12, 2023 21:15
-
-
Save jamescalam/1032fe85a7ca8e2b53d133b67602b824 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"metadata": { | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.5" | |
}, | |
"orig_nbformat": 2, | |
"kernelspec": { | |
"name": "ml", | |
"display_name": "ML", | |
"language": "python" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2, | |
"cells": [ | |
{ | |
"source": [ | |
"Setup GPU/CPU usage." | |
], | |
"cell_type": "markdown", | |
"metadata": {} | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')\n", | |
"# and move our model over to the selected device\n", | |
"model.to(device)" | |
] | |
}, | |
{ | |
"source": [ | |
"Activate the training mode of our model, and initialize our optimizer (Adam with weighted decay - reduces chance of overfitting)." | |
], | |
"cell_type": "markdown", | |
"metadata": {} | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from transformers import AdamW\n", | |
"\n", | |
"# activate training mode\n", | |
"model.train()\n", | |
"# initialize optimizer\n", | |
"optim = AdamW(model.parameters(), lr=1e-4)" | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to activate multiple GPU ?