boris commited on
Commit
e226ca6
2 Parent(s): 0cc04f2 39d3a15

Merge pull request #93 from borisdayma/inference

Browse files
dalle_mini/text.py CHANGED
@@ -98,23 +98,8 @@ def replace_person_token(t):
98
 
99
 
100
  def fix_html(t):
101
- "Adapted from fastai"
102
- t = (
103
- t.replace("#39;", "'")
104
- .replace("&", "&")
105
- .replace("amp;", "&")
106
- .replace("#146;", "'")
107
- .replace("nbsp;", " ")
108
- .replace("#36;", "$")
109
- .replace("\\n", "\n")
110
- .replace("quot;", "'")
111
- .replace("<br />", "\n")
112
- .replace('\\"', '"')
113
- .replace("<unk>", " ")
114
- .replace(" @.@ ", ".")
115
- .replace(" @-@ ", "-")
116
- )
117
- return html.unescape(t)
118
 
119
 
120
  def replace_punctuation_with_commas(t):
 
98
 
99
 
100
  def fix_html(t):
101
+ # from OpenAI CLIP
102
+ return html.unescape(html.unescape(t))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
 
105
  def replace_punctuation_with_commas(t):
dev/inference/samples.txt CHANGED
@@ -1,103 +1,112 @@
1
  white snow covered mountain under blue sky during daytime
2
- aerial view of the beach at night
3
  aerial view of the beach during daytime
 
4
  a beautiful sunset at a beach with a shell on the shore
5
  a farmhouse surrounded by beautiful flowers
6
- a photo of a fantasy version of New York City
7
- a picture of fantasy kingdoms
8
- a volcano erupting in the middle of San Francisco
9
- big wave destroying a city
10
- Paris in a far future, futuristic Paris
11
  sunset over green mountains
12
- the last sunrise on earth
13
- underwater cathedral
14
  painting of an oniric forest glade surrounded by tall trees
15
- real painting of an alien from Monet
16
  a graphite sketch of a gothic cathedral
17
  a graphite sketch of Elon Musk
18
  still life in the style of Kandinsky
19
  still life in the style of Picasso
20
  a colorful stairway to heaven
21
  a background consisting of colors blue, green, and red
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  the communist statue of liberty
23
  robots taking control over humans
24
- epic sword fight
25
- an avocado armchair
26
- an armchair in the shape of an avocado
27
- logo of an avocado armchair
28
- an avocado armchair flying into space
29
- a cute avocado armchair singing karaoke on stage in front of a crowd of strawberry shaped lamps
30
- an illustration of an avocado in a christmas sweater staring at its reflection in a mirror
31
- illustration of an avocado armchair
32
- illustration of an avocado armchair getting married to a pineapple
33
- a muscular banana sitting upright on a bench smoking watching a banana on television, high definition photography
34
- Mohammed Ali and Mike Tyson in a hypothetical match
35
- Pele and Maradona in a hypothetical match
36
- view of mars from space
37
  illustration of an astronaut in a space suit playing guitar
38
  a clown wearing a spacesuit floating in space
39
- a picture of the eiffel tower on the moon
40
- watercolor of the Eiffel tower on the moon
41
- a photo of the French flag on the planet Saturn
42
- the moon is a skull
43
  a dog playing with a ball
44
  a cat sits on top of an alligator
45
  a rat holding a red lightsaber in a white background
46
  A unicorn is passing by a rainbow in a field of flowers
47
- a dog eating worthlessness
48
  an elephant made of carrots
49
  an elephant on a unicycle during a circus
50
  photography of a penguin watching television
 
 
51
  rat wearing a crown
52
- a portrait of a nightmare creature watching at you
53
- a white room full of a black substance
54
- happy, happiness
55
- sad, sadness
56
- the representation of infinity
57
- a cute pikachu teapot
 
 
 
 
 
58
  a picture of a castle from minecraft
 
59
  an illustration of pikachu sitting on a bench
60
- mario eating an avocado while walking his baby koala
 
61
  star wars concept art
62
  a cartoon of a superhero bear
63
  an illustration of a cute skeleton wearing a blue hoodie
64
  illustration of a baby shark swimming around corals
65
  Cartoon of a carrot with big eyes
66
  logo of a robot wearing glasses and reading a book
67
- a bottle of coca-cola on a table
68
  a cactus lifting weights
69
- a living room with two white armchairs and a painting of the collosseum. The painting is mounted above a modern fireplace.
70
- a long line of alternating green and red blocks
71
- a long line of green blocks on a beach at subset
72
- a long line of peaches on a beach at sunset
73
- a peanut
74
  a photo of a camera from the future
75
- a restaurant menu
76
  a skeleton with the shape of a spider
77
- looking into the sky, 10 airplanes are seen overhead
78
- shelves filled with books and alchemy potion bottles
79
- this is a detailed high-resolution scan of a human brain
80
  a collection of glasses is sitting on a table
