Skip to content

Commit 0ea2853

Browse files
committed
transformer colab with comet.ml
1 parent 1c3992f commit 0ea2853

File tree

1 file changed

+81
-76
lines changed

1 file changed

+81
-76
lines changed

labml_nn/transformers/basic/autoregressive_experiment.ipynb

Lines changed: 81 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
11
{
2-
"nbformat": 4,
3-
"nbformat_minor": 0,
4-
"metadata": {
5-
"colab": {
6-
"name": "Transformer",
7-
"provenance": [],
8-
"collapsed_sections": []
9-
},
10-
"kernelspec": {
11-
"name": "python3",
12-
"display_name": "Python 3"
13-
},
14-
"accelerator": "GPU"
15-
},
162
"cells": [
173
{
184
"cell_type": "markdown",
@@ -43,26 +29,47 @@
4329
}
4430
},
4531
"source": [
46-
"Install the packages"
32+
"### Install the packages"
4733
]
4834
},
4935
{
5036
"cell_type": "code",
37+
"execution_count": null,
5138
"metadata": {
52-
"id": "ZCzmCrAIVg0L",
5339
"colab": {
5440
"base_uri": "https://localhost:8080/"
5541
},
42+
"id": "ZCzmCrAIVg0L",
5643
"outputId": "cf107fb2-4d50-4c67-af34-367624553421",
5744
"pycharm": {
5845
"name": "#%%\n"
5946
}
6047
},
48+
"outputs": [],
49+
"source": [
50+
"!pip install labml-nn comet_ml --quiet"
51+
]
52+
},
53+
{
54+
"cell_type": "markdown",
55+
"metadata": {},
6156
"source": [
62-
"!pip install labml-nn comet_ml"
63-
],
57+
"### Enable [Comet](https://www.comet.ml)"
58+
]
59+
},
60+
{
61+
"cell_type": "code",
6462
"execution_count": null,
65-
"outputs": []
63+
"metadata": {},
64+
"outputs": [],
65+
"source": [
66+
"#@markdown Select in order to enable logging this experiment to [Comet](https://www.comet.ml).\n",
67+
"use_comet = True #@param {type:\"boolean\"}\n",
68+
"\n",
69+
"if use_comet:\n",
70+
" import comet_ml\n",
71+
" comet_ml.init(project_name='transformer')"
72+
]
6673
},
6774
{
6875
"cell_type": "markdown",
@@ -73,56 +80,27 @@
7380
}
7481
},
7582
"source": [
76-
"Imports"
83+
"### Imports"
7784
]
7885
},
7986
{
8087
"cell_type": "code",
88+
"execution_count": null,
8189
"metadata": {
8290
"id": "0hJXx_g0wS2C",
8391
"pycharm": {
8492
"name": "#%%\n"
8593
}
8694
},
95+
"outputs": [],
8796
"source": [
8897
"import torch\n",
8998
"import torch.nn as nn\n",
9099
"\n",
91100
"from labml import experiment\n",
92101
"from labml.configs import option\n",
93102
"from labml_nn.transformers.basic.autoregressive_experiment import Configs"
94-
],
95-
"execution_count": null,
96-
"outputs": []
97-
},
98-
{
99-
"cell_type": "markdown",
100-
"source": [
101-
"Set [Comet](https://www.comet.ml) api-key and the workspace."
102-
],
103-
"metadata": {
104-
"collapsed": false,
105-
"pycharm": {
106-
"name": "#%% md\n"
107-
}
108-
}
109-
},
110-
{
111-
"cell_type": "code",
112-
"execution_count": null,
113-
"outputs": [],
114-
"source": [
115-
"import os\n",
116-
"\n",
117-
"os.environ['COMET_API_KEY'] = \"\"\n",
118-
"os.environ['COMET_WORKSPACE'] = \"\""
119-
],
120-
"metadata": {
121-
"collapsed": false,
122-
"pycharm": {
123-
"name": "#%%\n"
124-
}
125-
}
103+
]
126104
},
127105
{
128106
"cell_type": "markdown",
@@ -133,22 +111,22 @@
133111
}
134112
},
135113
"source": [
136-
"Create an experiment"
114+
"### Create an experiment"
137115
]
138116
},
139117
{
140118
"cell_type": "code",
119+
"execution_count": null,
141120
"metadata": {
142121
"id": "bFcr9k-l4cAg",
143122
"pycharm": {
144123
"name": "#%%\n"
145124
}
146125
},
126+
"outputs": [],
147127
"source": [
148-
"experiment.create(name=\"transformer\", writers={'screen', 'web_api', 'comet'})"
149-
],
150-
"execution_count": null,
151-
"outputs": []
128+
"experiment.create(name=\"transformer\", writers={\"screen\", \"comet\"} if use_comet else {'screen'})"
129+
]
152130
},
153131
{
154132
"cell_type": "markdown",
@@ -159,22 +137,22 @@
159137
}
160138
},
161139
"source": [
162-
"Initialize configurations"
140+
"### Configurations"
163141
]
164142
},
165143
{
166144
"cell_type": "code",
145+
"execution_count": null,
167146
"metadata": {
168147
"id": "Piz0c5f44hRo",
169148
"pycharm": {
170149
"name": "#%%\n"
171150
}
172151
},
152+
"outputs": [],
173153
"source": [
174154
"conf = Configs()"
175-
],
176-
"execution_count": null,
177-
"outputs": []
155+
]
178156
},
179157
{
180158
"cell_type": "markdown",
@@ -190,6 +168,7 @@
190168
},
191169
{
192170
"cell_type": "code",
171+
"execution_count": null,
193172
"metadata": {
194173
"colab": {
195174
"base_uri": "https://localhost:8080/",
@@ -201,6 +180,7 @@
201180
"name": "#%%\n"
202181
}
203182
},
183+
"outputs": [],
204184
"source": [
205185
"experiment.configs(conf, {\n",
206186
" # Use character level tokenizer\n",
@@ -231,9 +211,7 @@
231211
" 'optimizer.optimizer': 'Noam',\n",
232212
" 'optimizer.learning_rate': 1.,\n",
233213
"})"
234-
],
235-
"execution_count": null,
236-
"outputs": []
214+
]
237215
},
238216
{
239217
"cell_type": "markdown",
@@ -249,6 +227,7 @@
249227
},
250228
{
251229
"cell_type": "code",
230+
"execution_count": null,
252231
"metadata": {
253232
"colab": {
254233
"base_uri": "https://localhost:8080/",
@@ -260,11 +239,10 @@
260239
"name": "#%%\n"
261240
}
262241
},
242+
"outputs": [],
263243
"source": [
264244
"experiment.add_pytorch_models({'model': conf.model})"
265-
],
266-
"execution_count": null,
267-
"outputs": []
245+
]
268246
},
269247
{
270248
"cell_type": "markdown",
@@ -275,11 +253,12 @@
275253
}
276254
},
277255
"source": [
278-
"Start the experiment and run the training loop."
256+
"### Start the experiment and run the training loop."
279257
]
280258
},
281259
{
282260
"cell_type": "code",
261+
"execution_count": null,
283262
"metadata": {
284263
"colab": {
285264
"base_uri": "https://localhost:8080/",
@@ -291,25 +270,51 @@
291270
"name": "#%%\n"
292271
}
293272
},
273+
"outputs": [],
294274
"source": [
295275
"# Start the experiment\n",
296276
"with experiment.start():\n",
297277
" conf.run()"
298-
],
299-
"execution_count": null,
300-
"outputs": []
278+
]
301279
},
302280
{
303281
"cell_type": "code",
282+
"execution_count": null,
304283
"metadata": {
305284
"id": "oBXXlP2b7XZO",
306285
"pycharm": {
307286
"name": "#%%\n"
308287
}
309288
},
310-
"source": [],
311-
"execution_count": null,
312-
"outputs": []
289+
"outputs": [],
290+
"source": []
313291
}
314-
]
315-
}
292+
],
293+
"metadata": {
294+
"accelerator": "GPU",
295+
"colab": {
296+
"collapsed_sections": [],
297+
"name": "Transformer",
298+
"provenance": []
299+
},
300+
"kernelspec": {
301+
"display_name": "Python 3 (ipykernel)",
302+
"language": "python",
303+
"name": "python3"
304+
},
305+
"language_info": {
306+
"codemirror_mode": {
307+
"name": "ipython",
308+
"version": 3
309+
},
310+
"file_extension": ".py",
311+
"mimetype": "text/x-python",
312+
"name": "python",
313+
"nbconvert_exporter": "python",
314+
"pygments_lexer": "ipython3",
315+
"version": "3.7.11"
316+
}
317+
},
318+
"nbformat": 4,
319+
"nbformat_minor": 4
320+
}

0 commit comments

Comments
 (0)