Note about MPS devices (#329)

This commit is contained in:
Sebastian Raschka
2024-08-19 20:58:45 -05:00
committed by GitHub
parent a82169290e
commit 11e2f56af5
3 changed files with 43 additions and 1 deletions

View File

@@ -511,6 +511,21 @@
"outputs": [],
"source": [
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
"\n",
"# Note:\n",
"# Uncommenting the following lines will allow the code to run on Apple Silicon chips, if applicable,\n",
"# which is approximately 1.2x faster than on an Apple CPU (as measured on an M3 MacBook Air).\n",
"# However, the resulting loss values may be slightly different.\n",
"\n",
"#if torch.cuda.is_available():\n",
"# device = torch.device(\"cuda\")\n",
"#elif torch.backends.mps.is_available():\n",
"# device = torch.device(\"mps\")\n",
"#else:\n",
"# device = torch.device(\"cpu\")\n",
"#\n",
"# print(f\"Using {device} device.\")\n",
"\n",
"model.to(device); # no assignment model = model.to(device) necessary for nn.Module classes"
]
},