Skip to content

Instantly share code, notes, and snippets.

@jamescalam
Last active August 12, 2023 21:15
Show Gist options
  • Save jamescalam/1032fe85a7ca8e2b53d133b67602b824 to your computer and use it in GitHub Desktop.
Save jamescalam/1032fe85a7ca8e2b53d133b67602b824 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"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)"
]
}
]
}
@adarsh-dikhit
Copy link

How to activate multiple GPU ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment