mirror of
https://github.com/rasbt/LLMs-from-scratch.git
synced 2026-04-10 12:33:42 +00:00
Note about MPS in ch06 and ch07 (#325)
This commit is contained in:
committed by
GitHub
parent
8ef5022511
commit
c443035d56
@@ -1687,6 +1687,21 @@
|
||||
],
|
||||
"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 2x faster than on an Apple CPU (as measured on an M3 MacBook Air).\n",
|
||||
"# As of this writing, in PyTorch 2.4, the results obtained via CPU and MPS were identical.\n",
|
||||
"# However, in earlier versions of PyTorch, you may observe different results when using MPS.\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",
|
||||
"#print(f\"Running on {device} device.\")\n",
|
||||
"\n",
|
||||
"model.to(device) # no assignment model = model.to(device) necessary for nn.Module classes\n",
|
||||
"\n",
|
||||
"torch.manual_seed(123) # For reproducibility due to the shuffling in the training data loader\n",
|
||||
|
||||
Reference in New Issue
Block a user