81
- a cross-section view of a walnut
82
  a painting of a capybara sitting on a mountain during fall in surrealist style
83
  a pentagonal green clock
84
- a photo of san francisco golden gate bridge
85
  a pixel art illustration of an eagle sitting in a field in the afternoon
86
  a professional high-quality emoji of a lovestruck cup of boba
87
  a small red block sitting on a large green block
88
  a storefront that has the word 'openai' written on it
89
  a tatoo of a black broccoli
90
  a variety of clocks is sitting on a table
91
- an emoji of a baby fox wearing a blue hat, blue gloves, red shirt, and red pants
92
  an emoji of a baby penguin wearing a blue hat, blue gloves, red shirt, and green pants
93
  an extreme close-up view of a capybara sitting in a field
94
  an illustration of a baby cucumber with a mustache playing chess
95
  an illustration of a baby daikon radish in a tutu walking a dog
96
  an illustration of a baby hedgehog in a cape staring at its reflection in a mirror
97
  an illustration of a baby panda with headphones holding an umbrella in the rain
98
- an illustration of an avocado in a beanie riding a motorcycle
99
  urinals are lined up in a jungle
 
100
  a human face
101
  a person is holding a phone and a waterbottle, running a marathon
102
  a photograph of Ellen G. White
103
  Young woman riding her bike through the forest
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  white snow covered mountain under blue sky during daytime
 
2
  aerial view of the beach during daytime
3
+ aerial view of the beach at night
4
  a beautiful sunset at a beach with a shell on the shore
5
  a farmhouse surrounded by beautiful flowers
 
 
 
 
 
6
  sunset over green mountains
7
+ a photo of san francisco golden gate bridge
 
8
  painting of an oniric forest glade surrounded by tall trees
 
9
  a graphite sketch of a gothic cathedral
10
  a graphite sketch of Elon Musk
11
  still life in the style of Kandinsky
12
  still life in the style of Picasso
13
  a colorful stairway to heaven
14
  a background consisting of colors blue, green, and red
15
+ Mohammed Ali and Mike Tyson in a match
16
+ Pele and Maradona in a match
17
+ view of Mars from space
18
+ a picture of the Eiffel tower on the moon
19
+ a picture of the Eiffel tower on the moon, Earth is in the background
20
+ watercolor of the Eiffel tower on the moon
21
+ the moon is a skull
22
+ epic sword fight
23
+ underwater cathedral
24
+ a photo of a fantasy version of New York City
25
+ a picture of fantasy kingdoms
26
+ a volcano erupting next to San Francisco golden gate bridge
27
+ big wave destroying a city
28
+ Paris in a far future, futuristic Paris
29
+ real painting of an alien from Monet
30
  the communist statue of liberty
31
  robots taking control over humans
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  illustration of an astronaut in a space suit playing guitar
33
  a clown wearing a spacesuit floating in space
 
 
 
 
34
  a dog playing with a ball
35
  a cat sits on top of an alligator
36
  a rat holding a red lightsaber in a white background
37
  A unicorn is passing by a rainbow in a field of flowers
 
38
  an elephant made of carrots
39
  an elephant on a unicycle during a circus
40
  photography of a penguin watching television
41
+ a penguin is walking on the Moon, Earth is in the background
42
+ a penguin standing on a tower of books holds onto a rope from a helicopter
43
  rat wearing a crown
44
+ looking into the sky, 10 airplanes are seen overhead
45
+ shelves filled with books and alchemy potion bottles
46
+ this is a detailed high-resolution scan of a human brain
47
+ a restaurant menu
48
+ a bottle of coca-cola on a table
49
+ a peanut
50
+ a cross-section view of a walnut
51
+ a living room with two white armchairs and a painting of the collosseum. The painting is mounted above a modern fireplace.
52
+ a long line of alternating green and red blocks
53
+ a long line of green blocks on a beach at subset
54
+ a long line of peaches on a beach at sunset
55
  a picture of a castle from minecraft
56
+ a cute pikachu teapot
57
  an illustration of pikachu sitting on a bench
58
+ mario is jumping over a zebra during the sunset
59
+ famous anime hero
60
  star wars concept art
61
  a cartoon of a superhero bear
62
  an illustration of a cute skeleton wearing a blue hoodie
63
  illustration of a baby shark swimming around corals
64
  Cartoon of a carrot with big eyes
65
  logo of a robot wearing glasses and reading a book
 
66
  a cactus lifting weights
67
+ illustration of a cactus lifting weigths
68
+ logo of a cactus lifting weights
 
 
 
69
  a photo of a camera from the future
 
70
  a skeleton with the shape of a spider
 
 
 
71
  a collection of glasses is sitting on a table
 
72
  a painting of a capybara sitting on a mountain during fall in surrealist style
