Spaces:
Running
Running
feat: cleanup
Browse files- dev/inference/samples.csv +0 -102
- dev/inference/samples.txt +101 -0
- dev/inference/wandb-backend.ipynb +20 -52
dev/inference/samples.csv
DELETED
|
@@ -1,102 +0,0 @@
|
|
| 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/samples.txt
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
still life in the style of Kandinsky
|
| 18 |
+
still life in the style of Picasso
|
| 19 |
+
a colorful stairway to heaven
|
| 20 |
+
a background consisting of colors blue, green, and red
|
| 21 |
+
the communist statue of liberty
|
| 22 |
+
robots taking control over humans
|
| 23 |
+
epic sword fight
|
| 24 |
+
an avocado armchair
|
| 25 |
+
an armchair in the shape of an avocado
|
| 26 |
+
logo of an avocado armchair
|
| 27 |
+
an avocado armchair flying into space
|
| 28 |
+
a cute avocado armchair singing karaoke on stage in front of a crowd of strawberry shaped lamps
|
| 29 |
+
an illustration of an avocado in a christmas sweater staring at its reflection in a mirror
|
| 30 |
+
illustration of an avocado armchair
|
| 31 |
+
illustration of an avocado armchair getting married to a pineapple
|
| 32 |
+
Mohammed Ali and Mike Tyson in a hypothetical match
|
| 33 |
+
Pele and Maradona in a hypothetical match
|
| 34 |
+
view of mars from space
|
| 35 |
+
illustration of an astronaut in a space suit playing guitar
|
| 36 |
+
a clown wearing a spacesuit floating in space
|
| 37 |
+
a picture of the eiffel tower on the moon
|
| 38 |
+
watercolor of the Eiffel tower on the moon
|
| 39 |
+
a photo of the French flag on the planet Saturn
|
| 40 |
+
the moon is a skull
|
| 41 |
+
a dog playing with a ball
|
| 42 |
+
a cat sits on top of an alligator
|
| 43 |
+
a rat holding a red lightsaber in a white background
|
| 44 |
+
A unicorn is passing by a rainbow in a field of flowers
|
| 45 |
+
a dog eating worthlessness
|
| 46 |
+
an elephant made of carrots
|
| 47 |
+
an elephant on a unicycle during a circus
|
| 48 |
+
photography of a penguin watching television
|
| 49 |
+
rat wearing a crown
|
| 50 |
+
a portrait of a nightmare creature watching at you
|
| 51 |
+
a white room full of a black substance
|
| 52 |
+
happy, happiness
|
| 53 |
+
sad, sadness
|
| 54 |
+
the representation of infinity
|
| 55 |
+
a cute pikachu teapot
|
| 56 |
+
a picture of a castle from minecraft
|
| 57 |
+
an illustration of pikachu sitting on a bench
|
| 58 |
+
mario eating an avocado while walking his baby koala
|
| 59 |
+
star wars concept art
|
| 60 |
+
a cartoon of a superhero bear
|
| 61 |
+
an illustration of a cute skeleton wearing a blue hoodie
|
| 62 |
+
illustration of a baby shark swimming around corals
|
| 63 |
+
Cartoon of a carrot with big eyes
|
| 64 |
+
logo of a robot wearing glasses and reading a book
|
| 65 |
+
a bottle of coca-cola on a table
|
| 66 |
+
a cactus lifting weights
|
| 67 |
+
a living room with two white armchairs and a painting of the collosseum. The painting is mounted above a modern fireplace.
|
| 68 |
+
a long line of alternating green and red blocks
|
| 69 |
+
a long line of green blocks on a beach at subset
|
| 70 |
+
a long line of peaches on a beach at sunset
|
| 71 |
+
a peanut
|
| 72 |
+
a photo of a camera from the future
|
| 73 |
+
a restaurant menu
|
| 74 |
+
a skeleton with the shape of a spider
|
| 75 |
+
looking into the sky, 10 airplanes are seen overhead
|
| 76 |
+
shelves filled with books and alchemy potion bottles
|
| 77 |
+
this is a detailed high-resolution scan of a human brain
|
| 78 |
+
a collection of glasses is sitting on a table
|
| 79 |
+
a cross-section view of a walnut
|
| 80 |
+
a painting of a capybara sitting on a mountain during fall in surrealist style
|
| 81 |
+
a pentagonal green clock
|
| 82 |
+
a photo of san francisco golden gate bridge
|
| 83 |
+
a pixel art illustration of an eagle sitting in a field in the afternoon
|
| 84 |
+
a professional high-quality emoji of a lovestruck cup of boba
|
| 85 |
+
a small red block sitting on a large green block
|
| 86 |
+
a storefront that has the word 'openai' written on it
|
| 87 |
+
a tatoo of a black broccoli
|
| 88 |
+
a variety of clocks is sitting on a table
|
| 89 |
+
an emoji of a baby fox wearing a blue hat, blue gloves, red shirt, and red pants
|
| 90 |
+
an emoji of a baby penguin wearing a blue hat, blue gloves, red shirt, and green pants
|
| 91 |
+
an extreme close-up view of a capybara sitting in a field
|
| 92 |
+
an illustration of a baby cucumber with a mustache playing chess
|
| 93 |
+
an illustration of a baby daikon radish in a tutu walking a dog
|
| 94 |
+
an illustration of a baby hedgehog in a cape staring at its reflection in a mirror
|
| 95 |
+
an illustration of a baby panda with headphones holding an umbrella in the rain
|
| 96 |
+
an illustration of an avocado in a beanie riding a motorcycle
|
| 97 |
+
urinals are lined up in a jungle
|
| 98 |
+
a human face
|
| 99 |
+
a person is holding a phone and a waterbottle, running a marathon
|
| 100 |
+
a photograph of Ellen G. White
|
| 101 |
+
Young woman riding her bike through the forest
|
dev/inference/wandb-backend.ipynb
CHANGED
|
@@ -7,7 +7,6 @@
|
|
| 7 |
"metadata": {},
|
| 8 |
"outputs": [],
|
| 9 |
"source": [
|
| 10 |
-
"import csv\n",
|
| 11 |
"import tempfile\n",
|
| 12 |
"from functools import partial\n",
|
| 13 |
"import random\n",
|
|
@@ -36,7 +35,8 @@
|
|
| 36 |
"ENTITY, PROJECT = 'dalle-mini', 'dalle-mini' # used only for training run\n",
|
| 37 |
"VQGAN_REPO, VQGAN_COMMIT_ID = 'dalle-mini/vqgan_imagenet_f16_16384', None\n",
|
| 38 |
"normalize_text = True\n",
|
| 39 |
-
"latest_only = False # log only latest or all versions"
|
|
|
|
| 40 |
]
|
| 41 |
},
|
| 42 |
{
|
|
@@ -46,11 +46,12 @@
|
|
| 46 |
"metadata": {},
|
| 47 |
"outputs": [],
|
| 48 |
"source": [
|
| 49 |
-
"run_ids = ['
|
| 50 |
"ENTITY, PROJECT = 'wandb', 'hf-flax-dalle-mini'\n",
|
| 51 |
"VQGAN_REPO, VQGAN_COMMIT_ID = 'dalle-mini/vqgan_imagenet_f16_16384', None\n",
|
| 52 |
"normalize_text = False\n",
|
| 53 |
-
"latest_only = True # log only latest or all versions"
|
|
|
|
| 54 |
]
|
| 55 |
},
|
| 56 |
{
|
|
@@ -78,8 +79,8 @@
|
|
| 78 |
"outputs": [],
|
| 79 |
"source": [
|
| 80 |
"vqgan = VQModel.from_pretrained(VQGAN_REPO, revision=VQGAN_COMMIT_ID)\n",
|
| 81 |
-
"clip = FlaxCLIPModel.from_pretrained(\"openai/clip-vit-base-
|
| 82 |
-
"processor = CLIPProcessor.from_pretrained(\"openai/clip-vit-base-
|
| 83 |
"clip_params = replicate(clip.params)\n",
|
| 84 |
"vqgan_params = replicate(vqgan.params)"
|
| 85 |
]
|
|
@@ -108,13 +109,10 @@
|
|
| 108 |
"metadata": {},
|
| 109 |
"outputs": [],
|
| 110 |
"source": [
|
| 111 |
-
"with open('samples.
|
| 112 |
-
"
|
| 113 |
-
" samples = []\n",
|
| 114 |
-
" for row in reader:\n",
|
| 115 |
-
" samples.append(row)\n",
|
| 116 |
" # make list multiple of batch_size by adding elements\n",
|
| 117 |
-
" samples_to_add = [
|
| 118 |
" samples.extend(samples_to_add)\n",
|
| 119 |
" # reshape\n",
|
| 120 |
" samples = [samples[i:i+batch_size] for i in range(0, len(samples), batch_size)]"
|
|
@@ -160,7 +158,7 @@
|
|
| 160 |
"# retrieve inference run details\n",
|
| 161 |
"def get_last_inference_version(run_id):\n",
|
| 162 |
" try:\n",
|
| 163 |
-
" inference_run = api.run(f'dalle-mini/dalle-mini/
|
| 164 |
" return inference_run.summary.get('version', None)\n",
|
| 165 |
" except:\n",
|
| 166 |
" return None"
|
|
@@ -205,37 +203,7 @@
|
|
| 205 |
"execution_count": null,
|
| 206 |
"id": "bba70f33-af8b-4eb3-9973-7be672301a0b",
|
| 207 |
"metadata": {},
|
| 208 |
-
"outputs": [
|
| 209 |
-
{
|
| 210 |
-
"name": "stdout",
|
| 211 |
-
"output_type": "stream",
|
| 212 |
-
"text": [
|
| 213 |
-
"Processing artifact: model-4oh3u7ca:v54\n"
|
| 214 |
-
]
|
| 215 |
-
},
|
| 216 |
-
{
|
| 217 |
-
"name": "stderr",
|
| 218 |
-
"output_type": "stream",
|
| 219 |
-
"text": [
|
| 220 |
-
"\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mborisd13\u001b[0m (use `wandb login --relogin` to force relogin)\n"
|
| 221 |
-
]
|
| 222 |
-
},
|
| 223 |
-
{
|
| 224 |
-
"data": {
|
| 225 |
-
"text/html": [
|
| 226 |
-
"\n",
|
| 227 |
-
" Syncing run <strong><a href=\"https://wandb.ai/dalle-mini/dalle-mini/runs/inference-4oh3u7ca\" target=\"_blank\">inference-4oh3u7ca</a></strong> to <a href=\"https://wandb.ai/dalle-mini/dalle-mini\" target=\"_blank\">Weights & Biases</a> (<a href=\"https://docs.wandb.com/integrations/jupyter.html\" target=\"_blank\">docs</a>).<br/>\n",
|
| 228 |
-
"\n",
|
| 229 |
-
" "
|
| 230 |
-
],
|
| 231 |
-
"text/plain": [
|
| 232 |
-
"<IPython.core.display.HTML object>"
|
| 233 |
-
]
|
| 234 |
-
},
|
| 235 |
-
"metadata": {},
|
| 236 |
-
"output_type": "display_data"
|
| 237 |
-
}
|
| 238 |
-
],
|
| 239 |
"source": [
|
| 240 |
"artifact_versions = get_artifact_versions(run_id, latest_only)\n",
|
| 241 |
"last_inference_version = get_last_inference_version(run_id)\n",
|
|
@@ -247,10 +215,11 @@
|
|
| 247 |
" print(f'Processing artifact: {artifact.name}')\n",
|
| 248 |
" version = int(artifact.version[1:])\n",
|
| 249 |
" results = []\n",
|
| 250 |
-
" columns = ['Caption'
|
| 251 |
" \n",
|
| 252 |
" if latest_only:\n",
|
| 253 |
-
"
|
|
|
|
| 254 |
" else:\n",
|
| 255 |
" if last_inference_version is None:\n",
|
| 256 |
" # we should start from v0\n",
|
|
@@ -263,7 +232,7 @@
|
|
| 263 |
"\n",
|
| 264 |
" # start/resume corresponding run\n",
|
| 265 |
" if run is None:\n",
|
| 266 |
-
" run = wandb.init(job_type='inference', entity='dalle-mini', project='dalle-mini', config=training_config, id=f'
|
| 267 |
"\n",
|
| 268 |
" # work in temporary directory\n",
|
| 269 |
" with tempfile.TemporaryDirectory() as tmp:\n",
|
|
@@ -284,8 +253,7 @@
|
|
| 284 |
"\n",
|
| 285 |
" # process one batch of captions\n",
|
| 286 |
" for batch in tqdm(samples):\n",
|
| 287 |
-
"
|
| 288 |
-
" processed_prompts = [text_normalizer(x) for x in prompts] if normalize_text else prompts\n",
|
| 289 |
"\n",
|
| 290 |
" # repeat the prompts to distribute over each device and tokenize\n",
|
| 291 |
" processed_prompts = processed_prompts * jax.device_count()\n",
|
|
@@ -306,7 +274,7 @@
|
|
| 306 |
"\n",
|
| 307 |
" # get clip scores\n",
|
| 308 |
" print('Calculating CLIP scores')\n",
|
| 309 |
-
" clip_inputs = processor(text=
|
| 310 |
" # each shard will have one prompt, images need to be reorganized to be associated to the correct shard\n",
|
| 311 |
" images_per_prompt_indices = np.asarray(range(0, len(images), batch_size))\n",
|
| 312 |
" clip_inputs['pixel_values'] = jnp.concatenate(list(clip_inputs['pixel_values'][images_per_prompt_indices + i] for i in range(batch_size)))\n",
|
|
@@ -318,11 +286,11 @@
|
|
| 318 |
"\n",
|
| 319 |
" # add to results table\n",
|
| 320 |
" for i, (idx, scores, sample) in enumerate(zip(top_scores, logits, batch)):\n",
|
| 321 |
-
" if sample
|
| 322 |
" cur_images = [images[x] for x in images_per_prompt_indices + i]\n",
|
| 323 |
" top_images = [wandb.Image(cur_images[x]) for x in idx]\n",
|
| 324 |
" top_scores = [scores[x] for x in idx]\n",
|
| 325 |
-
" results.append([sample
|
| 326 |
"\n",
|
| 327 |
" # log results\n",
|
| 328 |
" table = wandb.Table(columns=columns, data=results)\n",
|
|
|
|
| 7 |
"metadata": {},
|
| 8 |
"outputs": [],
|
| 9 |
"source": [
|
|
|
|
| 10 |
"import tempfile\n",
|
| 11 |
"from functools import partial\n",
|
| 12 |
"import random\n",
|
|
|
|
| 35 |
"ENTITY, PROJECT = 'dalle-mini', 'dalle-mini' # used only for training run\n",
|
| 36 |
"VQGAN_REPO, VQGAN_COMMIT_ID = 'dalle-mini/vqgan_imagenet_f16_16384', None\n",
|
| 37 |
"normalize_text = True\n",
|
| 38 |
+
"latest_only = False # log only latest or all versions\n",
|
| 39 |
+
"suffix = '_1' # mainly for duplicate inference runs with a deleted version"
|
| 40 |
]
|
| 41 |
},
|
| 42 |
{
|
|
|
|
| 46 |
"metadata": {},
|
| 47 |
"outputs": [],
|
| 48 |
"source": [
|
| 49 |
+
"run_ids = ['3kaut6e8']\n",
|
| 50 |
"ENTITY, PROJECT = 'wandb', 'hf-flax-dalle-mini'\n",
|
| 51 |
"VQGAN_REPO, VQGAN_COMMIT_ID = 'dalle-mini/vqgan_imagenet_f16_16384', None\n",
|
| 52 |
"normalize_text = False\n",
|
| 53 |
+
"latest_only = True # log only latest or all versions\n",
|
| 54 |
+
"suffix = '_2' # mainly for duplicate inference runs with a deleted version"
|
| 55 |
]
|
| 56 |
},
|
| 57 |
{
|
|
|
|
| 79 |
"outputs": [],
|
| 80 |
"source": [
|
| 81 |
"vqgan = VQModel.from_pretrained(VQGAN_REPO, revision=VQGAN_COMMIT_ID)\n",
|
| 82 |
+
"clip = FlaxCLIPModel.from_pretrained(\"openai/clip-vit-base-patch16\")\n",
|
| 83 |
+
"processor = CLIPProcessor.from_pretrained(\"openai/clip-vit-base-patch16\")\n",
|
| 84 |
"clip_params = replicate(clip.params)\n",
|
| 85 |
"vqgan_params = replicate(vqgan.params)"
|
| 86 |
]
|
|
|
|
| 109 |
"metadata": {},
|
| 110 |
"outputs": [],
|
| 111 |
"source": [
|
| 112 |
+
"with open('samples.txt', encoding='utf8') as f:\n",
|
| 113 |
+
" samples = [l.strip() for l in f.readlines()]\n",
|
|
|
|
|
|
|
|
|
|
| 114 |
" # make list multiple of batch_size by adding elements\n",
|
| 115 |
+
" samples_to_add = [padding_item] * (-len(samples) % batch_size)\n",
|
| 116 |
" samples.extend(samples_to_add)\n",
|
| 117 |
" # reshape\n",
|
| 118 |
" samples = [samples[i:i+batch_size] for i in range(0, len(samples), batch_size)]"
|
|
|
|
| 158 |
"# retrieve inference run details\n",
|
| 159 |
"def get_last_inference_version(run_id):\n",
|
| 160 |
" try:\n",
|
| 161 |
+
" inference_run = api.run(f'dalle-mini/dalle-mini/inf-{run_id}{suffix}')\n",
|
| 162 |
" return inference_run.summary.get('version', None)\n",
|
| 163 |
" except:\n",
|
| 164 |
" return None"
|
|
|
|
| 203 |
"execution_count": null,
|
| 204 |
"id": "bba70f33-af8b-4eb3-9973-7be672301a0b",
|
| 205 |
"metadata": {},
|
| 206 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
"source": [
|
| 208 |
"artifact_versions = get_artifact_versions(run_id, latest_only)\n",
|
| 209 |
"last_inference_version = get_last_inference_version(run_id)\n",
|
|
|
|
| 215 |
" print(f'Processing artifact: {artifact.name}')\n",
|
| 216 |
" version = int(artifact.version[1:])\n",
|
| 217 |
" results = []\n",
|
| 218 |
+
" columns = ['Caption'] + [f'Image {i+1}' for i in range(top_k)] + [f'Score {i+1}' for i in range(top_k)]\n",
|
| 219 |
" \n",
|
| 220 |
" if latest_only:\n",
|
| 221 |
+
" pass\n",
|
| 222 |
+
" #assert last_inference_version is None or version > last_inference_version\n",
|
| 223 |
" else:\n",
|
| 224 |
" if last_inference_version is None:\n",
|
| 225 |
" # we should start from v0\n",
|
|
|
|
| 232 |
"\n",
|
| 233 |
" # start/resume corresponding run\n",
|
| 234 |
" if run is None:\n",
|
| 235 |
+
" run = wandb.init(job_type='inference', entity='dalle-mini', project='dalle-mini', config=training_config, id=f'inf-{run_id}{suffix}', resume='allow')\n",
|
| 236 |
"\n",
|
| 237 |
" # work in temporary directory\n",
|
| 238 |
" with tempfile.TemporaryDirectory() as tmp:\n",
|
|
|
|
| 253 |
"\n",
|
| 254 |
" # process one batch of captions\n",
|
| 255 |
" for batch in tqdm(samples):\n",
|
| 256 |
+
" processed_prompts = [text_normalizer(x) for x in batch] if normalize_text else list(batch)\n",
|
|
|
|
| 257 |
"\n",
|
| 258 |
" # repeat the prompts to distribute over each device and tokenize\n",
|
| 259 |
" processed_prompts = processed_prompts * jax.device_count()\n",
|
|
|
|
| 274 |
"\n",
|
| 275 |
" # get clip scores\n",
|
| 276 |
" print('Calculating CLIP scores')\n",
|
| 277 |
+
" clip_inputs = processor(text=batch, images=images, return_tensors='np', padding='max_length', max_length=77, truncation=True).data\n",
|
| 278 |
" # each shard will have one prompt, images need to be reorganized to be associated to the correct shard\n",
|
| 279 |
" images_per_prompt_indices = np.asarray(range(0, len(images), batch_size))\n",
|
| 280 |
" clip_inputs['pixel_values'] = jnp.concatenate(list(clip_inputs['pixel_values'][images_per_prompt_indices + i] for i in range(batch_size)))\n",
|
|
|
|
| 286 |
"\n",
|
| 287 |
" # add to results table\n",
|
| 288 |
" for i, (idx, scores, sample) in enumerate(zip(top_scores, logits, batch)):\n",
|
| 289 |
+
" if sample == padding_item: continue\n",
|
| 290 |
" cur_images = [images[x] for x in images_per_prompt_indices + i]\n",
|
| 291 |
" top_images = [wandb.Image(cur_images[x]) for x in idx]\n",
|
| 292 |
" top_scores = [scores[x] for x in idx]\n",
|
| 293 |
+
" results.append([sample] + top_images + top_scores)\n",
|
| 294 |
"\n",
|
| 295 |
" # log results\n",
|
| 296 |
" table = wandb.Table(columns=columns, data=results)\n",
|