From a35e17fd77f4f2232373d496bcde36c30dec3f07 Mon Sep 17 00:00:00 2001 From: Orange56 <34915619+OrangeJuly56@users.noreply.github.com> Date: Tue, 20 Dec 2022 12:29:28 +0000 Subject: [PATCH 1/3] Update A_B.ipynb --- nbs/A_B.ipynb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nbs/A_B.ipynb b/nbs/A_B.ipynb index 1e334539..4c3d9818 100644 --- a/nbs/A_B.ipynb +++ b/nbs/A_B.ipynb @@ -247,7 +247,7 @@ "\n", "### settings that will be used across test cases.\n", "defaults:\n", - " grpc_host: grpc.stability.ai:443\n", + " host: grpc.stability.ai:443\n", " # If API key not provided in test_config.yaml, user prompted with getpass\n", " key:\n", "\n", @@ -270,6 +270,7 @@ "# not a fan of this name. maybe call this section \"experiments\"?\n", "differentiators:\n", " test_case_A:\n", + " host: grpc-staging.stability.ai:443\n", " engine: stable-diffusion-512-v2-0\n", " prompt_chunks:\n", " middle: ''\n", @@ -342,7 +343,7 @@ "#####################################\n", "\n", "required_attributes = [\n", - " 'grpc_host',\n", + " 'host',\n", " #'api_key'\n", " 'key',\n", "]\n", @@ -472,7 +473,7 @@ " return pn.Column(*output)\n", "\n", "\n", - "non_generation_arguments = ['grpc_host', 'engine', 'key']\n", + "non_generation_arguments = ['host', 'engine', 'key']\n", "\n", "rec = random.choice(experiments)\n", "\n", From 1ad45196ec4c127cd06126eaefd5e7d2bb3d2b2b Mon Sep 17 00:00:00 2001 From: Orange56 <34915619+OrangeJuly56@users.noreply.github.com> Date: Thu, 22 Dec 2022 11:50:34 +0000 Subject: [PATCH 2/3] Save image feature --- nbs/A_B.ipynb | 185 +++++++++++++++++++++++++++----------------------- 1 file changed, 99 insertions(+), 86 deletions(-) diff --git a/nbs/A_B.ipynb b/nbs/A_B.ipynb index 4c3d9818..516ecdcd 100644 --- a/nbs/A_B.ipynb +++ b/nbs/A_B.ipynb @@ -1,21 +1,10 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "provenance": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" - }, - "language_info": { - "name": "python" - } - }, "cells": [ { "cell_type": "markdown", + "metadata": { + "id": "i0RWQRJAkdJe" + }, "source": [ "# Stability.AI A/B Testing Notebook\n", "\n", @@ -38,10 +27,7 @@ " - Click again to deselect if you cahnge your mind\n", " - The notebook does not currently constrain the user to only select one option, but that's how we recommend you use it. \n", " - When you're satisfied with your selection, execute the cell again to log your feedback and generate a new set of images." - ], - "metadata": { - "id": "i0RWQRJAkdJe" - } + ] }, { "cell_type": "code", @@ -242,6 +228,11 @@ }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "GX85BLyFrGlJ" + }, + "outputs": [], "source": [ "%%writefile test_config.yaml\n", "\n", @@ -286,25 +277,29 @@ " middle: ''\n", " # Don't do this, results in `middle:\"None\"`\n", " # middle:\n" - ], - "metadata": { - "id": "GX85BLyFrGlJ" - }, - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "xl_t3CjZlWvq" + }, + "outputs": [], "source": [ "# @markdown ## Load Experiments\n", "\n", "from omegaconf import OmegaConf\n", "import getpass\n", "from stability_sdk import client\n", - "\n", + "import shutil\n", "import panel as pn\n", "pn.extension()\n", "\n", + "!mkdir fav\n", + "!mkdir results\n", + "\n", "\n", "exp_cfg_fpath_out = Path(workspace_cfg.project_root) / workspace_cfg.exp_cfg_fname\n", "exp_cfg_fpath = exp_cfg_fpath_out\n", @@ -380,76 +375,35 @@ "for test_case in cfg.differentiators:\n", " running_score[test_case]+=0\n", "\n" - ], - "metadata": { - "id": "xl_t3CjZlWvq", - "cellView": "form" - }, - "execution_count": null, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, + "metadata": { + "cellView": "form", + "id": "ogPWQhWm7BXN" + }, + "outputs": [], "source": [ "# @markdown # Load a random sample to score preference\n", "\n", "SAMPLE_IDX += 1\n", - "\n", + "Copy_to_path = \"/content/results/\"\n", "##########################\n", "# Log experiment outcome #\n", "##########################\n", "\n", "save_images = False # @param {type:'boolean'}\n", - "save_favorite_only = False # @param {type:'boolean'}\n", + "save_favorite_only = True # @param {type:'boolean'}\n", + "\n", "\n", "\n", - "# to do: make this not a closure.\n", - "def log_items(items):\n", - " #for (img, test_case, kwargs_gen, is_preference) in items: # to do: dictify\n", - " recs = []\n", - " for item in items:\n", - " # assign image a filename\n", - " img_fname = f\"{RANDOM_PREFIX}_{SAMPLE_IDX}_{item['test_case']}.png\"\n", - " #rec = copy.deepcopy(item)\n", - " rec = item\n", - " img_fpath = Path(workspace_cfg.project_root) / img_fname\n", - " # save image\n", - " img = rec.pop('img')\n", - " save_im = False\n", - " if save_images or save_favorite_only:\n", - " save_im = True\n", - " if save_favorite_only and not rec['is_preference']:\n", - " save_im = False\n", - " if save_im:\n", - " print(img_fpath)\n", - " rec['img_fpath'] = str(img_fpath)\n", - " img.save(img_fpath)\n", - " # update outcome\n", - " rec['is_preference'] = rec['button'].value\n", - " if rec['is_preference']:\n", - " running_score[rec['test_case']] += 1\n", - " rec.pop('button')\n", - " # log outcome\n", - " recs.append(rec)\n", - " outfile = Path(workspace_cfg.project_root) / explog_fname\n", - " #with open(outfile, 'a') as f:\n", - " with outfile.open('a') as f:\n", - " json.dump(recs, f)\n", - " f.write('\\n')\n", - " logger.debug(running_score)\n", - " \n", - "if items:\n", - " try:\n", - " log_items(items)\n", - " posterior_plot(running_score)\n", - " except KeyError:\n", - " # fuck it\n", - " pass\n", "\n", "\n", "SEED = random.randrange(0, 4294967295)\n", "\n", - "blind_test = False # @param {type: \"boolean\"}\n", + "blind_test = True # @param {type: \"boolean\"}\n", "\n", "def item_to_ux(\n", " item\n", @@ -470,6 +424,7 @@ " output.append(toggle)\n", " item['button'] = toggle\n", " item['is_preference'] = toggle.value\n", + " print(item)\n", " return pn.Column(*output)\n", "\n", "\n", @@ -509,6 +464,10 @@ " if artifact.type == generation.ARTIFACT_IMAGE:\n", " img = Image.open(io.BytesIO(artifact.binary))\n", " img = img.resize([512, 512])\n", + " if save_images or save_favorite_only:\n", + " img_fname = f\"{kwargs_gen['prompt']}_{kwargs_gen['seed']}_{SAMPLE_IDX}_{test_case}.png\"\n", + " img.save(Copy_to_path+img_fname)\n", + "\n", " items.append({\n", " 'img':img,\n", " 'test_case':test_case,\n", @@ -518,18 +477,72 @@ " 'SDK_VERSION':SDK_VERSION,\n", " 'timestamp':time.time(),\n", " 'user_id': workspace_cfg.notebook_user_id,\n", - " 'project_name':workspace_cfg.active_project,\n", + " 'project_name':workspace_cfg.active_project, \n", " })\n", "\n", "random.shuffle(items)\n", - "pn.Row(*[item_to_ux(it) for it in items])" - ], - "metadata": { - "id": "ogPWQhWm7BXN", - "cellView": "form" - }, + "pn.Row(*[item_to_ux(it) for it in items]) " + ] + }, + { + "cell_type": "code", "execution_count": null, - "outputs": [] + "metadata": {}, + "outputs": [], + "source": [ + "# to do: make this not a closure.\n", + "import shutil\n", + "def log_items(items):\n", + " #for (img, test_case, kwargs_gen, is_preference) in items: # to do: dictify\n", + " recs = []\n", + " for item in items:\n", + " # assign image a filename\n", + " # rec = copy.deepcopy(item)\n", + " rec = item\n", + " # save image\n", + " rec['is_preference'] = rec['button'].value\n", + " if save_favorite_only:\n", + " if rec['is_preference']:\n", + " img_fname1 = f\"{rec['kwargs']['prompt']}_{rec['kwargs']['seed']}_{SAMPLE_IDX}_{rec['test_case']}.png\"\n", + " print(type(Copy_to_path+img_fname1))\n", + " shutil.move(Copy_to_path+img_fname1, '/content/fav')\n", + " # update outcome\n", + " if rec['is_preference']:\n", + " running_score[rec['test_case']] += 1\n", + " rec.pop('img')\n", + " rec.pop('button')\n", + " # log outcome\n", + " recs.append(rec)\n", + " outfile = Path(workspace_cfg.project_root) / explog_fname\n", + " #with open(outfile, 'a') as f:\n", + " with outfile.open('a') as f:\n", + " json.dump(recs, f)\n", + " f.write('\\n')\n", + " logger.debug(running_score)\n", + "\n", + "# print(items)\n", + "if items:\n", + " try:\n", + " log_items(items)\n", + " posterior_plot(running_score)\n", + " except KeyError:\n", + " # fuck it\n", + " pass" + ] } - ] + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 } From e7805c00ac9683b897ddaa1c670cfb29c983e42f Mon Sep 17 00:00:00 2001 From: Orange56 <34915619+OrangeJuly56@users.noreply.github.com> Date: Tue, 3 Jan 2023 11:11:34 +0000 Subject: [PATCH 3/3] Update A_B.ipynb No staging - external use --- nbs/A_B.ipynb | 1 - 1 file changed, 1 deletion(-) diff --git a/nbs/A_B.ipynb b/nbs/A_B.ipynb index 516ecdcd..abba7f04 100644 --- a/nbs/A_B.ipynb +++ b/nbs/A_B.ipynb @@ -261,7 +261,6 @@ "# not a fan of this name. maybe call this section \"experiments\"?\n", "differentiators:\n", " test_case_A:\n", - " host: grpc-staging.stability.ai:443\n", " engine: stable-diffusion-512-v2-0\n", " prompt_chunks:\n", " middle: ''\n",