73
  a pentagonal green clock
 
74
  a pixel art illustration of an eagle sitting in a field in the afternoon
75
  a professional high-quality emoji of a lovestruck cup of boba
76
  a small red block sitting on a large green block
77
  a storefront that has the word 'openai' written on it
78
  a tatoo of a black broccoli
79
  a variety of clocks is sitting on a table
80
+ an emoji of a baby fox wearing a blue hat, green gloves, red shirt, and yellow pants
81
  an emoji of a baby penguin wearing a blue hat, blue gloves, red shirt, and green pants
82
  an extreme close-up view of a capybara sitting in a field
83
  an illustration of a baby cucumber with a mustache playing chess
84
  an illustration of a baby daikon radish in a tutu walking a dog
85
  an illustration of a baby hedgehog in a cape staring at its reflection in a mirror
86
  an illustration of a baby panda with headphones holding an umbrella in the rain
 
87
  urinals are lined up in a jungle
88
+ a muscular banana sitting upright on a bench smoking watching a banana on television, high definition photography
89
  a human face
90
  a person is holding a phone and a waterbottle, running a marathon
91
  a photograph of Ellen G. White
92
  Young woman riding her bike through the forest
93
+ a portrait of a nightmare creature watching at you
94
+ a white room full of a black substance
95
+ the best soccer team of the world
96
+ the best basketball team of the world
97
+ the best football team of the world
98
+ happy, happiness
99
+ sad, sadness
100
+ the representation of infinity
101
+ the end of the world
102
+ the last sunrise on earth
103
+ an avocado armchair
104
+ an armchair in the shape of an avocado
105
+ illustration of an avocado armchair
106
+ illustration of an armchair in the shape of an avocado
107
+ logo of an avocado armchair
108
+ an avocado armchair flying into space
109
+ a cute avocado armchair singing karaoke on stage in front of a crowd of strawberry shaped lamps
110
+ an illustration of an avocado in a christmas sweater staring at its reflection in a mirror
111
+ illustration of an avocado armchair getting married to a pineapple
112
+ an illustration of an avocado in a beanie riding a motorcycle
dev/inference/wandb-backend.ipynb CHANGED
@@ -32,12 +32,15 @@
32
  "outputs": [],
33
  "source": [
34
  "run_ids = ['3kaut6e8']\n",
 
 
 
35
  "ENTITY, PROJECT = 'wandb', 'hf-flax-dalle-mini'\n",
36
  "VQGAN_REPO, VQGAN_COMMIT_ID = 'dalle-mini/vqgan_imagenet_f16_16384', None\n",
37
  "normalize_text = False\n",
38
  "latest_only = True # log only latest or all versions\n",
39
  "suffix = '' # mainly for duplicate inference runs with a deleted version\n",
40
- "add_clip_32 = True"
41
  ]
42
  },
43
  {
@@ -47,7 +50,10 @@
47
  "metadata": {},
48
  "outputs": [],
49
  "source": [
50
- "run_ids = ['k76r0v39']\n",
 
 
 
51
  "ENTITY, PROJECT = 'dalle-mini', 'dalle-mini' # used only for training run\n",
52
  "VQGAN_REPO, VQGAN_COMMIT_ID = 'dalle-mini/vqgan_imagenet_f16_16384', None\n",
53
  "normalize_text = True\n",
@@ -56,6 +62,19 @@
56
  "add_clip_32 = False"
57
  ]
58
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  {
60
  "cell_type": "code",
61
  "execution_count": null,
@@ -115,16 +134,6 @@
115
  " return logits"
116
  ]
117
  },
