Skip to content

Commit 08040f0

Browse files
authored
Test code in pytorch 2.4 (#285)
* test code in pytorch 2.4 * update
1 parent 6cbe652 commit 08040f0

File tree

17 files changed

+509
-377
lines changed

17 files changed

+509
-377
lines changed

appendix-A/01_main-chapter-code/code-part1.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"name": "stdout",
4747
"output_type": "stream",
4848
"text": [
49-
"2.2.1\n"
49+
"2.4.0\n"
5050
]
5151
}
5252
],
@@ -658,13 +658,13 @@
658658
"output_type": "stream",
659659
"text": [
660660
"Parameter containing:\n",
661-
"tensor([[ 0.0956, 0.1280, -0.0696, ..., 0.0961, 0.0631, 0.1349],\n",
662-
" [ 0.0983, 0.0580, -0.0574, ..., 0.0981, 0.0370, 0.0516],\n",
663-
" [-0.0429, -0.1411, -0.1399, ..., 0.0767, 0.0019, 0.1400],\n",
661+
"tensor([[ 0.1182, 0.0606, -0.1292, ..., -0.1126, 0.0735, -0.0597],\n",
662+
" [-0.0249, 0.0154, -0.0476, ..., -0.1001, -0.1288, 0.1295],\n",
663+
" [ 0.0641, 0.0018, -0.0367, ..., -0.0990, -0.0424, -0.0043],\n",
664664
" ...,\n",
665-
" [-0.0777, -0.0726, 0.1273, ..., -0.0613, 0.0491, -0.1381],\n",
666-
" [-0.0830, -0.0969, -0.0473, ..., 0.0762, 0.1318, -0.1174],\n",
667-
" [ 0.0468, -0.0213, 0.0387, ..., 0.0639, 0.0927, -0.0668]],\n",
665+
" [ 0.0618, 0.0867, 0.1361, ..., -0.0254, 0.0399, 0.1006],\n",
666+
" [ 0.0842, -0.0512, -0.0960, ..., -0.1091, 0.1242, -0.0428],\n",
667+
" [ 0.0518, -0.1390, -0.0923, ..., -0.0954, -0.0668, -0.0037]],\n",
668668
" requires_grad=True)\n"
669669
]
670670
}
@@ -1264,7 +1264,7 @@
12641264
],
12651265
"source": [
12661266
"model = NeuralNetwork(2, 2) # needs to match the original model exactly\n",
1267-
"model.load_state_dict(torch.load(\"model.pth\"))"
1267+
"model.load_state_dict(torch.load(\"model.pth\", weights_only=True))"
12681268
]
12691269
},
12701270
{
@@ -1340,7 +1340,7 @@
13401340
"name": "python",
13411341
"nbconvert_exporter": "python",
13421342
"pygments_lexer": "ipython3",
1343-
"version": "3.10.11"
1343+
"version": "3.11.4"
13441344
}
13451345
},
13461346
"nbformat": 4,

