Skip to content

Commit 5110022

Browse files
Updating to latest version
1 parent 6f82565 commit 5110022

File tree

2 files changed

+192
-2
lines changed

2 files changed

+192
-2
lines changed

notebooks/GPU_training.ipynb

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# GPU accelerated training\n",
8+
"\n",
9+
"Using twinLab you can accelerate the training time of some models using our cloud-based GPU training. In our testing, this has only produced reliable speed-ups for larger variational Gaussian Processes (`estimator_type=\"variational_gp\"`), or for models with output decomposition (either `output_explained_variance` or `output_retained_dimensions` set in `TrainParams`).\n",
10+
"\n",
11+
"Start, as usual, by importing the packages you need for this tutorial:"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 1,
17+
"metadata": {},
18+
"outputs": [
19+
{
20+
"name": "stdout",
21+
"output_type": "stream",
22+
"text": [
23+
"\n",
24+
" ====== TwinLab Client Initialisation ======\n",
25+
" Version : 2.20.1.dev0\n",
26+
" User : [email protected]\n",
27+
" Server : http://localhost:8000\n",
28+
" Environment : /Users/mead/digiLab/twinLab/tutorials/.env\n",
29+
"\n"
30+
]
31+
}
32+
],
33+
"source": [
34+
"import twinlab as tl"
35+
]
36+
},
37+
{
38+
"cell_type": "markdown",
39+
"metadata": {},
40+
"source": [
41+
"We use the `tritium-desorption` example for this tutorial:"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": 2,
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"dataset_id = \"tritium-desorption-small\"\n",
51+
"dataset = tl.Dataset(dataset_id)\n",
52+
"df = tl.load_example_dataset(dataset_id)\n",
53+
"dataset.upload(df)"
54+
]
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"metadata": {},
59+
"source": [
60+
"Now we setup the emulator to be trained. With this dataset we try to predict the desorption rate (a function of temperature, so this is a functional output model) as a function of parameters of the material used in the reactor wall (parametrized via `E1`, `E2`, `E3`, `n1`, `n2`). "
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 3,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"emulator_id = \"tritium-desorption\"\n",
70+
"inputs = [\"E1\", \"E2\", \"E3\", \"n1\", \"n2\"]\n",
71+
"outputs = [f\"y{i}\" for i in range(624)]\n",
72+
"emulator = tl.Emulator(emulator_id)\n",
73+
"params = tl.TrainParams(output_retained_dimensions=5)\n",
74+
"\n",
75+
"# Create a dataset on which to make predictions\n",
76+
"df_test = df[inputs].sample(5, random_state=42).reset_index(drop=True)"
77+
]
78+
},
79+
{
80+
"cell_type": "markdown",
81+
"metadata": {},
82+
"source": [
83+
"The GPU is activated by setting `processor=\"gpu\"` in the call to `emulator.train`. Here we see that it cuts down training time by a factor of $\\sim 1/2$. This is not a life-changing improvement, but an improvement never-the-less."
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": 4,
89+
"metadata": {},
90+
"outputs": [
91+
{
92+
"name": "stdout",
93+
"output_type": "stream",
94+
"text": [
95+
"Training model on cpu\n",
96+
"Emulator 'tritium-desorption' has begun training.\n",
97+
"0:00:00: Job status: processing\n",
98+
"0:00:03: Job status: processing\n",
99+
"0:00:08: Job status: processing\n",
100+
"0:00:17: Job status: processing\n",
101+
"0:00:31: Job status: processing\n",
102+
"0:00:36: Job status: processing\n",
103+
"0:00:41: Job status: processing\n",
104+
"0:00:47: Job status: processing\n",
105+
"0:00:53: Job status: processing\n",
106+
"0:01:00: Job status: processing\n",
107+
"0:01:08: Job status: processing\n",
108+
"0:01:16: Job status: processing\n",
109+
"0:01:25: Job status: processing\n",
110+
"0:01:35: Job status: processing\n",
111+
"0:01:46: Job status: processing\n",
112+
"0:01:59: Job status: processing\n",
113+
"0:02:12: Job status: success\n",
114+
"Training of emulator tritium-desorption is complete!\n",
115+
"\n",
116+
"Predicting from trained cpu model...\n",
117+
"Predictions made successfully!\n",
118+
"\n",
119+
"Training model on gpu\n",
120+
"Emulator 'tritium-desorption' has begun training.\n",
121+
"0:00:00: Job status: processing\n",
122+
"0:00:01: Job status: processing\n",
123+
"0:00:03: Job status: processing\n",
124+
"0:00:04: Job status: processing\n",
125+
"0:00:06: Job status: processing\n",
126+
"0:00:08: Job status: processing\n",
127+
"0:00:11: Job status: processing\n",
128+
"0:00:13: Job status: processing\n",
129+
"0:00:16: Job status: processing\n",
130+
"0:00:19: Job status: processing\n",
131+
"0:00:22: Job status: processing\n",
132+
"0:00:26: Job status: processing\n",
133+
"0:00:30: Job status: processing\n",
134+
"0:00:35: Job status: processing\n",
135+
"0:00:40: Job status: processing\n",
136+
"0:00:45: Job status: processing\n",
137+
"0:00:51: Job status: processing\n",
138+
"0:00:58: Job status: processing\n",
139+
"0:01:05: Job status: processing\n",
140+
"0:01:13: Job status: success\n",
141+
"Training of emulator tritium-desorption is complete!\n",
142+
"\n",
143+
"Predicting from trained gpu model...\n",
144+
"Predictions made successfully!\n",
145+
"\n"
146+
]
147+
}
148+
],
149+
"source": [
150+
"# Loop over CPU and GPU to compare training times between the two\n",
151+
"for processor in [\"cpu\", \"gpu\"]:\n",
152+
" print(f\"Training model on {processor}\")\n",
153+
" emulator.train(\n",
154+
" dataset,\n",
155+
" inputs,\n",
156+
" outputs,\n",
157+
" params=params,\n",
158+
" verbose=True,\n",
159+
" processor=processor,\n",
160+
" )\n",
161+
" print()\n",
162+
" print(f\"Predicting from trained {processor} model...\")\n",
163+
" emulator.predict(df_test, verbose=False)\n",
164+
" print(\"Predictions made successfully!\")\n",
165+
" print()"
166+
]
167+
}
168+
],
169+
"metadata": {
170+
"kernelspec": {
171+
"display_name": "twinlab-tutorials-VByujxwf-py3.10",
172+
"language": "python",
173+
"name": "python3"
174+
},
175+
"language_info": {
176+
"codemirror_mode": {
177+
"name": "ipython",
178+
"version": 3
179+
},
180+
"file_extension": ".py",
181+
"mimetype": "text/x-python",
182+
"name": "python",
183+
"nbconvert_exporter": "python",
184+
"pygments_lexer": "ipython3",
185+
"version": "3.10.15"
186+
}
187+
},
188+
"nbformat": 4,
189+
"nbformat_minor": 2
190+
}

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ maintainers = ["twinLab Product Team <[email protected]>"]
77
readme = "README.md"
88

99
[tool.poetry.dependencies]
10-
python = ">=3.8,<3.13"
10+
python = ">=3.9,<3.13"
1111
jupyter = "^1.0.0"
1212
matplotlib = "^3.7.1"
1313
numpy = [
@@ -19,7 +19,7 @@ pandas = [
1919
{ version = "^2.0", python = ">=3.9,<3.13" },
2020
]
2121
plotly = "^5.19.0"
22-
twinlab = "^2.10.0"
22+
twinlab = "^2.21.0"
2323
# twinlab = { path = "../client/python", develop = true }
2424
nbdime = "^4.0.1"
2525

0 commit comments

Comments
 (0)