118
- {
119
- "cell_type": "code",
120
- "execution_count": null,
121
- "id": "ebf4f7bf-2efa-46cc-b3f4-2d7a54f7b2cb",
122
- "metadata": {},
123
- "outputs": [],
124
- "source": [
125
- "clip_params['logit_scale']"
126
- ]
127
- },
128
  {
129
  "cell_type": "code",
130
  "execution_count": null,
@@ -204,7 +213,9 @@
204
  " do_sample=True,\n",
205
  " num_beams=1,\n",
206
  " prng_key=key,\n",
207
- " params=params\n",
 
 
208
  " )\n",
209
  " \n",
210
  " return _generate"
@@ -286,7 +297,8 @@
286
  "\n",
287
  " # generate images\n",
288
  " images = []\n",
289
- " for i in tqdm(range(num_images // jax.device_count()), desc='Generating Images'):\n",
 
290
  " key, subkey = jax.random.split(key)\n",
291
  " encoded_images = p_generate(tokenized_prompt, shard_prng_key(subkey), model_params)\n",
292
  " encoded_images = encoded_images.sequences[..., 1:]\n",
@@ -296,7 +308,7 @@
296
  " images.append(Image.fromarray(np.asarray(img * 255, dtype=np.uint8)))\n",
297
  "\n",
298
  " # get clip scores\n",
299
- " print('Calculating CLIP scores')\n",
300
  " clip_inputs = processor(text=batch, images=images, return_tensors='np', padding='max_length', max_length=77, truncation=True).data\n",
301
  " # each shard will have one prompt, images need to be reorganized to be associated to the correct shard\n",
302
  " images_per_prompt_indices = np.asarray(range(0, len(images), batch_size))\n",
@@ -333,6 +345,7 @@
333
  " top_images = [wandb.Image(cur_images[x]) for x in idx]\n",
334
  " top_scores = [scores[x] for x in idx]\n",
335
  " results32.append([sample] + top_images + top_scores)\n",
 
336
  "\n",
337
  " # log results\n",
338
  " table = wandb.Table(columns=columns, data=results)\n",
 
32
  "outputs": [],
33
  "source": [
34
  "run_ids = ['3kaut6e8']\n",
35
+ "# Alamy - 3kaut6e8\n",
36
+ "# YFCC - to do\n",
37
+ "# HF spaces - 4oh3u7ca\n",
38
  "ENTITY, PROJECT = 'wandb', 'hf-flax-dalle-mini'\n",
39
  "VQGAN_REPO, VQGAN_COMMIT_ID = 'dalle-mini/vqgan_imagenet_f16_16384', None\n",
40
  "normalize_text = False\n",
41
  "latest_only = True # log only latest or all versions\n",
42
  "suffix = '' # mainly for duplicate inference runs with a deleted version\n",
43
+ "add_clip_32 = False"
44
  ]
45
  },
46
  {
 
50
  "metadata": {},
51
  "outputs": [],
52
  "source": [
53
+ "run_ids = ['2u5lk3uw']\n",
54
+ "# poorly shuffled 1nj161cl\n",
55
+ "# well shuffled he9rrc3q\n",
56
+ "# non normalized 1fwxpyfh ! requires changing normalize_text\n",
57
  "ENTITY, PROJECT = 'dalle-mini', 'dalle-mini' # used only for training run\n",
58
  "VQGAN_REPO, VQGAN_COMMIT_ID = 'dalle-mini/vqgan_imagenet_f16_16384', None\n",
59
  "normalize_text = True\n",
 
62
  "add_clip_32 = False"
63
  ]
64
  },
65
+ {
66
+ "cell_type": "code",
67
+ "execution_count": null,
68
+ "id": "71f27b96-7e6c-4472-a2e4-e99a8fb67a72",
69
+ "metadata": {},
70
+ "outputs": [],
71
+ "source": [
72
+ "# model.generate parameters - Not used yet\n",
73
+ "gen_top_k = None\n",
74
+ "gen_top_p = None\n",
75
+ "temperature = None"
76
+ ]
77
+ },
78
  {
79
  "cell_type": "code",
80
  "execution_count": null,
 
134
  " return logits"
135
  ]
136
  },
 
 
 
 
 
 
 
 
 
 
137
  {
138
  "cell_type": "code",
139
  "execution_count": null,
 
213
  " do_sample=True,\n",
214
  " num_beams=1,\n",
215
  " prng_key=key,\n",
216
+ " params=params,\n",
217
+ " top_k=gen_top_k,\n",
218
+ " top_p=gen_top_p\n",
219
  " )\n",
220
  " \n",
221
  " return _generate"
 
297
  "\n",
298
  " # generate images\n",
299
  " images = []\n",
300
+ " pbar = tqdm(range(num_images // jax.device_count()), desc='Generating Images', leave=None)\n",
301
+ " for i in pbar:\n",
302
  " key, subkey = jax.random.split(key)\n",
303
  " encoded_images = p_generate(tokenized_prompt, shard_prng_key(subkey), model_params)\n",
304
  " encoded_images = encoded_images.sequences[..., 1:]\n",
 
308
  " images.append(Image.fromarray(np.asarray(img * 255, dtype=np.uint8)))\n",
309
  "\n",
310
  " # get clip scores\n",
311
+ " pbar.set_description('Calculating CLIP scores')\n",
312
  " clip_inputs = processor(text=batch, images=images, return_tensors='np', padding='max_length', max_length=77, truncation=True).data\n",
313
  " # each shard will have one prompt, images need to be reorganized to be associated to the correct shard\n",
314
  " images_per_prompt_indices = np.asarray(range(0, len(images), batch_size))\n",
 
345
  " top_images = [wandb.Image(cur_images[x]) for x in idx]\n",
346
  " top_scores = [scores[x] for x in idx]\n",
347
  " results32.append([sample] + top_images + top_scores)\n",
348
+ " pbar.close()\n",
349
  "\n",
350
  " # log results\n",
351
  " table = wandb.Table(columns=columns, data=results)\n",