appendix-A/01_main-chapter-code/code-part2.ipynb

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"metadata": {},
5+
"metadata": {
6+
"id": "AAAnDw04iAm4"
7+
},
68
"source": [
79
"<table style=\"width:100%\">\n",
810
"<tr>\n",
@@ -54,14 +56,14 @@
5456
"base_uri": "https://localhost:8080/"
5557
},
5658
"id": "RM7kGhwMF_nO",
57-
"outputId": "ac60b048-b81f-4bb0-90fa-1ca474f04e9a"
59+
"outputId": "b1872617-aacd-46fa-e5f3-f130fd81b246"
5860
},
5961
"outputs": [
6062
{
6163
"name": "stdout",
6264
"output_type": "stream",
6365
"text": [
64-
"2.0.1+cu118\n"
66+
"2.4.0+cu121\n"
6567
]
6668
}
6769
],
@@ -79,7 +81,7 @@
7981
"base_uri": "https://localhost:8080/"
8082
},
8183
"id": "OXLCKXhiUkZt",
82-
"outputId": "39fe5366-287e-47eb-cc34-3508d616c4f9"
84+
"outputId": "e9ca3c58-d92c-4c8b-a9c9-cd7fcc1fedb4"
8385
},
8486
"outputs": [
8587
{
@@ -102,18 +104,15 @@
102104
"base_uri": "https://localhost:8080/"
103105
},
104106
"id": "MTTlfh53Va-T",
105-
"outputId": "f31d8bbe-577f-4db4-9939-02e66b9f96d1"
107+
"outputId": "bae76cb5-d1d3-441f-a7c5-93a161e2e86a"
106108
},
107109
"outputs": [
108110
{
109-
"data": {
110-
"text/plain": [
111-
"tensor([5., 7., 9.])"
112-
]
113-
},
114-
"execution_count": 3,
115-
"metadata": {},
116-
"output_type": "execute_result"
111+
"name": "stdout",
112+
"output_type": "stream",
113+
"text": [
114+
"tensor([5., 7., 9.])\n"
115+
]
117116
}
118117
],
119118
"source": [
@@ -125,13 +124,13 @@
125124
},
126125
{
127126
"cell_type": "code",
128-
"execution_count": 5,
127+
"execution_count": 4,
129128
"metadata": {
130129
"colab": {
131130
"base_uri": "https://localhost:8080/"
132131
},
133132
"id": "Z4LwTNw7Vmmb",
134-
"outputId": "1c025c6a-e3ed-4c7c-f5fd-86c14607036e"
133+
"outputId": "9ad97923-bc8e-4c49-88bf-48dc1de56804"
135134
},
136135
"outputs": [
137136
{
@@ -151,24 +150,24 @@
151150
},
152151
{
153152
"cell_type": "code",
154-
"execution_count": 7,
153+
"execution_count": 5,
155154
"metadata": {
156155
"colab": {
157156
"base_uri": "https://localhost:8080/",
158-
"height": 184
157+
"height": 158
159158
},
160159
"id": "tKT6URN1Vuft",
161-
"outputId": "e6f01e7f-d9cf-44cb-cc6d-46fc7907d5c0"
160+
"outputId": "8396eb18-47c8-47a1-c1b6-8bcb9480fb52"
162161
},
163162
"outputs": [
164163
{
165164
"ename": "RuntimeError",
166-
"evalue": "ignored",
165+
"evalue": "Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!",
167166
"output_type": "error",
168167
"traceback": [
169168
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
170169
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
171-
"\u001b[0;32m<ipython-input-7-4ff3c4d20fc3>\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mtensor_1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtensor_1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"cpu\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtensor_1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mtensor_2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
170+
"\u001b[0;32m/tmp/ipykernel_2321/2079609735.py\u001b[0m in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mtensor_1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtensor_1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"cpu\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtensor_1\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mtensor_2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
172171
"\u001b[0;31mRuntimeError\u001b[0m: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!"
173172
]
174173
}
@@ -189,7 +188,7 @@
189188
},
190189
{
191190
"cell_type": "code",
192-
"execution_count": 8,
191+
"execution_count": 6,
193192
"metadata": {
194193
"id": "GyY59cjieitv"
195194
},
@@ -215,7 +214,7 @@
215214
},
216215
{
217216
"cell_type": "code",
218-
"execution_count": 9,
217+
"execution_count": 7,
219218
"metadata": {
220219
"id": "v41gKqEJempa"
221220
},
@@ -243,7 +242,7 @@
243242
},
244243
{
245244
"cell_type": "code",
246-
"execution_count": 23,
245+
"execution_count": 8,
247246
"metadata": {
248247
"id": "UPGVRuylep8Y"
249248
},
@@ -271,7 +270,7 @@
271270
},
272271
{
273272
"cell_type": "code",
274-
"execution_count": 24,
273+
"execution_count": 9,
275274
"metadata": {
276275
"id": "drhg6IXofAXh"
277276
},
@@ -302,13 +301,13 @@
302301
},
303302
{
304303
"cell_type": "code",
305-
"execution_count": 25,
304+
"execution_count": 10,
306305
"metadata": {
307306
"colab": {
308307
"base_uri": "https://localhost:8080/"
309308
},
310309
"id": "7jaS5sqPWCY0",
311-
"outputId": "84c74615-38f2-48b8-eeda-b5912fed1d3a"
310+
"outputId": "8a5cd93d-671c-4abf-d5cd-97845f300ffd"
312311
},
313312
"outputs": [
314313
{
@@ -362,7 +361,7 @@
362361
},
363362
{
364363
"cell_type": "code",
365-
"execution_count": 26,
364+
"execution_count": 11,
366365
"metadata": {
367366
"id": "4qrlmnPPe7FO"
368367
},
@@ -391,13 +390,13 @@
391390
},
392391
{
393392
"cell_type": "code",
394-
"execution_count": 27,
393+
"execution_count": 12,
395394
"metadata": {
396395
"colab": {
397396
"base_uri": "https://localhost:8080/"
398397
},
399398
"id": "1_-BfkfEf4HX",
400-
"outputId": "473bf21d-5880-4de3-fc8a-051d75315b94"
399+
"outputId": "9453154f-0a5b-4a44-a3c9-f010e08d5a2c"
401400
},
402401
"outputs": [
403402
{
@@ -406,7 +405,7 @@
406405
"1.0"
407406
]
408407
},
409-
"execution_count": 27,
408+
"execution_count": 12,
410409
"metadata": {},
411410
"output_type": "execute_result"
412411
}
@@ -417,13 +416,13 @@
417416
},
418417
{
419418
"cell_type": "code",
420-
"execution_count": 21,
419+
"execution_count": 13,
421420
"metadata": {
422421
"colab": {
423422
"base_uri": "https://localhost:8080/"
424423
},
425424
"id": "iYtXKBGEgKss",
426-
"outputId": "508edd84-3fb7-4d04-cb23-9df0c3d24170"
425+
"outputId": "d6cc870a-34de-490e-e5d3-23e6956744bd"
427426
},
428427
"outputs": [
429428
{
@@ -432,7 +431,7 @@
432431
"1.0"
433432
]
434433
},
435-
"execution_count": 21,
434+
"execution_count": 13,
436435
"metadata": {},
437436
"output_type": "execute_result"
438437
}
@@ -443,21 +442,27 @@
443442
},
444443
{
445444
"cell_type": "markdown",
446-
"metadata": {},
445+
"metadata": {
446+
"id": "nc2LGFVbiAnB"
447+
},
447448
"source": [
448449
"### A.9.3 Training with multiple GPUs"
449450
]
450451
},
451452
{
452453
"cell_type": "markdown",
453-
"metadata": {},
454+
"metadata": {
455+
"id": "cOUza9iQiAnC"
456+
},
454457
"source": [
455458
"See [DDP-script.py](DDP-script.py)"
456459
]
457460
},
458461
{
459462
"cell_type": "markdown",
460-
"metadata": {},
463+
"metadata": {
464+
"id": "YOYk5Fh7iAnC"
465+
},
461466
"source": [
462467
"<img src=\"https://sebastianraschka.com/images/LLMs-from-scratch-images/appendix-a_compressed/12.webp\" width=\"600px\">\n",
463468
"<img src=\"https://sebastianraschka.com/images/LLMs-from-scratch-images/appendix-a_compressed/13.webp\" width=\"600px\">"
@@ -485,7 +490,7 @@
485490
"name": "python",
486491
"nbconvert_exporter": "python",
487492
"pygments_lexer": "ipython3",
488-
"version": "3.11.4"
493+
"version": "3.10.14"
489494
}
490495
},
491496
"nbformat": 4,

ch02/01_main-chapter-code/ch02.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"name": "stdout",
4747
"output_type": "stream",
4848
"text": [
49-
"torch version: 2.3.1\n",
49+
"torch version: 2.4.0\n",
5050
"tiktoken version: 0.7.0\n"
5151
]
5252
}
@@ -1244,7 +1244,7 @@
12441244
"name": "stdout",
12451245
"output_type": "stream",
12461246
"text": [
1247-
"PyTorch version: 2.3.1\n"
1247+
"PyTorch version: 2.4.0\n"
12481248
]
12491249
}
12501250
],

