boris commited on
Commit
378a628
1 Parent(s): 4a4820f

feat: log to backend

Browse files
dev/inference/samples.csv ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Caption,Theme
2
+ a cat seats on top of an alligator,Animals
3
+ a dog eating worthlessness,Animals
4
+ a dog playing with a ball,Animals
5
+ a rat holding a red lightsable in a white background,Animals
6
+ A unicorn is passing by a rainbow in a field of flowers,Animals
7
+ an elephant made of carrots,Animals
8
+ an elephant on a unicycle during a circus,Animals
9
+ photography of a penguin watching television,Animals
10
+ rat wearing a crown,Animals
11
+ "a background consisting of colors blue, green, and red.",Art
12
+ a colorful stairway to heaven,Art
13
+ a graphite sketch of a gothic cathedral,Art
14
+ a portrait of a nightmare creature watching at you,Art
15
+ a white room full of a black substance,Art
16
+ epic sword fight,Art
17
+ "happy, happiness",Art
18
+ painting of an oniric forest glade surrounded by tall trees,Art
19
+ real painting of an alien from Monet,Art
20
+ robots taking control over humans,Art
21
+ "sad, sadness",Art
22
+ still life in the style of Kandinsky,Art
23
+ still life in the style of Picasso,Art
24
+ the representation of infinity,Art
25
+ a cute avocado armchair singing karaoke on stage in front of a crowd of strawberry shaped lamps,Avocado
26
+ an armchair in the shape of an avocado,Avocado
27
+ an avocado armchair,Avocado
28
+ an avocado armchair flying into space,Avocado
29
+ an illustration of an avocado in a christmas sweater staring at its reflection in a mirror,Avocado
30
+ illustration of an avocado armchair,Avocado
31
+ illustration of an avocado armchair getting married to a pineapple,Avocado
32
+ logo of an avocado armchair,Avocado
33
+ watercolor of the Eiffel tower on the moon,Avocado
34
+ a cute pikachu teapot,Culture
35
+ a picture of a castle from minecraft,Culture
36
+ an illustration of pikachu seating on a bench,Culture
37
+ mario eating an avocado while walking his baby koala,Culture
38
+ star wars concept art,Culture
39
+ a cartoon of a superhero bear,Illustrations
40
+ an illustration of a cute skeleton wearing a blue hoodie,Illustrations
41
+ Cartoon of a carrot with big eyes,Illustrations
42
+ illustration of a baby shark swimming around corals,Illustrations
43
+ logo of a robot wearing glasses and reading a book,Illustrations
44
+ a beautiful sunset at a beach with a shell on the shore,Landscape
45
+ a farmhouse surrounded by beautiful flowers,Landscape
46
+ a photo of a fantasy version of New York City,Landscape
47
+ a picture of fantasy kingdoms,Landscape
48
+ a volcano erupting in the middle of New York city,Landscape
49
+ aerial view of the beach at night,Landscape
50
+ aerial view of the beach during daytime,Landscape
51
+ big wave destroying a city,Landscape
52
+ "London in a far future, futuristic London",Landscape
53
+ sunset over green mountains,Landscape
54
+ the last sunrise on earth,Landscape
55
+ underwater cathedral,Landscape
56
+ white snow covered mountain under blue sky during daytime,Landscape
57
+ a bottle of coca-cola on a table,Objects
58
+ a cactus lifitng weights,Objects
59
+ a living room with two white armchairs and a painting of the collosseum. The painting is mounted above a modern fireplace.,Objects
60
+ a long line of alternating green and red blocks,Objects
61
+ a long line of green blocks on a beach at subset,Objects
62
+ a long line of peaches on a beach at sunset,Objects
63
+ a peanut,Objects
64
+ a photo of a camera from the future,Objects
65
+ a restaurant menu,Objects
66
+ a skeleton with the shape of a spider,Objects
67
+ "looking into the sky, 10 airplanes are seen overhead",Objects
68
+ sheves filled with books and archemy potion bottles,Objects
69
+ the communist statue of liberty,Objects
70
+ this is a detailed high-resolution scan of a human brain,Objects
71
+ a collection of glasses is sitting on a table,OpenAI
72
+ a cross-section view of a walnut,OpenAI
73
+ a painting of a capybara sitting on a mountain during fall in surrealist style,OpenAI
74
+ a pentagonal green clock,OpenAI
75
+ a photo of san francisco golden gate bridge,OpenAI
76
+ a pixel art illustration of an eagle sitting in a field in the afternoon,OpenAI
77
+ a professional high-quality emoji of a lovestruck cup of boba,OpenAI
78
+ a small red block sitting on a large green block,OpenAI
79
+ a storefront that has the word 'openai' written on it,OpenAI
80
+ a tatoo of a black broccoli,OpenAI
81
+ a variety of clocks is sitting on a table,OpenAI
82
+ "an emoji of a baby fox wearing a blue hat, blue gloves, red shirt, and red pants",OpenAI
83
+ "an emoji of a baby penguin wearing a blue hat, blue gloves, red shirt, and green pants",OpenAI
84
+ an extreme close-up view of a capybara sitting in a field,OpenAI
85
+ an illustration of a baby cucumber with a mustache playing chess,OpenAI
86
+ an illustration of a baby daikon radish in a tutu walking a dog,OpenAI
87
+ an illustration of a baby hedgehog in a cape staring at its reflection in a mirror,OpenAI
88
+ an illustration of a baby panda with headphones holding an umbrella in the rain,OpenAI
89
+ an illustration of an avocado in a beanie riding a motorcycle,OpenAI
90
+ urinals are lined up in a jungle,OpenAI
91
+ a human face,People
92
+ "a person is holding a phone and a waterbottle, running a marathon.",People
93
+ a photograph of Ellen G. White,People
94
+ Mohammed Ali and Mike Tyson in a hypothetical match,People
95
+ Pele and Maradona in a hypothetical match,People
96
+ Young woman riding her bike through the forest,People
97
+ a clown wearing a spacesuit floating in space,Space
98
+ a photo of the French flag on the planet Saturn,Space
99
+ a picture of the eiffel tower on the moon,Space
100
+ illustration of an astronaut in a space suit playing guitar,Space
101
+ the moon is a skull,Space
102
+ view of mars from space,Space
dev/inference/wandb-backend.ipynb ADDED
@@ -0,0 +1,353 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "id": "4ff2a984-b8b2-4a69-89cf-0d16da2393c8",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import csv\n",
11
+ "import tempfile\n",
12
+ "import wandb\n",
13
+ "from dalle_mini.model import CustomFlaxBartForConditionalGeneration\n",
14
+ "from vqgan_jax.modeling_flax_vqgan import VQModel\n",
15
+ "from transformers import BartTokenizer, CLIPProcessor, FlaxCLIPModel\n",
16
+ "from dalle_mini.text import TextNormalizer"
17
+ ]
18
+ },
19
+ {
20
+ "cell_type": "code",
21
+ "execution_count": null,
22
+ "id": "92f4557c-fd7f-4edc-81c2-de0b0a10c270",
23
+ "metadata": {},
24
+ "outputs": [],
25
+ "source": [
26
+ "wandb_runs = ['rjf3rycy']\n",
27
+ "VQGAN_REPO, VQGAN_COMMIT_ID = 'dalle-mini/vqgan_imagenet_f16_16384', None\n",
28
+ "normalize_text = True"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": null,
34
+ "id": "c6a878fa-4bf5-4978-abb5-e235841d765b",
35
+ "metadata": {},
36
+ "outputs": [],
37
+ "source": [
38
+ "vqgan = VQModel.from_pretrained(VQGAN_REPO, revision=VQGAN_COMMIT_ID)\n",
39
+ "clip = FlaxCLIPModel.from_pretrained(\"openai/clip-vit-base-patch32\")\n",
40
+ "processor = CLIPProcessor.from_pretrained(\"openai/clip-vit-base-patch32\")"
41
+ ]
42
+ },
43
+ {
44
+ "cell_type": "code",
45
+ "execution_count": null,
46
+ "id": "e57797ab-0b3a-4490-be58-03d8d1c23fe9",
47
+ "metadata": {},
48
+ "outputs": [],
49
+ "source": [
50
+ "with open('samples.csv', newline='', encoding='utf8') as f:\n",
51
+ " reader = csv.reader(f)\n",
52
+ " for row in reader:\n",
53
+ " breakpoint()"
54
+ ]
55
+ },
56
+ {
57
+ "cell_type": "code",
58
+ "execution_count": null,
59
+ "id": "3ffb1d09-bd1c-4f57-9ae5-3eda6f7d3a08",
60
+ "metadata": {},
61
+ "outputs": [],
62
+ "source": [
63
+ "wandb_run = wandb_runs[0]\n",
64
+ "api = wandb.Api()"
65
+ ]
66
+ },
67
+ {
68
+ "cell_type": "code",
69
+ "execution_count": null,
70
+ "id": "f3e02d9d-4ee1-49e7-a7bc-4d8b139e9614",
71
+ "metadata": {},
72
+ "outputs": [],
73
+ "source": [
74
+ "try:\n",
75
+ " versions = api.artifact_versions(type_name='bart_model', name=f'dalle-mini/dalle-mini/model-{wandb_run}', per_page=10000)\n",
76
+ "except:\n",
77
+ " versions = []"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": null,
83
+ "id": "e8026e63-9e73-472c-9440-5e742c614901",
84
+ "metadata": {},
85
+ "outputs": [],
86
+ "source": [
87
+ "versions, len(versions)"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": null,
93
+ "id": "29613a9d-de7e-44e3-94f1-650085039204",
94
+ "metadata": {},
95
+ "outputs": [],
96
+ "source": [
97
+ "versions = sorted(versions, key=lambda x: int(x.version[1:]))"
98
+ ]
99
+ },
100
+ {
101
+ "cell_type": "code",
102
+ "execution_count": null,
103
+ "id": "d77159df-1a16-4996-aafd-1df82c5a3509",
104
+ "metadata": {},
105
+ "outputs": [],
106
+ "source": [
107
+ "versions"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": null,
113
+ "id": "cfd48de9-6022-444f-8b12-05cba8fad071",
114
+ "metadata": {},
115
+ "outputs": [],
116
+ "source": [
117
+ "artifact = versions[0]"
118
+ ]
119
+ },
120
+ {
121
+ "cell_type": "code",
122
+ "execution_count": null,
123
+ "id": "4db848c1-2bb5-432c-a732-1c6d0636e172",
124
+ "metadata": {},
125
+ "outputs": [],
126
+ "source": [
127
+ "version = int(artifact.version[1:])"
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": null,
133
+ "id": "25fac577-146d-4e62-a3ea-f0baea79ef83",
134
+ "metadata": {},
135
+ "outputs": [],
136
+ "source": [
137
+ "version"
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "code",
142
+ "execution_count": null,
143
+ "id": "f0d7ed17-7abb-4a31-ab3c-a12b9039a570",
144
+ "metadata": {},
145
+ "outputs": [],
146
+ "source": [
147
+ "# retrieve training run\n",
148
+ "training_run = api.run(f'dalle-mini/dalle-mini/{wandb_run}')\n",
149
+ "config = training_run.config"
150
+ ]
151
+ },
152
+ {
153
+ "cell_type": "code",
154
+ "execution_count": null,
155
+ "id": "9b9393c6-0a3c-46a8-ba27-ba37982b0009",
156
+ "metadata": {},
157
+ "outputs": [],
158
+ "source": [
159
+ "# see summary metrics\n",
160
+ "training_run.summary"
161
+ ]
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "execution_count": null,
166
+ "id": "7e784a43-626d-4e8d-9e47-a23775b2f35f",
167
+ "metadata": {},
168
+ "outputs": [],
169
+ "source": [
170
+ "# retrieve inference run details\n",
171
+ "def get_last_version_inference(run_id):\n",
172
+ " try:\n",
173
+ " inference_run = api.run(f'dalle-mini/dalle-mini/inference-{run_id}')\n",
174
+ " return inference_run.summary.get('_step', None)\n",
175
+ " except:\n",
176
+ " return None"
177
+ ]
178
+ },
179
+ {
180
+ "cell_type": "code",
181
+ "execution_count": null,
182
+ "id": "93b8d869-1658-4fa4-a401-2b91f8ac7a11",
183
+ "metadata": {},
184
+ "outputs": [],
185
+ "source": [
186
+ "last_version_inference = get_last_version_inference(wandb_run)"
187
+ ]
188
+ },
189
+ {
190
+ "cell_type": "code",
191
+ "execution_count": null,
192
+ "id": "8324835e-fd94-408e-b106-138be308480b",
193
+ "metadata": {},
194
+ "outputs": [],
195
+ "source": [
196
+ "if last_version_inference is None:\n",
197
+ " assert version == 0\n",
198
+ "else:\n",
199
+ " assert version == last_version_inference + 1"
200
+ ]
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "execution_count": null,
205
+ "id": "8ce9d2d3-aea3-4d5e-834a-c5caf85dd117",
206
+ "metadata": {},
207
+ "outputs": [],
208
+ "source": [
209
+ "run = wandb.init(job_type='inference', config=config, id=f'inference-{wandb_run}', resume='allow')"
210
+ ]
211
+ },
212
+ {
213
+ "cell_type": "code",
214
+ "execution_count": null,
215
+ "id": "ffe392c9-36d2-4aaa-a1b3-a827e348c1ef",
216
+ "metadata": {},
217
+ "outputs": [],
218
+ "source": [
219
+ "tmp_f.cleanup\n",
220
+ "tmp_f = tempfile.TemporaryDirectory()\n",
221
+ "tmp = tmp_f.name\n",
222
+ "#TODO: use context manager"
223
+ ]
224
+ },
225
+ {
226
+ "cell_type": "code",
227
+ "execution_count": null,
228
+ "id": "562036ed-dc86-48af-90b1-9c18383b3552",
229
+ "metadata": {},
230
+ "outputs": [],
231
+ "source": [
232
+ "# remove tmp\n",
233
+ "tmp_f.cleanup()"
234
+ ]
235
+ },
236
+ {
237
+ "cell_type": "code",
238
+ "execution_count": null,
239
+ "id": "299db1bb-fbe6-4d79-a48f-89893f8ed809",
240
+ "metadata": {},
241
+ "outputs": [],
242
+ "source": [
243
+ "artifact = run.use_artifact(artifact)"
244
+ ]
245
+ },
246
+ {
247
+ "cell_type": "code",
248
+ "execution_count": null,
249
+ "id": "d71481bf-98aa-42cb-b7e2-545d13ae4309",
250
+ "metadata": {},
251
+ "outputs": [],
252
+ "source": [
253
+ "# only download required files\n",
254
+ "for f in ['config.json', 'flax_model.msgpack', 'merges.txt', 'special_tokens_map.json', 'tokenizer.json', 'tokenizer_config.json', 'vocab.json']:\n",
255
+ " artifact.get_path(f).download(tmp)"
256
+ ]
257
+ },
258
+ {
259
+ "cell_type": "code",
260
+ "execution_count": null,
261
+ "id": "6f8ad8dd-da8f-40f9-b438-e43b779d637c",
262
+ "metadata": {},
263
+ "outputs": [],
264
+ "source": [
265
+ "# we verify all the files are present\n",
266
+ "from pathlib import Path\n",
267
+ "list(Path(tmp).glob('*'))"
268
+ ]
269
+ },
270
+ {
271
+ "cell_type": "code",
272
+ "execution_count": null,
273
+ "id": "5b715c32-e757-4cb0-9912-ff90238b9f10",
274
+ "metadata": {},
275
+ "outputs": [],
276
+ "source": [
277
+ "tokenizer = BartTokenizer.from_pretrained(tmp)\n",
278
+ "model = CustomFlaxBartForConditionalGeneration.from_pretrained(tmp)"
279
+ ]
280
+ },
281
+ {
282
+ "cell_type": "code",
283
+ "execution_count": null,
284
+ "id": "d1cc9993-1bfc-4ec6-a004-c056189c42ac",
285
+ "metadata": {},
286
+ "outputs": [],
287
+ "source": []
288
+ },
289
+ {
290
+ "cell_type": "code",
291
+ "execution_count": null,
292
+ "id": "43d2a99b-3501-4b30-b041-0fdeead12380",
293
+ "metadata": {},
294
+ "outputs": [],
295
+ "source": []
296
+ },
297
+ {
298
+ "cell_type": "code",
299
+ "execution_count": null,
300
+ "id": "06472541-75f1-44e5-841f-a4a26a0493e3",
301
+ "metadata": {},
302
+ "outputs": [],
303
+ "source": []
304
+ },
305
+ {
306
+ "cell_type": "code",
307
+ "execution_count": null,
308
+ "id": "7a24b903-777b-4e3d-817c-00ed613a7021",
309
+ "metadata": {},
310
+ "outputs": [],
311
+ "source": []
312
+ },
313
+ {
314
+ "cell_type": "code",
315
+ "execution_count": null,
316
+ "id": "e1c04761-1016-47e9-925c-3a9ec6fec95a",
317
+ "metadata": {},
318
+ "outputs": [],
319
+ "source": [
320
+ "wandb.finish()"
321
+ ]
322
+ },
323
+ {
324
+ "cell_type": "code",
325
+ "execution_count": null,
326
+ "id": "b37c1714-d54b-479e-a9e8-740affc0de2c",
327
+ "metadata": {},
328
+ "outputs": [],
329
+ "source": []
330
+ }
331
+ ],
332
+ "metadata": {
333
+ "kernelspec": {
334
+ "display_name": "Python 3 (ipykernel)",
335
+ "language": "python",
336
+ "name": "python3"
337
+ },
338
+ "language_info": {
339
+ "codemirror_mode": {
340
+ "name": "ipython",
341
+ "version": 3
342
+ },
343
+ "file_extension": ".py",
344
+ "mimetype": "text/x-python",
345
+ "name": "python",
346
+ "nbconvert_exporter": "python",
347
+ "pygments_lexer": "ipython3",
348
+ "version": "3.9.7"
349
+ }
350
+ },
351
+ "nbformat": 4,
352
+ "nbformat_minor": 5
353
+ }