ch02/01_main-chapter-code/dataloader.ipynb

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,39 @@
3838
"This notebook contains the main takeaway, the data loading pipeline without the intermediate steps."
3939
]
4040
},
41+
{
42+
"cell_type": "markdown",
43+
"id": "2b4e8f2d-cb81-41a3-8780-a70b382e18ae",
44+
"metadata": {},
45+
"source": [
46+
"Packages that are being used in this notebook:"
47+
]
48+
},
4149
{
4250
"cell_type": "code",
4351
"execution_count": 1,
52+
"id": "c7ed6fbe-45ac-40ce-8ea5-4edb212565e1",
53+
"metadata": {},
54+
"outputs": [
55+
{
56+
"name": "stdout",
57+
"output_type": "stream",
58+
"text": [
59+
"torch version: 2.4.0\n",
60+
"tiktoken version: 0.7.0\n"
61+
]
62+
}
63+
],
64+
"source": [
65+
"from importlib.metadata import version\n",
66+
"\n",
67+
"print(\"torch version:\", version(\"torch\"))\n",
68+
"print(\"tiktoken version:\", version(\"tiktoken\"))"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 2,
4474
"id": "0ed4b7db-3b47-4fd3-a4a6-5f4ed5dd166e",
4575
"metadata": {},
4676
"outputs": [],
@@ -107,7 +137,7 @@
107137
},
108138
{
109139
"cell_type": "code",
110-
"execution_count": 2,
140+
"execution_count": 3,
111141
"id": "664397bc-6daa-4b88-90aa-e8fc1fbd5846",
112142
"metadata": {},
113143
"outputs": [],
@@ -125,7 +155,7 @@
125155
},
126156
{
127157
"cell_type": "code",
128-
"execution_count": 3,
158+
"execution_count": 4,
129159
"id": "d3664332-e6bb-447e-8b96-203aafde8b24",
130160
"metadata": {},
131161
"outputs": [

0 commit comments

Comments
 (0)